// JavaScript Document

$(document).ready(function(){
		$('#talent').click(function(e){
				e.preventDefault();
				$("#talent_dropdown").slideToggle('fast');
		});

		$('.close').click(function(){
				$("#talent_dropdown").slideUp('fast');
		});
		
		$('#contact_drop').click(function(e){
				$('#contact_slide').slideToggle('fast');
		});

		$('#contact_slide #close').click(function(e){
				$('#contact_slide').slideUp('fast');
		});

		
		//MUSIC VIDEO PRESENTATION
		$('.cont_a a').ceebox({video:true});
		var _max = $('.cont_a').length;
		for(var i = 0; i <= _max; i += 1){
			$('.cont_a').delay(500).eq(i).fadeIn(300);
		}
		$('.cont_a').hover(
			function(){
			  $(this).children('.div_bot').show();
			  $(this).children('.offset_div').show();
			  $(this).children('.text_cont').addClass('desc_active');
			  $(this).children('.vid_description').css('font-weight', 'bold');
			  $(this).children('.small_play_a').show();
			  $(this).children('.small_play_b').show();
			}, function(){
			  $(this).children('.div_bot').hide();
			  $(this).children('.offset_div').hide();
			  $(this).children('.text_cont').removeClass('desc_active');
			  $(this).children('.vid_description').css('font-weight', 'bold');
			  $(this).children('.small_play_a').hide();
			  $(this).children('.small_play_b').hide();
			}
		);

		//TALENT PRESENTATION
		//info display for fields
		$(".display_info").click(function(){
				$('#display_client').children().remove();
				$('#display_agency').children().remove();
				var empty = '';
				$('#display_client').html(empty);
				$('#display_agency').html(empty);
				$('#thumbnail_container div.display_active').removeClass('display_active');
				$(this).addClass('display_active');
				if($(this).children('.client').text() == ''){
						$('#display_client').text(' ');
				} else {
						var client = $('.display_active .client').clone();
						$('#display_client .shown').fadeOut(600);
						client.appendTo("#display_client").fadeIn(600).addClass('shown');
				}
				if($(this).children('.agency').text() == ''){
						$('#display_agency').text(' ');	
				} else {
						var agency = $('.display_active .agency').clone();
						$('#display_agency .shown').fadeOut(600);
						agency.appendTo("#display_agency").fadeIn(600).addClass('shown');
				}
		});	

		//picture gallery
		$('.img_slide #photo_drop').click(function(){
			$(this).toggleClass('p_drop_active');
			$('#pic_cont').slideToggle('fast');
		});

		$('.c_gal').ceebox({imageGallery:true});
		
		$('.vid_thumbs').hover(
		function(){
				$(this).children('.vid_desc').css("color", "#00b4f9");
				$(this).stop().animate({ 
						borderBottomColor: "#4a8095",
						borderTopColor: "#4a8095",	
						borderLeftColor: "#4a8095",
						borderRightColor: "#4a8095",
						backgroundColor: "#202020"
				}, 350);
		},
		function(){
				$(this).children('.vid_desc').css("color", "#848484");
				$(this).stop().animate({ 
						borderBottomColor: "#21282A",
						borderTopColor: "#21282A",	
						borderLeftColor: "#21282A",
						borderRightColor: "#21282A",
						backgroundColor: "#21282A"
				}, 350);					
		});

			$('#display_agency').text(' ');	
			$('#display_client').text(' ');
		  
		  $('#play_button').click(function(){
				var first_thumb = $('#thumbnail_container a:eq(0)');
				$(this).remove();
				vid_id = $(first_thumb).attr('href');
				clip_title = $(first_thumb).attr('title');
				loadNewVideo(vid_id, clip_title, true);
				vimeo_player_loaded();

				$('#display_client .shown').remove();
				$('#display_agency .shown').remove();
				var empty = '';
				$('#display_client').html(empty);
				$('#display_agency').html(empty);
				$('#thumbnail_container .display_active').removeClass('display_active');
				$('.display_info:first').addClass('display_active');
				if($('.display_info:first').children('.client').text() == ''){
						$('#display_client').text(' ');
				} else {
						var client = $('.display_active .client').clone();
						$('#display_client .shown').fadeOut(600);
						client.appendTo("#display_client").fadeIn(600).addClass('shown');
				}
				if($(".display_info:first").children('.agency').text() == ''){
						$('#display_agency').text(' ');	
				} else {
						var agency = $('.display_active .agency').clone();
						$('#display_agency .shown').fadeOut(600);
						agency.appendTo("#display_agency").fadeIn(600).addClass('shown');
				}


		  });

		  $('#thumbnail_container a').click(function(e){
				e.preventDefault();
				$('.vid_thumbs').removeClass('vid_thumbs_active');
				$(this).addClass('vid_thumbs_active');
				vid_id = $(this).attr('href');
				clip_title = $(this).attr('title');
				loadNewVideo(vid_id, clip_title, true);
		  });
	
		//HOME PAGE
		
		var active_html =	$('#feat_cont .feat_cont_active span').html();
		var active_text = "" + active_html;
		$('#feat_text p').text(active_text).show();
		
		$('#feat_cont a').hover(function(){
			$('#feat_text p').html('');
			var active_html =	$(this).children('span').html();
			var active_text = "" + active_html;
			$('#feat_text p').text(active_text).show();
		
		}, function(){
			var active_html =	$('#feat_cont .feat_cont_active span').html();
			var active_text = "" + active_html;
			$('#feat_text p').text(active_text).show();
		
		});

		$('#feat_cont a').click(function(e){
				e.preventDefault();
				$('.home_thumbs').removeClass('feat_cont_active');
				$(this).addClass('feat_cont_active');
				var text_num = $(this).index();
				vid_id = $(this).attr('href');
				clip_title = $(this).attr('title');
				loadNewVideo(vid_id, clip_title, true);

				var active_html =	$('#feat_cont .feat_cont_active span').html();
				var active_text = "" + active_html;
				$('#feat_text p').text(active_text).show();


		});

		$('#play_reel').click(function(){
				var first_thumb = $('#feat_cont a:eq(0)');
				$(this).remove();
				vid_id = $(first_thumb).attr('href');
				clip_title = $(first_thumb).attr('title');
				loadNewVideo(vid_id, clip_title, true);
				vimeo_player_loaded();
		});

		
		
		//Global variables
		var flashvars = {
			'clip_id': '1',
			'server': 'vimeo.com',
			'show_title': 0,
			'show_byline': 0,
			'show_portrait': 0,
			'fullscreen': 1,
			'js_api': 1,
			'autoplay': 1,
			'wmode':'transparent'
		};
		var parObj = {
			'swliveconnect':true,
			'fullscreen': 1,
			'allowscriptaccess': 'always',
			'allowfullscreen':true,
			'wmode':'transparent'
		};
		var attObj = {};
		var oSwfId='myFlashID';
		var vimeoAPI;
		var autoPlay;
		var flag;
		//Helper function
		function fnHelp(d) {return document.getElementById(d);}
	
		function loadNewVideo(vid,title,ap) {
		
			$('#plname').html("Please wait while loading the video...");
			attObj.id= oSwfId;
			flashvars.clip_id= vid;
			var vp = fnHelp('videoPlayer');
					
			if(!vp) {
				fnHelp('vpContainer').innerHTML ='';
				vp = document.createElement("DIV");
				vp.id = 'videoPlayer';
				fnHelp('vpContainer').appendChild(vp);
			}
			
			swfobject.embedSWF("http://www.vimeo.com/moogaloop.swf",'videoPlayer','450','250','9.0.0','expressInstall.swf',flashvars,parObj,attObj);
			$('#plname').html(title);
		}

		//This method will get called when the movie gets loaded
		//Although the document says, this method can be overridden with js_onload parameter, I haven't had any luck with that.
		swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "450", "250", "9.0.0","expressInstall.swf", flashvars, params, attributes);

		function vimeo_player_loaded() {
			vimeoAPI = fnHelp(oSwfId);
			//vimeoAPI.api_addEventListener("onPlay","handleVimeoPlay");
			//vimeoAPI.api_addEventListener("onProgress","handleVimeoProgess");
			flag=true;
			//alert(autoPlay);
			if(autoPlay === true) {
				playVimeoVideo();
			}
			}	
		//This method will get called once when the movie gets played
		function handleVimeoPlay() {
			fnHelp('plwGif').style.visibility='visible';
			flag=true;
			//alert('x');
		}
		//This method will get called during movie playback with the number of seconds played as the attribute
		function handleVimeoProgess(data) {
			if(flag) {
				if(data > 0) {
					fnHelp('plwGif').style.visibility='hidden';
					flag=false;
				}
			}
		}	
		//This method get called as a call back method to API call (made from HTML page)
		//Moogaloop method wrappers

		function playVimeoVideo() {vimeoAPI.api_play();}
		function stopLoading() {vimeoAPI.api_unload();}
		function pauseVimeoVideo() {vimeoAPI.api_pause();}
		function seekToVimeoVideo(value) {vimeoAPI.api_seekTo(value);}
		function stopVimeoVideo() {vimeoAPI.api_seekTo(0);vimeoAPI.api_pause();}


});

