function getAudioState(){
	var state = checkCookie('musicState');
	var currentState = true;
	if(state == "on"){
		$("#music").css('background-image','url("images/btn_music.png")');
		currentState = true;

	}
	if(state=="off"){
		$("#music").css('background-image','url("images/btn_music_off.png")');
		currentState = false;
		
	}
	return currentState;
}





function changeMusicState(){
	var state = checkCookie('musicState');
	var flashAnimation = getCookie("flashAnimationID");
	
	//background-image:url("../images/btn_music.png");
	if(state == "on"){// Current state is ON, should change to OFF
		$("#music").css('background-image','url("images/btn_music_off.png")');
		setCookie("musicState","off");
		if(flashAnimation != ""){ //Checks if there's a movie loaded
			if (navigator.appName.indexOf("Microsoft") != -1) 
		        window[flashAnimation].mute("off");
		    else 
		        document[flashAnimation].mute("off");
		}
	}
	else{
		if(state=="off"){// Current state is OFF, should change to ON
			$("#music").css('background-image','url("images/btn_music.png")');
			setCookie("musicState","on");
			if(flashAnimation != ""){ //Checks if there's a movie loaded
				//music.mute("on");
				
				if (navigator.appName.indexOf("Microsoft") != -1) 
			        window[flashAnimation].mute("on");
			    else 
			        document[flashAnimation].mute("on");
			}
		}
	}
}

function setCookie(c_name,value)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+365);
	document.cookie=c_name+ "=" +escape(value);
}

function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1){
			    c_start=c_start + c_name.length+1;
			    c_end=document.cookie.indexOf(";",c_start);
			    if (c_end==-1) c_end=document.cookie.length;
			    return unescape(document.cookie.substring(c_start,c_end));
		   }
	}
	return "";
}

function checkCookie(name){
	var state=getCookie(name);
	var musicState = "dunno";
	
	if (state!=null && state!=""){
		musicState = state;
	}
	else{
		setCookie(name,'on',365);
	}
	return musicState;
}

function toggleSignUp(){
	
	var isLocked = getCookie("signUpBlock");
		
	if(isLocked == "false")
		$("#signUpBox").toggle(500);
	
	$("#cemail").focus();
}

function resizePage(){
	var textSize = $(".Section1").css('height');
	if(textSize == undefined){
		textSize = $(".WordSection1").css('height');
	}
	
	if(textSize == 'auto'){
		resizePageExplorer();
	}
	else{
		textSize = textSize.substring(0,textSize.length-2);
		textSize = parseInt(textSize)+200;
		$("#mainContainerBox").css("height",''+textSize+'px');
		$("#PTRightSide").css('height',(textSize-100));
		$("#PTLeftSide").css('height',(textSize-100));
	}
}

function resizePageExplorer(){
	var version = jQuery.browser.version;
	var textSize = $(".Section1").height();
	if(textSize == undefined){
		textSize = $(".WordSection1").height();
	}
	var extraSize = 200; // used to fit text
	if(version == "7.0"){
		extraSize = 500;
	}
	textSize = parseInt(textSize)+extraSize;
	$("#mainContainerBox").css("height",''+textSize+'px');
	$("#PTRightSide").css('height',(textSize-100));
	$("#PTLeftSide").css('height',(textSize-100));
}


function activateMenuButton (id){
	var menuActive=["gamesActive","ebooksActive","videosActive","ducksAlphabetActive","forKidsActive","parentsTeachersActive","storeActive","aboutUsActive","signUpActive"];
	var menuInactive=["gamesMenuContainer","ebooksMenuContainer","videosMenuContainer","ducksAlphabetMenuContainer","forKidsMenuContainer","parentsTeachersContainer","storeMenuContainer","aboutUsMenuContainer","signUpMenuContainer"];

	for(var i = 0; i< menuActive.length; i++){
		if(id == menuActive[i]){
			$("#"+menuInactive[i]).css('display','none');
			$("."+menuActive[i]).css('display','block');
		}
		else{
			$("#"+menuInactive[i]).css('display','block');
			$("."+menuActive[i]).css('display','none');
		}	
	}
}

function checkLogin(){
	var isLoggedIn = true;
	if(getCookie("user") == ""){// Is user logged in ? if not, display Sign Up popup
		toggleSignUp();
		setCookie("signUpBlock","true");
		isLoggedIn = false;
	}
	return isLoggedIn;
}

function validateEmail (){
	 if($("#commentForm").valid()){
		// Set user email to gain access to ebooks & videos
		var emailAddress = $("#cemail").val();
		setCookie("signUpBlock","false");
		setCookie("user",emailAddress);
		sendEmailData(emailAddress);
		$("#signUpBox").toggle(500);
	 }
	 return false;
}

function sendEmailData (email){
	var emailEncoded = encodeURIComponent(email); 
	var query = "function=setEmail&email="+emailEncoded;
	$.get("include/SignUpManager.php",query, 
		function (data){
			//data = JSON.parse(data);
		}
	);
}
