$(document).ready(function(){

	//SCREENS DEFAULTS
	$('.thumbs:first, .thumbs li div:first').show();
	$('.thumbs li label').animate({opacity:0.5},1);
	$('.thumbs li label:first').animate({opacity:1},1);
	
	//VIDEOS DEFAULT
	$('.videoSlideshow:first, .videoSlideshow li div:first').show();
	$('.videoSlideshow li label').animate({opacity:0.5},1);
	$('.videoSlideshow li label:first').animate({opacity:1},1);

	//SCREENS CLICK FUNC
	$('.thumbs li label').click(function(){
		$('.thumbs li label').animate({opacity:0.5},100);
		$('.thumbs li div').hide();
		$(this).animate({opacity:1},100);
		$(this).parent('li').children('div').fadeIn(150);
	});
	
	//VIDEOS CLICK FUNC
	$('.videoSlideshow li label').click(function(){
		$('.videoSlideshow li label').animate({opacity:0.5},100);
		$('.videoSlideshow li div').hide();
		$(this).animate({opacity:1},100);
		$(this).parent('li').children('div').fadeIn(150);
	});

	//NAVIGATION DEFAULTS
	$('#gameInfo').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/gameinfo.png) top left no-repeat'});
	$('#screenshots').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/screenshots.png) top left no-repeat'});
	$('#features').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/features.png) top left no-repeat'});
	$('#trailer').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/trailer.png) top left no-repeat'});
	$('#submenuBtn05 a').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/videosbtn.png) bottom left no-repeat'});
	$('#externalNav li a#movie').css({'background':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+lang+'/morebtn.png) top left no-repeat'});
	
	//VIDEO SECTIONS AND SCREENSHOTS CSS BACKGROUND
	$('.thumbs, #videoContainer').css({'background-image':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+platform+'.png)', 'background-repeat': 'no-repeat'});
	$('#videoContaineriPad').css({'background-image':'url(http://media01.gameloft.com/web_mkt/minisites/shrek-forever-after/iphone/images/'+platform+'big.png)', 'background-repeat': 'no-repeat'});
	
	/*
	//NAVIGATION FUNCTION
	$('a#gameInfo').hover(
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/gameinfo.png) bottom left no-repeat'}) },
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/gameinfo.png) top left no-repeat'}) }
		);
	$('a#screenshots').hover(
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/screenshots.png) bottom left no-repeat'}) },
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/screenshots.png) top left no-repeat'}) }
		);
	$('a#features').hover(
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/features.png) bottom left no-repeat'}) },
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/features.png) top left no-repeat'}) }
		);
	$('a#trailer').hover(
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/trailer.png) bottom left no-repeat'}) },
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/trailer.png) top left no-repeat'}) }
		);

	//EXTERNAL NAV FUNCTION
	$('a#submenuBtn05').hover(
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/videosbtn.png) top left no-repeat'}) },
		function() { $(this).css({'background':'url(iphone/images/'+lang+'/videosbtn.png) top left no-repeat'}) }
		);
	*/


	//SCREENS PAGER
		var init = 0;
		var maximo = $('.thumbs ul').size() -1; // PAGER MAX VALUE

		if ( init == 0 ){
			$('.screensPrev').animate({opacity:0.3},100);
			$('.thumbs_1, .videoSlideshow_1').hide();
		}

		$('.screensPrev').click(function(){
			if (init > 0)
			{
				$('.thumbs li label, .videoSlideshow li label').animate({opacity:0.5},100);
				$('.thumbs li div, .videoSlideshow li div').hide();
				$('.screensPrev, .screensNext').animate({opacity:1},100);
				$('.thumbs_'+init).hide();
				$('.videoSlideshow_'+init).hide();
				init--;
				$('.videoSlideshow_'+init+' li label').animate({opacity:0.5},1);
				$('.videoSlideshow_'+init+' li label:first').animate({opacity:1},1);
				$('.videoSlideshow_'+init+' li div:first').show();
				$('.videoSlideshow_'+init).fadeIn(250);
				
				$('.thumbs_'+init+' li label').animate({opacity:0.5},1);
				$('.thumbs_'+init+' li label:first').animate({opacity:1},1);
				$('.thumbs_'+init+' li div:first').show();
				$('.thumbs_'+init).fadeIn(250);
				
				if ( init == 0 ){
					$('.screensPrev').animate({opacity:0.3},100);
				}
			}
		});

		$('.screensNext').click(function(){
			if (init < maximo)
			{
				$('.thumbs li label, .videoSlideshow li label').animate({opacity:0.5},0);
				$('.thumbs li div, .videoSlideshow li div').hide();
				$('.screensPrev, .screensNext').animate({opacity:1},100);
				$('.thumbs_'+init).hide();
				$('.videoSlideshow_'+init).hide();
				init++;
				$('.videoSlideshow_'+init+' li label').animate({opacity:0.5},1);
				$('.videoSlideshow_'+init+' li label:first').animate({opacity:1},1);
				$('.videoSlideshow_'+init+' li div:first').show();
				$('.videoSlideshow_'+init).fadeIn(250);
				
				$('.thumbs_'+init+' li label').animate({opacity:0.5},1);
				$('.thumbs_'+init+' li label:first').animate({opacity:1},1);
				$('.thumbs_'+init+' li div:first').show();
				$('.thumbs_'+init).fadeIn(250);
				if ( init == maximo ){
					$('.screensNext').animate({opacity:0.3},100);
				}
			}
		});

			
		//JSCROLL PANE
		$('.scrollPane').jScrollPane({
			showArrows:true,
			scrollbarWidth:10,
			arrowSize:30
		});
		
		$('#subcontentContainer_03').hide();
		
		//LOOP FOR SECTION'S EVENT
		for (var i=1; i < 6; i++){
			$('#submenuBtn0' + i).click(function(){
				var id_subSec = this.id.split("submenuBtn")[1];
				showSubSection(id_subSec);
			})
		}
		//READS URL AND CHECKS
		var loc = window.location.href;
		if (loc.indexOf('#') != -1)
		{
			var subSection = loc.split('#')[1];
			var totalSubSections = {"info":"01","screens":"02","feats":"03","trailers":"04","videos":"05"};

			if (typeof totalSubSections[subSection] != "undefined"){
				showSubSection(totalSubSections[subSection]);
			}
		}
			
});

		//SECTION SWITCH ANIMATION
		function showSubSection(sec){
			$('#subcontentContainer_01, #subcontentContainer_02, #subcontentContainer_03, #subcontentContainer_04, #subcontentContainer_05').hide();
			$('#subcontentContainer_' + sec).fadeIn(350);
			$('#submenu li a').css({'background-position':'top left'});
			$('#submenuBtn' + sec).find('a').css({'background-position':'bottom left'});
		}

		function completeUrl (element)
		{
			var loc = window.location.href;
			if (loc.indexOf('#') != -1)
			{
				var subSection = loc.split('#')[1];
				element.href = element.href + '#' + subSection;
			}
			return true;
		}
