function setGroup(grp){
	setPresentationViewed(true);
	updateGUI();
	try{	
	//setCountryToFlash();
		//alert("set group to"+grp);
		document.getElementById("worldcup").setGroup(grp);
		//$('#worldcup').get(0).setGroup(grp);
		//alert("group is set");
	}catch(e){
		//alert(e);
		setTimeout("setGroup("+grp+")",500);
	}
}

function selectGroup(grp){
	try{	
	//setCountryToFlash();
		//alert("set group to"+grp);
		document.getElementById("worldCupConsensus").selectGroup(grp);
		//$('#worldcup').get(0).setGroup(grp);
		//alert("group is set");
	}catch(e){
		//alert(e);
		setTimeout("selectGroup("+grp+")",500);
	}
}
function setFinalViewed(viewed){
	if(viewed){
		$.cookie('finalView',viewed)
	}else{
		$.cookie('finalView', null);
	}
}
function isFinalViewed(){
	if($.cookie('finalView')!=null){
		return true;
	}
	return false;
}

function setPresentationViewed(viewed){
	if(viewed){
		$.cookie('presentationViewed',viewed)
	}else{
		$.cookie('presentationViewed', null);
	}
}
function isPresentationViewed(){
	if($.cookie('presentationViewed')!=null){
		return true;
	}
	return false;
}
function updateGUI(){
	hide($('#worldcupFinal'));
	$('#maincenter').width(800);
	
	if(isFinalViewed()){
		stage2()
	}else{
		//cherher si il y a un cookie pour la presentation
		//si oui
		if(isPresentationViewed()){
			//Afficher le votepanel
			switchPanel(true);
		}else{
			//sinon
			//afficher le presentation panel
			switchPanel(false);
		}
	}
}

function switchPanel(vote){
	if(vote){
		show($('#worldcup'));
		hide($('#worldcupIntro'));
	}else{
		hide($('#worldcup'));
		show($('#worldcupIntro'));
	}
	$(window).load();
}

function show(ptr){
	//position: absolute; top: 80 px; left: 100 px;
	//ptr.removeClass('hideux');
	ptr.height(620);
}
function hide(ptr){
	//position: absolute; top: 80 px; left: 100 px;
	//ptr.addClass('hideux');
	ptr.height(0);
}

function resetPresentation(){
	setPresentationViewed(false);
	updateGUI();
	
}

function stage2(){
	setFinalViewed(true);
	hide($('#worldcup'));
	hide($('#worldcupIntro'));
	$('#maincenter').width(1049);
	show($('#worldcupFinal'));

}
function resetFinal(){
	setFinalViewed(false);
	setPresentationViewed(true);
	updateGUI();
}

function showPres(ptr){
	//position: absolute; top: 80 px; left: 100 px;
	//ptr.removeClass('hideux');
	ptr.height(515);
}

$(document).ready(function() {
	setPresentationViewed(true);
	setFinalViewed(true);
	updateGUI();
	$("a[rel]").overlay({
		mask: 'darkred',
		effect: 'apple',
		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			// load the page specified in the trigger
			//wrap.load(this.getTrigger().attr("href"));
			wrap.flashembed({src:this.getTrigger().attr("href"),width: "635",height:"515"});
		}
	});
});
