var onloadarray = '';
$(document).ready(function(){
	eval(onloadarray);
});

var onunloadarray = '';
/*
function onunloadfunction_commonjs(){
		eval(onunloadarray);
}
window.unload=onunloadfunction_commonjs;
*/
/*---------------------------------------------------*/
var sms_gewinspiel_loschen=false;
var gs_fertig=new Array();
gs_fertig[1]=$.cookies.get('gs_fertig_1');
gs_fertig[2]=$.cookies.get('gs_fertig_2');
gs_fertig[3]=$.cookies.get('gs_fertig_3');
gs_fertig[4]=$.cookies.get('gs_fertig_4');
gs_fertig[5]=$.cookies.get('gs_fertig_5');
gs_fertig[6]=$.cookies.get('gs_fertig_6');
gs_gestartet=$.cookies.get('gs_gestartet');

gs_status=gs_berechneStatus();
onloadarray+='gs_preloadImages();';
function gs_preloadImages(){
	image1 = new Image(); 
	image1.src = "/typo3conf/ext/sms_gewinnspiel/res/spargelbund.png";
	
	image2 = new Image(); 
	image2.src = "/typo3conf/ext/sms_gewinnspiel/res/0von4.png";
	
	image3 = new Image(); 
	image3.src = "/typo3conf/ext/sms_gewinnspiel/res/1von4.png";
	
	image4 = new Image(); 
	image4.src = "/typo3conf/ext/sms_gewinnspiel/res/2von4.png";
	
	image5 = new Image(); 
	image5.src = "/typo3conf/ext/sms_gewinnspiel/res/3von4.png";
	
	image9 = new Image(); 
	image9.src = "/typo3conf/ext/sms_gewinnspiel/res/4von4.png";
	
	image6 = new Image(); 
	image6.src = "/typo3conf/ext/sms_gewinnspiel/res/Gewinnformular.png";
	
	image7 = new Image(); 
	image7.src = "/typo3conf/ext/sms_gewinnspiel/res/doppelschild.png";
	
	image8 = new Image(); 
	image8.src = "/typo3conf/ext/sms_gewinnspiel/res/spargel.png";
}

function gs_showKorbAndSpargeln(){
	if(sms_gewinspiel_loschen){
		$.cookies.set('gs_gestartet', 'nein', {path: '/'});
		gs_gestartet=false;
	}
	if(gs_gestartet=='ja'){
		$('.gs_element').each(function(i){
			if(!gs_istGemacht($(this).attr("id"))){
				//ak este nebola urobena
				if(gs_status<4){
					$(this).addClass('gs_element_1');
				}else{
					$(this).addClass('gs_element_4spargel');
				}	
				$(this).css({'display':'block'});
			}
		});
		$('#gs_korb_'+gs_status).css({'display':'block'});
		gs_showKorbText();
	}
}

function gs_istGemacht(uid){
	istgemacht=false;
	for(i=1;i<gs_fertig.length;i++){
		if(gs_fertig[i]==uid){
			istgemacht=true;
		}
	}
	return istgemacht;
}

function gs_clickonelement(uid){
	/* store data */
	if(!gs_istGemacht(uid)){
		if(gs_status==4){
			gs_status=6;
			//$.cookies.set('gs_status', gs_status, {path: '/'});
			$.cookies.set('gs_fertig_5', '123456', {path: '/'});
			gs_fertig[5]='123456';
			gs_fertig[6]=uid;
			$.cookies.set('gs_fertig_6', uid, {path: '/'});
			/* animate */
			$('#'+uid).fadeOut("slow");
			$('#gs_korb_4').fadeOut("slow");
			$('#gs_korb_6').fadeIn("slow");
		}else{
			gs_status++;
			//$.cookies.set('gs_status', gs_status, {path: '/'});
			$.cookies.set('gs_fertig_'+gs_status, uid, {path: '/'});
			gs_fertig[gs_status]=uid;
			/* animate */
			$('#'+uid).fadeOut("slow");
			$('#gs_korb_'+(gs_status-1)).fadeOut("slow");
			$('#gs_korb_'+gs_status).fadeIn("slow");
			gs_showKorbText();
		}
		gs_showKorbText();
	}
}

function gs_berechneStatus(){
	counter=0;
	for(i=1;i<gs_fertig.length;i++){
		if(gs_fertig[i]!=null && gs_fertig[i]!='null' && gs_fertig[i]!='a_a'){
			counter++;
		}		
	}
	return counter;
}

function gs_showKorbText(){
	if(gs_status==4){
		$('#gs_korb_4 .inner').html('<span class="link1"><a href="http://www.abraham.de/index.php?id=1101">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span><span class="link2"><a href="#" onclick="return makeKorb4von4();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>');
	}else if(gs_status==6){
		$('#gs_korb_6 .inner').html('<span><a href="http://www.abraham.de/index.php?id=1102">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>');
	}else{
		
	}
}

function makeKorb4von4(){
	gs_status++;
	//$.cookies.set('gs_status', gs_status, {path: '/'});
	$.cookies.set('gs_fertig_'+gs_status, '123456', {path: '/'});
	$('#gs_korb_'+(gs_status-1)).fadeOut("slow");
	$('#gs_korb_'+gs_status).fadeIn("slow");
	gs_showKorbText();
	return false;
}


function spielstarten(){
	$.cookies.set('gs_gestartet', 'ja', {path: '/'});
	$.cookies.set('gs_fertig_1', 'a_a', {path: '/'});
	$.cookies.set('gs_fertig_2', 'a_a', {path: '/'});
	$.cookies.set('gs_fertig_3', 'a_a', {path: '/'});
	$.cookies.set('gs_fertig_4', 'a_a', {path: '/'});
	$.cookies.set('gs_fertig_5', 'a_a', {path: '/'});
	$.cookies.set('gs_fertig_6', 'a_a', {path: '/'});
}


function showgewinformular(){
	if(gs_status>3){
		$('#sms_gewinspiel_gewinformular').css({'display':'block'});
	}
}
