// JavaScript Document
function actions (){ /* Opening main function */
	/* Actions to execute after the window has loaded go here. */
	
	/***********************************************
	Funtions for the Case Studies gallery
	***********************************************/
	$('.nav-case li').each(function(){
		$(this).click(
			function (){
				/* Defining a var with the full address to math the active content */
				var currentContent = "#main ." + $(this).attr('class');
				
				/* Removing the class of the current active div */
				$('#mainContent').find('.active').removeClass('active');
				
				/* Showing up the selected div */
				$('#mainContent').find(currentContent).slideDown(0);
				
				/* Adding the 'active' class to the current selection */
				$('#mainContent').find(currentContent).addClass('active');
				
				/* Hidding the other divs, but the one with the 'active' class */
				$('#mainContent').find('#main div:not(.active)').slideUp(0);
				
				/* Adding the 'active' class to the currently clicked button, to change to blue */
				$(this).addClass('active');
				
			});
	})
	
	
	/***********************************************
	Funtions for homapegae video player
	***********************************************/
	function initHoverEffect(){
		$('#homepageVideoCarousel .videoThumbContainer').each(function(){
		$(this).hover(
			function (){
				if(!($(this).hasClass('currentVideo'))){
					$($(this).find(".videoThumbTitle")).slideDown("fast");
				}
			},
			function (){
				if(!($(this).hasClass('currentVideo'))){
					$($(this).find(".videoThumbTitle")).slideUp("fast");
				}
			});
		})
	}
	initHoverEffect();
	
	function initVideoPlayer(){
			var currentVideoID;
			var videoTitle;
			
			currentVideoID = $('#homepageVideoCarousel .videoThumbContainer:first-child .thumbVideoTrigger').attr('id');
			videoTitle = $('#homepageVideoCarousel .videoThumbContainer:first-child .videoThumbTitle').text();
			
			$('#theVideo').empty();
			$('#homepageVideoCarousel .videoThumbContainer:first-child').addClass('currentVideo');
			$('#homepageVideoCarousel .videoThumbContainer:first-child .videoThumbTitle').hide();
			$('#homepageVideoCarousel:first-child').prepend("<div class='currentVideoCover'></div>");
			
			$('.videoTitle').empty();
			$('.videoTitle').append('Now Playing: ' + videoTitle);
			
			$('#currentlyPlaying').slideDown('fast');
			
			$('#theVideo').append("<object type='application/x-shockwave-flash' id='myytplayer' data='http://www.youtube.com/v/"+ currentVideoID +"?version=3&enablejsapi=1&playerapiid=ytplayer&autoplay=1' width='550' height='309'><param name='allowScriptAccess' value='always'><param name='bgcolor' value='#000000'><param name='allowFullScreen' value='true'></object>");
		}
	
	$('.bigPlayButton').click(function(event){
		event.preventDefault();
		initVideoPlayer();
	});
	
	function switchVideo(){
			var currentVideoID;
			var videoTitle;
			
			$('#homepageVideoCarousel .videoThumbContainer').each(function(){
				$($(this).find('.thumbVideoTrigger')).click(function(event){
					event.preventDefault();
					currentVideoID = $(this).attr('id');
					videoTitle = $(this).parent().find('.videoThumbTitle').text();
					$('#theVideo').empty();
					$('#homepageVideoCarousel .videoThumbContainer').each(function(){ $(this).removeClass('currentVideo'); });
					$(this).parent().addClass('currentVideo');
					$(this).parent().find('.videoThumbTitle').hide();
					$('#homepageVideoCarousel .videoThumbContainer').each(function(){ $(this).find('.currentVideoCover').remove(); });
					$(this).parent().prepend("<div class='currentVideoCover'></div>");
					
					$('.videoTitle').empty();
					$('.videoTitle').append('Now Playing: ' + videoTitle);
					
					//$('#theVideo').append("<iframe width='550' height='309' src='http://www.youtube.com/embed/"+currentVideoID+"' frameborder='0' allowfullscreen></iframe>");
					$('#theVideo').append("<object type='application/x-shockwave-flash' id='myytplayer' data='http://www.youtube.com/v/"+ currentVideoID +"?version=3&enablejsapi=1&playerapiid=ytplayer&autoplay=1' width='550' height='309'><param name='allowScriptAccess' value='always'><param name='bgcolor' value='#000000'><param name='allowFullScreen' value='true'></object>");
					$('#currentlyPlaying').slideDown('fast');
				});														   
		   	});
		}
	switchVideo();
	
	/***********************************************
	Funtions for gallery items
	***********************************************/
	$("a.grouped_elements").fancybox();
	
}; /* Closing main function */

window.onload = actions;
