$(document).ready(function(){
	
	var clearQueue = true;
	var gotoEnd = true;
	
	//IF THIS GAME HAS MORE THAN ONE PLATFORM

	if(enable_overlay)
	{
		$('#minisiteOverlay').show();
		$('#platformSelector ul').slideDown(400);
	}
	
	$('body').click(function()
		{
			$('#minisiteOverlay').fadeOut(300); 
			$('#platformSelector ul').slideUp(400);
		});
	//

	//RELATED GAMES URLS
	/*
	$('#related001').css({'background-image':'url('+ urlOverlay +'images/related_games/001.png)'});
	$('#related002').css({'background-image':'url('+ urlOverlay +'images/related_games/002.png)'});
	$('#related003').css({'background-image':'url('+ urlOverlay +'images/related_games/003.png)'});
	$('#related004').css({'background-image':'url('+ urlOverlay +'images/related_games/002.png)'});
	$('#related005').css({'background-image':'url('+ urlOverlay +'images/related_games/003.png)'});
	*/
	$('#relatedGames li a img').hover(
		function(){
			$(this).css({'left':'-57px'});
			$(this).parent('a').parent('li').animate({top:-10},{duration:200,easing:'easeOutQuad'});
		},
		function(){
			$(this).css({'left':'0px'});
			$(this).parent('a').parent('li').stop(clearQueue, gotoEnd).animate({top:0},{duration:200,easing:'easeOutQuad'});
		}
	);

	//
	$('.selectorContainer li').hover(
		function(){
			$(this).parent('ul').css({'background-position':'top right'});
			$(this).children('ul').slideDown(550,'easeOutBack');
		},
		function(){
			$(this).parent('ul').css({'background-position':'top left'});
			$(this).children('ul').stop(clearQueue, gotoEnd).fadeOut(200);
		}
	);

	$('.selectorContainer ul li img').animate({opacity:.7});

	$('.selectorContainer ul li').hover(
		function(){
			$(this).css({'background':'#d0d0d0','font-weight':'bold'});
			$(this).children('a').css({'color':'#000'});
			$(this).children('img').animate({opacity:1},0);
		},
		function(){
			$(this).css({'background':'#3f3f3f','font-weight':'normal'});
			$(this).children('a').css({'color':'#fff'});
			$(this).children('img').animate({opacity:.7},0);
		}
	);

	$('#socialBtns li').hover(
		function() { $(this).css({'background-position':'top right'}); },
		function() { $(this).css({'background-position':'top left'}); }
	);

	$('#linkRss').hover(
		function(){
			$(this).children('ul').animate({opacity:1,top:-167},{duration:400,easing:'easeOutQuad'});
		},
		function(){
			$(this).children('ul').stop(clearQueue, gotoEnd).animate({opacity:0,top:-300},300).animate({top:100},0);
		}
	);

	$('#linkNewsletter').hover(
		function(){
			$(this).children('ul').animate({opacity:1,top:-110},{duration:400,easing:'easeOutQuad'});
		},
		function(){
			$(this).children('ul').stop(clearQueue, gotoEnd).animate({opacity:0,top:-300},300).animate({top:100},0);
		}
	);

	$('#newsletterSubmit').click(function(){
		$(this).parent('li').parent('ul').stop(clearQueue, gotoEnd).animate({opacity:0,top:-300},300).animate({top:100},0);
	});
	
	// Tracking system
	$('#buyBtn img').click(function(){
		var sAux = $(this).attr('id');		
		trackBuyButtonClick ( sAux.substring(sAux.indexOf('_')+1) );
		$(this).parent('a#buyBtn').attr('target', '_blank');
		return true;
	});
	
	// Open all the RSS feeds
	$('#linkRssAll').click(function(){		
		$('#linkRss ul li a').each(function(index)
		{			
			var sLink = $(this).attr('href');
			if (sLink != '#' )
				window.open(sLink, '_blank');
		});		
		return false;
	});	

	$('#linkGL a, #linkFacebook a, #linkTwitter a, #linkYoutube a, #linkMyspace a, #linkBuzz a, #linkGlive a,#relatedGames a, #linkDailyMotion a').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		extraClass: "toolTip",
		fixPNG: false,
		top: 20,
		left: 0,
		showBody: " - "
	});

	$('#platformSelector li ul li a').click(function() { var sAux = $(this).attr('id'); return completeUrl( document.getElementById (sAux) )} );

	$('#languageSelector li ul li a').click(function() { var sAux = $(this).attr('id'); return completeUrl( document.getElementById (sAux) )} );
});

//STAY IN THE SAME SECTION WHEN CHANGING LANGUAGE
function completeUrl (element)
{
	var loc = window.location.href;						
	if (loc.indexOf('#') != -1)
	{
		var subSection = loc.split('#')[1];
		element.href = element.href + '#' + subSection;
	}
	return true;
}
