// writeflash.js

// Some stupid var for tracking
var llactid = 12223;

function writeFlash (src, width, height, id, flashVars, isTransparent)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '" id="' + id + '">');
	document.write('<param name="movie" value="' + src + '">');
	document.write('<param name="quality" value="high">');
	if (isTransparent == true) 
	{
		document.write('<param name="wmode" value="transparent">');
	}
	document.write('<param name="FlashVars" value="' + flashVars + '">');
	document.write('<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" name="' + id + '" FlashVars="' +  flashVars + '" ');
	if (isTransparent == true) 
	{
		document.write('wmode="transparent"');
	}
	document.write('></embed>');
	document.write('</object>');
}

function beginHTML ()
{
	document.write('<body onload="loadMenuXML()">');
	document.write('<div id="pageContainer">');
	document.write('<div id="page">');
	document.write('<div id="header">');
	flashVars="theURL=" + window.location.href;
	writeFlash("/files/header.swf", "960", "100%", "top", flashVars, true);
	document.write('</div> <!-- header -->');
	document.write('<div id="headerSpacer"></div>');
}

function beginHTML404 ()
{
	document.write('<body onload="onLoad404()">');
	document.write('<div id="pageContainer">');
	document.write('<div id="page">');
	document.write('<div id="header">');
	flashVars="theURL=404";
	writeFlash("/files/header.swf", "960", "100%", "top", flashVars, true);
	document.write('</div> <!-- header -->');
	document.write('<div id="headerSpacer"></div>');
}

function onLoad404 ()
{
	loadMenuXML();
	redirect();
}

function redirect ()
{
	window.location = "http://www.florical.com/";
}

function endHTML ()
{
	document.write('<div id="footer">');
	document.write('<div id="bottomBar">');
	flashVars="theURL=" + window.location;
	writeFlash("/files/bottombar.swf", "960", "21", "bottombar", flashVars, true);
	document.write('</div> <!-- bottomBar -->');
	document.write('<div id="footerMenu">');
	document.write('</div> <!-- footerMenu -->');
	document.write('<script src="http://t2.trackalyzer.com/trackalyze.js" type="text/JavaScript"><\/script>');
	document.write('</div> <!-- footer -->');
	document.write('</div> <!-- page -->');
	document.write('</div> <!-- pageContainer -->');
	document.write('</body>');
}

function buildFooterMenu(theMenu)
{
	theHTML = "<div class='spacer5'></div>";
	categoryNodes = theMenu.getElementsByTagName("category");
	for (i = 1; i < categoryNodes.length; i++)
	{
		theHTML += "<div class='menuCategoryContainer'>";
		theHTML += "<div class='topShadow'>";
		theHTML += categoryNodes[i].attributes.getNamedItem("title").value.toUpperCase();;
		theHTML += "</div> <!-- topShadow -->";
		theHTML += "<div class='menuCategoryLink'>";
		theHTML += "<a href='";
		theHTML += categoryNodes[i].attributes.getNamedItem("url").value;
		theHTML += "'>";
		theHTML += categoryNodes[i].attributes.getNamedItem("title").value.toUpperCase();
		theHTML += "</a>";
		theHTML += "</div> <!-- menuCategoryLink -->";
		
		theHTML += "<div class='menuLinksContainer'>";
		linkNodes = categoryNodes[i].getElementsByTagName("link");
		for (j = 0; j < linkNodes.length; j++)
		{
			theHTML += "<div class='menuLink'>";
			theHTML += "<a href='";
			theHTML += linkNodes[j].attributes.getNamedItem("url").value;
			theHTML += "'>";
			theHTML += linkNodes[j].attributes.getNamedItem("title").value;
			theHTML += "</a>";
			theHTML += "</div> <!-- menuLink -->";
		}
		theHTML += "</div> <!-- menuLinksContainer -->";
		theHTML += "</div> <!-- menuCategoryContainer -->";
	}
	theHTML += "<div class='clear'></div>";
	document.getElementById("footerMenu").innerHTML = theHTML;
}

function loadMenuXML()
{
	xmlhttp = null;
	
	if (window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xmlhttp != null)
	{
		xmlhttp.onreadystatechange = xmlStateChange;
		xmlhttp.open("GET","/menu/menu.xml",true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
}

function xmlStateChange()
{
	if (xmlhttp.readyState == 4)
	{
		// 4 = "loaded"
		if (xmlhttp.status==200)
		{
			buildFooterMenu(xmlhttp.responseXML.documentElement);
		}
		else
		{
			alert("Error retrieving menu XML");
		}
	}
}

function resizeFlash (theHeight)
{
	//alert("resize to " + theHeight);
	document.getElementById("header").style.height = theHeight + "px";
	
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		var ffversion=new Number(RegExp.$1);
		if (ffversion < 3)
		{
			window.scrollBy(0, 1);
			window.scrollBy(0, -1);
		}
	}
}

function windowOrDocument()
{
	if (navigator.appName.indexOf("Microsoft") != -1) 
	{
        return window;
    }
    else 
	{
        return document;
    }
}

// DEPRECATED
function embedVideo(videoURL, imageURL, videoWidth, videoHeight, autoLoad, autoPlay)
{
	flashVars = "videoURL=" + videoURL;
	flashVars += "&imageURL=" + imageURL;
	flashVars += "&videoWidth=" + videoWidth;
	flashVars += "&videoHeight=" + videoHeight;
	flashVars += "&autoLoadVideo=" + autoLoad;
	flashVars += "&autoPlayVideo=" + autoPlay;
	
	document.write('<div class="centerContainer">');
	
	writeFlash("/files/videoplayer.swf", videoWidth + 4, videoHeight + 28, "video", flashVars, true);
	
	document.write('</div> <!-- centerContainer -->');
}

function embedVideoPlayer(videoURL, imageURL, videoWidth, videoHeight, autoLoad, autoPlay)
{
	flashVars = "videoURL=" + videoURL;
	flashVars += "&imageURL=" + imageURL;
	flashVars += "&videoWidth=" + videoWidth;
	flashVars += "&videoHeight=" + videoHeight;
	flashVars += "&autoLoadVideo=" + autoLoad;
	flashVars += "&autoPlayVideo=" + autoPlay;
	
	document.write('<div class="centerContainer">');
	
	writeFlash("/files/videoplayer.swf", videoWidth + 4, videoHeight + 28, "video", flashVars, true);
	
	document.write('</div> <!-- centerContainer -->');
}

function embedFlashPlayer(flashURL, imageURL, flashWidth, flashHeight, autoLoad, autoPlay)
{
	flashVars = "flashURL=" + flashURL;
	flashVars += "&imageURL=" + imageURL;
	flashVars += "&flashWidth=" + flashWidth;
	flashVars += "&flashHeight=" + flashHeight;
	flashVars += "&autoLoadFlash=" + autoLoad;
	flashVars += "&autoPlayFlash=" + autoPlay;
	
	document.write('<div class="centerContainer">');
	
	writeFlash("/files/flashplayer.swf", flashWidth + 4, flashHeight + 28, "animation", flashVars, true);
	
	document.write('</div> <!-- centerContainer -->');
}

function embedFlash(flashURL, flashWidth, flashHeight, isTransparent)
{
	flashVars = "";
	
	document.write('<div class="centerContainer">');
	
	writeFlash(flashURL, flashWidth, flashHeight, "flash", flashVars, isTransparent);
	
	document.write('</div> <!-- centerContainer -->');
}
