/*
JS Loaded: 
0.mf+tour+js+actions+scene.js
*/



 // Including ./mf/tour/js/actions/scene.js 

var player;
var scene_id;
var ext;

$(document).ready(function(){

	player = $('div#player_box_trailer');
	scene_id = player.find('input.scene_id').val();
	ext = player.find('input.ext').val();

	//	Page tabs
	$('ul#page_tabs a').click(function(){
		if(!$(this).hasClass('unavailable')){
			$('div.page_tab').removeClass('active');
			$('div#'+$(this).attr('title')).addClass('active');

			$('ul#page_tabs a').removeClass('active');
			$(this).addClass('active');

			var active_tab = $(this).attr('title');
			if(active_tab == 'video')
			{
				$('p.title_header span').html('VIDEO PLAYER');
				$('div#video_options').addClass('hidden');
				$('p.msg_pictures').addClass('hidden');
				$('p.video_player_title_box').css('visibility','visible');
			}
			if(active_tab == 'pics')
			{
				$('p.title_header span').html('PICTURES FROM THIS VIDEO');
				$('div#video_options').removeClass('hidden');
				$('p.msg_pictures').removeClass('hidden');
				$('p.video_player_title_box').css('visibility','hidden');
			}
		}

		return false;
	});

	//	Bottom tabs
	$('ul#bottom_scene_tabs a').click(function(){
		$('div#bottom_scenes_container ul').removeClass('active');
		$('div#bottom_scenes_container ul#bottom_'+$(this).attr('title')).addClass('active');

		$('ul#bottom_scene_tabs li').removeClass('active');
		$(this).parent('li').addClass('active');

		return false;
	});

	//	Rating
	$(this).mousemove(function(e){
		var offset = $('#rating_deep').offset();
		if(offset != undefined){
			var left = e.pageX - offset.left;
			var top = e.pageY - offset.top;
			var note = Math.round(left / 10);
			if(
				left > 0 &&
				left < $('div#rating_deep').css('width').substr(0,$('div#rating_deep').css('width').length-2) &&
				top > 0 &&
				top < $('div#rating_deep').css('height').substr(0,$('div#rating_deep').css('height').length-2)
			){
				$('span#user_current_vote').html(note);
				$('img#rating_bullet').css('left', left - 4 + 'px');
				$('div#rating_surface').css('width', left + 'px');
			}
		}
	});



	$('ul#video_qualities li.active a').click(function(){
		return false;
	});

	/*
	 *
	 * Player
	 *
	 * */

	player.flash(
		{
			src: "http://static.mofos.com/player/wide_ma_player.swf",
			'width': player.width(),
			'height': player.height(),
			wmode: "transparent",
			align: "middle",
			allowfullscreen:true,
			allowscriptaccess: "always",
			allownetworkaccess: "always",
			flashvars: {
				options: "/tour/scene_info/?scene_id="+scene_id+"&type=trailer&autoplay=0&show_info=1&ext="+ext+"&part=0"
			}
		},{version:"10.0.22"}
	);
	$('div#open_player_info_box').click(function(){
		toggle_scene_info_box();

	});
	$('a#close_player_info_box').click(function(event){
		toggle_scene_info_box();
		return false;
	});

	//lightbox affect
	$('a.lightbox').lightBox();
});

function toggle_scene_info_box(){
	$('div#player_info_box').toggle();
}

function toggle_info_box(){
	$('div#player_info_box').toggle();
}

function toggleJS_SceneInfo(){
	toggle_info_box();
}

function videostart() {
	$('div#after_video_play_link_box').remove();
 	$.ajax({
		url: "/tour/ajax_increment_trailer_count/",
		type: "post",
		data: {"scene_id" : scene_id}
	});
 }

function gotojoin(){
 window.location = '/tour/join/';
}

function toggleHdTabs(){
 gotojoin();
}

function videoFinish(){
	var addhtml = '<div id="after_video_play_link_box"><a id="after_video_play_link" href="/tour/join/" title="Click Here Now"></a></div>';
	$(addhtml).insertAfter($('div#player_box_trailer embed'));
}