var fullscreen = false;

$(document).ready(function() {
	embedIntroFlash();
	
	$(".bt_concours").click(function(){
		$("#zone_concours").css("display", "block");
		$("#zone_reglements").css("display", "none");
		return false;
	});
	
	$(".bt_reglements").click(function(){
		$("#zone_concours").css("display", "none");
		$("#zone_reglements").css("display", "block");
		return false;
	});
	
	var hash = window.location.hash.substr(1);
	
	if (hash == "merci") {
		$("#zone_concours").css("display", "none");
		$("#zone_reglements").css("display", "none");
		$("#zone_merci").css("display", "block");
		
		window.location.hash = "";
	} else if (hash == "refus") {
		$("#zone_concours").css("display", "none");
		$("#zone_reglements").css("display", "none");
		$("#zone_refus").css("display", "block");
		
		window.location.hash = "";
	}
});

function toggleFullScreen() {
	if (!fullscreen) {
		swfobject.removeSWF("intro_flash");
		
		$("div#intro_container").append('<div id="intro_flash"></div>');
		
		$("div#main_container").fadeIn(
			300,
			embedMainFlash
		);
		
		fullscreen = true;
	} else {
		swfobject.removeSWF("main_flash");
		
		$("div#main_container").append('<div id="main_flash"></div>');
		
		$("div#main_container").fadeOut(
			300,
			embedIntroFlash
		);
		
		fullscreen = false;
	}
	
	return false;
}

function embedIntroFlash() {
	flashvars = {};
	
	params = {};
	params.salign = "TL";;
	params.scale = "noscale";
	params.bgcolor = "#000000";
	params.wmode = "opaque";
	params.menu = false;
	params.allowFullscreen = "true";
	params.allowScriptAccess = "always";
	
	attributes = {};
	attributes.id = "intro_flash";
	
	swfobject.embedSWF("/resources/flash/legendesdici/legendes_intro.swf?v2", "intro_flash", "950", "400", "9.0.0","http://legendesdici.com/swf/expressInstall.swf", flashvars, params);
}

function embedMainFlash() {
	var startDate = new Date("July 05, 2010 00:00:00");
	var currentDate = new Date();
	
	var week = currentDate.getWeek() - startDate.getWeek();
	
	flashvars = {};
	flashvars.gateway = "http://legendesdici.com/amfphp/gateway.php";
	flashvars.cdn = "http://legendesdici.s3.amazonaws.com";
	flashvars.address = "http://legendesdici.com";
	flashvars.week = week;
	
	params = {};
	params.salign = "TL";
	params.scale = "noScale";
	params.bgcolor = "#000000";
	params.menu = false;
	params.allowFullscreen = "true";
	params.allowScriptAccess = "always";
	
	attributes = {};
	attributes.id = "main_flash";
	
	swfobject.embedSWF("http://legendesdici.com/swf/legendes-dici.swf?w=" + week, "main_flash", "100%", "100%", "10.0.0", "http://legendesdici.com/swf/expressInstall.swf", flashvars, params, attributes);
	
	SWFAddress.setId(attributes.id);
}

function openReglements() {
	window.open("http://legendesdici.s3.amazonaws.com/pdf/reglements.pdf","reglements ","menubar=0,status=0,toolbar=0,width=550,height=650"); 
}

Date.prototype.getWeek = function() {
	var onejan = new Date(this.getFullYear(),0,1);
	return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
