﻿// ********************************* Javascript zur Kommunikation mit Flash *********************************

function splitCookie(myCookie){
	var flashCookie = document.cookie;
	
	if(flashCookie.indexOf("&") != -1){
		var tmp = flashCookie.split("&");
		
		if(tmp[0].indexOf("FlashIsPlaying") != -1){
			cookieWert = tmp[0].split("=");
		}else if(tmp[1].indexOf("FlashIsPlaying") != -1){
			cookieWert = tmp[1].split("=");
		}
	}else{
		if(flashCookie.indexOf("FlashIsPlaying") == -1)
			document.cookie = 'FlashIsPlaying=1';
		
		var cookieWert = flashCookie.split("=");
	}
	
	return cookieWert;
}

function switchPlayStatus(){
	
	var cookieWert = splitCookie(document.cookie);
	
	if(!document.cookie || isNaN(parseInt(cookieWert[1]))){
		// Cookie wurde noch nicht definiert
		// -> Button wurde zum ersten Mal geklickt
		// -> Film wird angehalten
		val = -1;
	}else{
		val = parseInt(cookieWert[1]) * -1;
	}
	
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*365);
	//document.cookie = 'FlashIsPlaying=' + val + '; expires='+a.toGMTString()+';';
	document.cookie = 'FlashIsPlaying=' + val + ';'; // Cookie expires when Browser is closed
	return false;
}

function getPlayStatus(){

	var cookieWert = splitCookie(document.cookie);
	
	if(cookieWert[1] == undefined || !document.cookie.indexOf("IsPlaying")){
		// Cookie wurde noch nicht definiert
		// -> Button wurde zum ersten Mal geklickt
		// -> Film wird angehalten
		document.cookie = 'FlashIsPlaying=1';
		cookieWert = splitCookie(document.cookie);

	}

	return cookieWert[1];
}
