$(document).ready(function(){
	
	var clearQueue = true;
	var gotoEnd = true;
	
	$('#socialBtns li').hover(
		function() { $(this).css({'background-position':'top right'}); },
		function() { $(this).css({'background-position':'top left'}); }
	);
	
	$('#linkRss').hover(
		function(){
			$(this).children('ul').fadeIn(300);
		},
		function(){
			$(this).children('ul')
				.stop(clearQueue, gotoEnd)
				.animate({opacity:0,top:-165},200)
				.animate({top:-135},0,function(){$('#linkRss ul').hide();})
				.animate({opacity:1},0);
		}
	);
	
	$('#linkNewsletter').hover(
		function(){
			$(this).children('ul').fadeIn(300);
		},
		function(){
			$(this).children('ul')
				.stop(clearQueue, gotoEnd)
				.animate({opacity:0,top:-110},200)
				.animate({top:-80},0,function(){$('#linkNewsletter ul').hide();})
				.animate({opacity:1},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;
}