$(document).ready(function(){

	//GLOBAL STOP VARS
	var clearQueue = true;
	var gotoEnd = true;

	//SCREENS DEFAULTS
	$('.screenSelection ul:first, .screenSelection li div:first').show();
	$('.screenSelection li label').animate({opacity:0.5},1);
	$('.screenSelection li label:first').animate({opacity:1},1);	

	//VIDEOS DEFAULTS
	$('.videoSelection ul:first, .videoSelection li div:first').show();
	$('.videoSelection li label').animate({opacity:0.5},1);
	$('.videoSelection li label:first').animate({opacity:1},1);	

	//SCREENS CLICK FUNC
	$('.slideshow li label').click(function(){
		$('.slideshow li label').animate({opacity:0.5},100);
		$('.slideshow li div').hide();
		$(this).animate({opacity:1},100);
		$(this).parent('li').children('div').fadeIn(150);
	});
	
	$('.slideshow li label img').hover(
		function(){ $(this).animate({opacity:0.8},200); },
		function(){ 
			$(this).stop(clearQueue,gotoEnd);
			$(this).animate({opacity:1},200);
		}
	);
	
	//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);
	});
	
	$('.videoslideshow li label img').hover(
		function(){ $(this).animate({opacity:0.8},200); },
		function(){ 
			$(this).stop(clearQueue,gotoEnd);
			$(this).animate({opacity:1},200);
		}
	);
/*
	//LOCALIZE MAIN MENU
	$('.scores').css({'background':'url(images/'+lang+'/btn_scores.png) top left no-repeat'});
	$('.videoReplays').css({'background':'url(images/'+lang+'/btn_videoreplays.png) top left no-repeat'});
	$('.gameInfo').css({'background':'url(images/'+lang+'/btn_gameinfo.png) top left no-repeat'});
	$('.screenshots').css({'background':'url(images/'+lang+'/btn_screenshots.png) top left no-repeat'});
	$('.videos').css({'background':'url(images/'+lang+'/btn_videos.png) top left no-repeat'});
	$('.characters').css({'background':'url(images/'+lang+'/btn_characters.png) top left no-repeat'});
	$('.courses').css({'background':'url(images/'+lang+'/btn_courses.png) top left no-repeat'});
	*/
	/*
	$('.scores').mouseover(function(){
		$('.scores').css({'background':'url(images/'+lang+'/btn_scores.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.scores').css({'background':'url(images/'+lang+'/btn_scores.png) top left no-repeat'});
	});
	
	$('.videoReplays').mouseover(function(){
		$('.videoReplays').css({'background':'url(images/'+lang+'/btn_videoreplays.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.videoReplays').css({'background':'url(images/'+lang+'/btn_videoreplays.png) top left no-repeat'});
	});
	
	$('.gameInfo').mouseover(function(){
		$('.gameInfo').css({'background':'url(images/'+lang+'/btn_gameinfo.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.gameInfo').css({'background':'url(images/'+lang+'/btn_gameinfo.png) top left no-repeat'});
	});
	
	$('.screenshots').mouseover(function(){
		$('.screenshots').css({'background':'url(images/'+lang+'/btn_screenshots.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.screenshots').css({'background':'url(images/'+lang+'/btn_screenshots.png) top left no-repeat'});
	});
	
	$('.videos').mouseover(function(){
		$('.videos').css({'background':'url(images/'+lang+'/btn_videos.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.videos').css({'background':'url(images/'+lang+'/btn_videos.png) top left no-repeat'});
	});
	
	$('.characters').mouseover(function(){
		$('.characters').css({'background':'url(images/'+lang+'/btn_characters.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.characters').css({'background':'url(images/'+lang+'/btn_characters.png) top left no-repeat'});
	});
	
	$('.courses').mouseover(function(){
		$('.courses').css({'background':'url(images/'+lang+'/btn_courses.png) bottom left no-repeat'});
	}).mouseout(function(){
		$('.courses').css({'background':'url(images/'+lang+'/btn_courses.png) top left no-repeat'});
	});
	*/
	
	// VIDEO REPLAYS FUNCTIONS
	
	$('#youtubePager span a, #gallerybtnPrev, #gallerybtnNext').hover(
			function(){ $(this).animate({opacity:0.5},50) },
			function(){ $(this).animate({opacity:1},50) }
		);
	
	$('#youtubePager span img.pagerDisabled').animate( {opacity:0.5},50 );
	
	$('#vidList li').hover(
		function(){
			$(this).css({'border':'2px solid #98AF15'});
			$(this).children('label').css({'background-position':'top right','color':'#fff'});
		},
		function(){
			$(this).css({'border':'2px solid #98AF15'});
			$(this).children('label').css({'background-position':'top left','color':'#000'});
		}
	);
	
	$('.youtubeSelects h3').click(function(){
		$('.youtubeSelects div').slideUp(300);
		$(this).parent('div.youtubeSelects').children('div').slideDown(300);
	});
	
	$('#youtubePager span img.btnPager').click(function(){
		$('#loader').show();
	});
	
	//SCREENS PAGER
		var init = 0;
		var maximo = $('.screenSelection ul').size() -1; // PAGER MAX VALUE
		
		if ( init == 0 ){
			$('#screenArrowLeft').animate({opacity:0.3},100);
		}
		
		$('#screenArrowLeft').click(function(){
			if (init > 0)
			{
				$('.slideShow li label').animate({opacity:0.5},100);
				$('.slideShow li div').hide();
				$('#screenArrowLeft, #screenArrowRight').animate({opacity:1},100);
				$('.screenshots_'+init).hide();
				init--;
				$('.screenshots_'+init+' li label').animate({opacity:0.5},1);
				$('.screenshots_'+init+' li label:first').animate({opacity:1},1);
				$('.screenshots_'+init+' li div:first').show();
				$('.screenshots_'+init).fadeIn(250);
				if ( init == 0 ){
					$('#screenArrowLeft').animate({opacity:0.3},100);
				}
			}
		});
		
		$('#screenArrowRight').click(function(){
			if (init < maximo)
			{
				$('.slideShow li label').animate({opacity:0.5},0);
				$('.slideShow li div').hide();
				$('#screenArrowLeft, #screenArrowRight').animate({opacity:1},100);
				$('.screenshots_'+init).hide();
				init++;
				$('.screenshots_'+init+' li label').animate({opacity:0.5},1);
				$('.screenshots_'+init+' li label:first').animate({opacity:1},1);
				$('.screenshots_'+init+' li div:first').show();
				$('.screenshots_'+init).fadeIn(250);
				if ( init == maximo ){
					$('#screenArrowRight').animate({opacity:0.3},100);
				}
			}
		});
		
		//VIDEOS PAGER
		var init = 0;
		var maximo2 = $('.videoSelection ul').size() -1; // PAGER MAX VALUE
		
		if ( init == 0 ){
			$('#videoArrowLeft').animate({opacity:0.3},100);
		}
		
		$('#videoArrowLeft').click(function(){
			if (init > 0)
			{
				$('.slideShow li label').animate({opacity:0.5},100);
				$('.slideShow li div').hide();
				$('#videoArrowLeft, #videoArrowRight').animate({opacity:1},100);
				$('.videos_'+init).hide();
				init--;
				$('.videos_'+init+' li label').animate({opacity:0.5},1);
				$('.videos_'+init+' li label:first').animate({opacity:1},1);
				$('.videos_'+init+' li div:first').show();
				$('.videos_'+init).fadeIn(250);
				if ( init == 0 ){
					$('#videoArrowLeft').animate({opacity:0.3},100);
				}
			}
		});
		
		$('#videoArrowRight').click(function(){
			if (init < maximo2)
			{
				$('.slideShow li label').animate({opacity:0.5},0);
				$('.slideShow li div').hide();
				$('#videoArrowLeft, #videoArrowRight').animate({opacity:1},100);
				$('.videos_'+init).hide();
				init++;
				$('.videos_'+init+' li label').animate({opacity:0.5},1);
				$('.videos_'+init+' li label:first').animate({opacity:1},1);
				$('.videos_'+init+' li div:first').show();
				$('.videos_'+init).fadeIn(250);
				if ( init == maximo2 ){
					$('#videoArrowRight').animate({opacity:0.3},100);
				}
			}
		});
	
	//LOOP FOR SECTION'S EVENT
	for (var i=1; i < 8; 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 = {"scores":"01","videoReplays":"02","gameInfo":"03","screenshots":"04","videos":"05", "characters":"06","courses":"07"};
		
		if (typeof totalSubSections[subSection] != "undefined"){
			showSubSection(totalSubSections[subSection]);
		}
	}

});

		//SECTION SWITCH ANIMATION
		function showSubSection(sec){
			$('#subcontentContainer_01, #subcontentContainer_02, #subcontentContainer_03, #subcontentContainer_04, #subcontentContainer_05, #subcontentContainer_06, #subcontentContainer_07').hide();
			$('#submenu li a').css({'background-position':'top left'});
			$('#submenuBtn' + sec).find('a').css({'background-position':'bottom left'});
			$('#subcontentContainer_' + sec).fadeIn(350); return false;
		}
		
		function completeUrl (element)
		{
			var loc = window.location.href;						
			if (loc.indexOf('#') != -1)
			{
				var subSection = loc.split('#')[1];
				element.href = element.href + '#' + subSection;
			}
			return true;
		}

		
function avatar_begins(){
		document.getElementById('selected_vincent').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/vincentavatar.png";	
		document.getElementById('selected_jade').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/jadeavatar.png";	
		document.getElementById('selected_chris').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/chrisavatar.png";	
		document.getElementById('selected_mark').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/markavatar.png";	
		document.getElementById('selected_elena').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/elenaavatar.png";	
		document.getElementById('selected_rose').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/roseavatar.png";	
		document.getElementById('selected_jack').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/jackavatar.png";	
		document.getElementById('selected_peter').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/peteravatar.png";	
			
		
		}
function changeChar(name,text){
	//document.getElementById('player').innerHTML = "<img src='images/characters/"+name+"image.png' alt='"+ name +"' />";
   document.getElementById('player_big').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/"+name+"image.png";
    document.getElementById('charNameImg').src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/"+name+".png";
    document.getElementById('charNameImg').alt = name;
    avatar_begins();
   // document.getElementById('selected_'+name).src = "images/characters/"+name+"avatar.png";
    document.getElementById('selected_'+name).src = "http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/"+name+"avatarselected.png";
    document.getElementById('charNametext').innerHTML = text;
     document.getElementById('player').innerHTML = "<img src='http://media01.gameloft.com/web_mkt/minisites/lets-golf-2/images/characters/"+name+"image.png' alt='"+ name +"' />";



} // document.getElementById('charStatsImg').src = "images/characters/stats/"+name+"stats.png";
