//Variables

var enableFlash = true; //True: detect flash, False: disable flash
var forceFlash = false; //True: use flash only and override 'enableFlash', False: do nothing
var enableCookie = true; //True: allow sending a cookie, False: disallow sending a cookie
var debug = false; //Enable debuging alerts

//////////////////////////
// Do not change        //
var STATIC = 0;
var FLASH = 1;

var hasFlash = false; //Query this variable from scripts for flash detection

var html = new Array();
var flashCanPlay = false;

var isWinIE = (navigator.userAgent &&
	navigator.userAgent.toLowerCase().indexOf("msie") > -1 &&
	navigator.appVersion.toLowerCase().indexOf("win") > -1);
// End do not change    //
//////////////////////////

function writeStyleLink() {
	if (isWinIE) {
		//Write Windows IE stylesheet link
		document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"global.css\">");
	} else {
		//Write other stylesheet link
		document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"global.css\">");
	}
}

function detectFlash() {
	if (enableFlash) {
		if (debug)
			alert("Detecting flash...");

		//Check for cookie
		if (hasCookie()) {
			if (debug)
				alert("Cookie found.");

			if (getHasFlash()) {
				hasFlash = true;
				if (debug)
					alert("Cookie said has flash.");
			} else
			if (debug) {
				alert("Cookie said no flash.");
			}
			return;
		}

		//No cookie, continue detect
		var FlashMode = 0;
		//Detect for netscape
		if (navigator.plugins && navigator.plugins.length > 0)
		{
			if (navigator.plugins["Shockwave Flash"])
			{
				var plugin_version = 0;
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");

				for (var i = 0; i < words.length; ++i)
				{
					if (isNaN(parseInt(words[i])))
						continue;
					plugin_version = words[i];
				}
				if (plugin_version >= 6)
				{
					var plugin = navigator.plugins["Shockwave Flash"];
					var numTypes = plugin.length;
					for (j = 0; j < numTypes; j++)
					{
						mimetype = plugin[j];
						if (mimetype)
						{
							if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("swf") != -1))
								FlashMode = 1;
							// Mac wierdness
							if (navigator.mimeTypes["application/x-shockwave-flash"] == null)
								FlashMode = 0;
						}
					}
				}
			}
		} else
		//Detect for IE
		if (isWinIE)
		{
			document.write(
				'<SCR' + 'IPT LANGUAGE=VBScript\> \n' +
				'on error resume next \n' +
				'flashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 6)))\n' +
				'</SCR' + 'IPT\> \n'
			);
			FlashMode = (flashCanPlay ? 1 : 0);
		}

		hasFlash = (FlashMode == 1);
		
		if (debug)
			alert("Detect said " + (hasFlash ? "flash" : "no flash"));

		//Save cookie
		setHasFlash(hasFlash);
	}
}

/** Creates a slot for a named snipet */
function makeSnipet(name) {
	name = String(name);
	html[name] = new Array(2);
	html[name][STATIC] = new String("");
	html[name][FLASH] = new String("");
}

/** Sets the html or text for the named snipet */
function setSnipet(name, type, txt) {
	html[String(name)][parseInt(type)] = String(txt);
}

/** Writes the named sniped to the document */
function writeSnipet(name) {
	name = String(name);

	//Write appropriate snipet
	if (hasFlash) {
		document.write(html[name][FLASH]);
	} else {
		document.write(html[name][STATIC]);
	}
}

/** Save flash status in a cookie (expires tomorrow) */
function setHasFlash(f) {
	if (!enableCookie)
		return;

	var d = new Date();
	d.setTime(d.getTime() - 1000*60*60*24);
	document.cookie = "hasFlash=" + String(f) +
		";expires=" + d.toGMTString();
}

function hasCookie() {
	if (!enableCookie)
		return false;

	if (!document.cookie || document.cookie.length <= 0)
		return false;
	return (document.cookie.indexOf("hasFlash=") > -1 ||
		document.cookie.indexOf("indexVisited=") > -1);
}

/** Load flash status from a cookie */
function getHasFlash() {
	var i = document.cookie.indexOf("hasFlash=");
	if (i == -1)
		return false;
	return (document.cookie.indexOf("true") > -1);
}

//Main

if (forceFlash) {
	hasFlash = true;
	enableFlash = true;
} else {
	detectFlash();
}

if (!hasFlash) {
	//Preload nav images
	var img = new Image();
	img.src = "images/daisy.jpg"
	
}
