/**
 *
 *  On init  procedure 
 *
 */
//alert(os+" - "+browser+" - "+browserVersion);

expressInstallCancelled = true;
expressInstallError = true;

function init() {
	//alert(version["rev"]);
	if ((version["major"] == 9 && version["rev"] >= 20) || version["major"] > 9) {
		loadFlash();
	} else if (version["major"] >= 6) {
		if (!expressInstallCancelled || !expressInstallError) {
			if (version["major"] == 6 && version["rev"] < 65) {
				// do not load
			} else {
				//alert("dang?");
				//loadFlash();
			}
		}
	}
}

function removeHash() {
	window.location.hash = "";
}

/**
 *
 *  Main function for inserting Flash
 *
 */

var flashIsLoaded = false;
var flashHeight = -1;

function loadFlash() {
	document.getElementsByTagName("html")[0].style.overflow = "hidden";
	var so = new SWFObject("main.swf?infoBrowser="+browser+"&infoBrowserVersion="+browserVersion+"&infoOS="+os, "osc_001", "100%", "100%", "9");
	//so.useExpressInstall("expressinstall.swf");
	so.addParam("allowScriptAccess", "always");
	so.write("wrapper");
	flashIsLoaded = true;
	document.getElementById("wrapper").style.visibility = "visible";
	flashHeight = document.body.clientHeight;
	resizeHeight(flashHeight);
}


/**
 *
 *  Functions for handling events in ExpressInstall
 *
 *	Todo: Admininstallerblock in Firefox.
 *
 */

var expressInstallCancelled = false;
var expressInstallError = false;

function onExpressInstallCancel() {
	
}

function onExpressInstallError() {
	
}


/**
 *
 *  Functions for handling browser resize and flash resize according to its dynamic content
 *
 */

function handleBrowserResize() {
	//if (flashHeight > document.body.clientHeight) {
	//	resizeHeight(flashHeight);
	//} else {
		resizeHeight(document.body.clientHeight);
	//}
}

function resizeHeight(height) {
	//if(document.all && !document.getElementById) {
	//	document.all['wrapper'].style.pixelHeight = height;
	//} else {
		//alert(document.body.clientHeight);
		//if (height > document.body.clientHeight) {
		height += "px";
		document.getElementById("wrapper").style.height = height;
		//} else {
		//	document.getElementById('wrapper').style.height = document.body.clientHeight;
		//}
		
	//}
}

function resizeWidth(width) {
	//if(document.all && !document.getElementById) {
	//	document.all['wrapper'].style.pixelWidth = width;
	//} else {
		document.getElementById("wrapper").style.width = width;
	//}
}


/**
 *
 *  Functions for redirecting according to progressive enhancement
 *
 */

function getParameter(type) {
	var pn = "";
	if (type == "hash") {
		pn = window.location.hash;
	} else {
		pn = window.location.pathname;
	}
	if (pn.length > 1) {
		pn = pn.substring(1, pn.length);
		var p = pn.split("/")[0];
		var v = null;
		if (pn.length > p.length+1) {
			v = pn.substring((p.length+1), pn.length);
		}
		return [p, v]
	} else {
		return false;
	}
}

function hideWrapper() {
	if ((version["major"] == 9 && version["rev"] >= 20) || version["major"] > 9) {
		document.getElementById("wrapper").style.visibility = 'hidden';
	}
}


/**
 *
 *  ASAP procedure
 *
 */

var version = deconcept.SWFObjectUtil.getPlayerVersion();
var locationIdentifyer = "go";

if (location.search == "" || location.search == "?") {
	sp = "";
} else {
	sp = location.search;
}

if ((version["major"] == 9 && version["rev"] >= 20) || version["major"] > 9) {

	if (window.location.pathname != "/" && window.location.pathname != "") {
		var q = getParameter("pathname");
		if (q[0] == locationIdentifyer) {
			if (q[1] != null) {
				window.location = location.protocol+"//"+location.host+"/"+sp+"#"+q[0]+"/"+q[1];
			}
		}
	}
	
//} else if ((version["major"] == 6 && version["rev"] >= 65) || version["major"] >= 7) {
	// do nothing and let expressinstall work it later
} else {
	var q = getParameter("hash");
	if (q[0] == locationIdentifyer) {
		if (q[1] != null) {
			window.location = location.protocol+"//"+location.host+"/"+q[0]+"/"+q[1];
		}
	}
}


window.onresize = handleBrowserResize;
window.onload = init;
