// JavaScript Document
function getKidsBackground(){
	var nameEQ = "tateKidsBG=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i += 1) {
		var c = ca[i];
		while (c.charAt(0)==' ') { c = c.substring(1,c.length); }
		if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
	}
	return 1;
}

function setKidsBackground(background, imagesDir, tateKidsHomeURL, flash, flashDir){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+3);
	document.cookie = "tateKidsBG=" + escape(background) + "; expires=" + exdate.toGMTString();
	if (flash) {
		$('#flashTop').hide();
		$('#flashLeft').hide();
		switchBGFlash(background, imagesDir, flashDir);
		setTimeout(showBackground, 500);
	} else {
		switchBG(background, imagesDir, tateKidsHomeURL);
	}
}

function showBackground() {
	if ($.browser.mozilla) {
		$('#flashTop').show();
		$('#flashLeft').show();
	} else {
		location.reload();
	}
}

function switchBG(background, imagesDir, tateKidsHomeURL){
	document.getElementById("flashTop").innerHTML='<a href="' + tateKidsHomeURL + '"><img src="' + imagesDir + '/title_top' + background + '.jpg" alt="Tate Kids" /></a>';
	document.getElementById("flashLeft").innerHTML='<img src="' + imagesDir + '/title_left' + background + '.jpg" alt="" />';
	document.body.style.backgroundImage='url(' + imagesDir + '/far_right' + background + '.jpg)';
}

function switchBGFlash(background, imagesDir, flashDir){
	document.getElementById("flashTop").innerHTML='<a href="/">'
		+'<object type="application/x-shockwave-flash" '
		+'	data="' + flashDir + '/bg' + background + '_logo.swf" width="305" height="86" name="bg' + background + '_logo">'
		+'	<param name="movie" value="' + flashDir + '/bg' + background + '_logo.swf" />'
		+'	<img src="' + imagesDir + '/title_top' + background + '.jpg" alt="Tate Kids" />'
		+'</object></a>';
	
	document.getElementById("flashLeft").innerHTML='<object type="application/x-shockwave-flash" '
		+'	data="' + flashDir + '/bg' + background + '_bar.swf" width="98" height="1000" name="bg' + background + '_bar">'
		+'	<param name="movie" value="' + flashDir + '/bg' + background + '_bar.swf" />'
		+'	<a href="/"><img src="' + imagesDir + '/title_left' + background + '.jpg" alt="" /></a>'
		+'</object>';

	document.body.style.backgroundImage='url(' + imagesDir + '/far_right' + background + '.jpg)';
}

function loadKidsBG(imagesDir, tateKidsHomeURL){
	var backgroundNum = getKidsBackground();
	if(backgroundNum != 1){
		switchBG(backgroundNum, imagesDir, tateKidsHomeURL);
	}else{
		//alert("Default");
	}
}

function loadKidsBGFlash(imagesDir, flashDir){
	var backgroundNum = getKidsBackground();
	if(backgroundNum != 1){
		switchBGFlash(backgroundNum, imagesDir, flashDir);
	}else{
		//alert("Default");
	}
}

