var re = new RegExp("^.*goa.com$");
if (re.test(document.domain)) document.domain="goa.com";

var COOKIE_NAME = "goacomv3";

jQuery.fn.resizeSite = function() {
	var hc = $('#portal>.content_space').height();
	var hb = $('#portal>.block_space').height();
	if(hc > hb) $('#portal>.block_space').height(hc);
	else		$('#portal>.content_space').height(hb);			
};

// Function de changement de couleur du background
function fadeBackgroundColor(sColor, nDuration){
	$('body').animate({backgroundColor:sColor}, nDuration);	
	$.cookie(COOKIE_NAME, sColor, { path: '/'});
}
function setBackgroundColor(sColor){
	$('body').css('background-color', sColor);	
	$.cookie(COOKIE_NAME, sColor, { path: '/'});
}

// Google stats
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try{ 
	var pageTracker = _gat._getTracker("UA-2860046-1");
	pageTracker._trackPageview();
} catch(err) {} 


// SplashScreens
var splashScreens = ["splashscreen_pangya_season4", "splashscreen_lol"];

function detectSplashScreen()
{
	if(document.referrer.indexOf('goa.com') == -1)
	{
		for(i = 0; i < splashScreens.length; i++)
		{
			var currentSplashScreen = splashScreens[i];
			var COOKIE_NAME_SPLASHSCREEN = currentSplashScreen;
			$go = $.cookie(COOKIE_NAME_SPLASHSCREEN);
			if ($go == null) {
				$.cookie(COOKIE_NAME_SPLASHSCREEN, currentSplashScreen, { path: '/', expires: 7 });
				$('body').append('<iframe id="splashscreen" name="splashscreen" src="/' + currentSplashScreen + '" allowtransparency="true" scrolling="no" style="z-index:100;border:none;position:absolute;top:0;left:0;width:100%;height:'+$(document).height()+'px"></iframe>');
				return;			
			}
		}
	}
}
function removeSplashscreen()
{
	$('#splashscreen').remove();
}

// Initialise
$(document).ready(function(){
	
	detectSplashScreen();

	// On change la couleur du fond
	$c = $.cookie(COOKIE_NAME);
	if ($c != null) {
		$('body').css('background-color', $c);
	}

	//Initialise le menu de la barre GOA.com
	$("#goa_bar ul:first").superfish({
		autoArrows:false,
		delay:500,
		animation:{opacity:'show'},
		speed:'normal'
	});	
	$("#goa_bar ul>ul").hide();
	
	// Blocks News 
	$(".lastinfos li:gt(3)").hide();
	$(".lastinfos .tabs a").click(function(){
		$(".lastinfos .btn_tab_selected").removeClass("btn_tab_selected").addClass("btn_tab");
		$(this).removeClass("btn_tab").addClass("btn_tab_selected");
		$(".lastinfos li").hide();
		var type = $(this).attr('rel');
		if(type == "all") type ="li";
		else type = "." + type;
		$(".lastinfos "+type+":lt(4)").show();
		$(this).resizeSite();
		return false;
	});
	
	if($(document).pngFix)
		$(document).pngFix();
		
	// promo homepage
	if($(".promo a").length > 1)
	{	
		function changePromo()
		{
			var current = $(".promo a:first");
			var next = $(".promo a:last");
			next.insertBefore(current);
			current.fadeOut('slow');
			next.fadeIn('slow');
		}
		window.setInterval(changePromo, 4000);
	}
});

//Event appele lorsque les images sont chargees
$(window).load(function(){
	$(this).resizeSite();
});


// Image promo homepage