var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var defaultLeft = "";
var defaultHome = "index.html";
var movieRef = "";
var currentURL = document.location.href.split("#");
if (currentURL.length > 1)
	currentURL = currentURL[currentURL.length-1];
else
	currentURL = currentURL[0];
	
	
	
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(loadFlash);

function loadFlash ()
{	
	// initialize the DHTML History
       // framework
	   
	//window.alert("onload");
	
	var thelocal = document.location.href;
	var locationsplit = thelocal.split("/");
	var file = locationsplit[locationsplit.length-1];
	file = file.split("#");
	var fileleft = file[0];
	var fileright = file[1];
	
	var baseurl = fileleft;
	if (file.length >1)
		baseurl = fileright;
		
	var page = new PageQuery(window.location.search); 
	
	
	currentURL=baseurl;
	
	var reload = false;
	
	//window.alert("reload test");
	if (page.getValue("reload") == "true" || readCookie("reload") == "true")
	{
		reload = true;
		createCookie("reload","true",1)
		//window.alert("reload add");
	}
	
	if (page.getValue("reload") == "false")
	{
		reload = false;
		eraseCookie("reload");
		//window.alert("reload clear");
	}
	
	//this.params.reload
	
	
	if (page.getValue("edit") != "true")
	{
		if (reload == false && fileleft != defaultLeft)
		{
		
			if (fileleft.length > 0)
			{
				var newlocation = document.location.href.split("/");
				newlocation.pop();
				document.location = newlocation.join("/")+"/"+"#"+baseurl;
			}
			else
			{
				document.location = document.location+"#"+defaultHome;
			}
		}
		else
		{
		
			var so = new SWFObject("library/flash/c.swf?path=library/flash/heavyduty.swf", "theflash", "100%", "100%", "9.0.28.0", "#000000", true);
			so.addParam("scale", "noscale");
			
			//so.addParam("allowScriptAccess", "sameDomain");
			//so.addVariable("bookmarkable", "true");
			
			so.addParam("allowFullScreen", "true");
			so.useExpressInstall('library/swfobject1-5/expressinstall.swf');
			
			if (baseurl.length > 0)
				so.addVariable("baseurl", escape(baseurl));
			else
				so.addVariable("baseurl", escape(defaultHome));
			
			
			var keys = page.getParameters();
			
			
			for (var i = 0; i<keys.length;i++)
			{
				so.addVariable(keys[i], page.getValue(keys[i]));
			}
			//window.alert(document.getElementsByName("body").length);
			
			if (so.write("content"))
			{
			
				//  t - type of tag to check for (e.g., SPAN)
				//  c - class name
				//  p - CSS property
				//  v - value
		
				setStyleByClass("div","mustinstall","display","none");
				
				//  e - element type or id
				//  p - property
				//  v - value
				//  g - boolean 0: modify global only; 1: modify all elements in document
				//setStyleByTag("div", "display", "table", 1); 
				setStyleById("content", "display", "block");
			}
			
		}
		movieRef=thisMovie("theflash");
	}
	else
	{
		setStyleById("content", "display", "block");	
	}
}

// query string utilities
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

// swf instance finder
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		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 null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setHeight(newheight)
{
	//window.alert(newheight);
	document.getElementById("content").style.height = newheight + 'px';	
	document.getElementById("theflash").style.height = newheight + 'px';	
}

function setWidth(newwidth)
{
	//window.alert(newheight);
	document.getElementById("content").style.width = newwidth + 'px';	
	document.getElementById("theflash").style.width = newwidth + 'px';	
}

