if (typeof window.Gore === "undefined") {
	window.Gore = {};
}
	
if (typeof Gore.local === "undefined") {
	Gore.local = {};
}

if (typeof Gore.local.isModal === "undefined") {
	Gore.local.isModal = true;
}

if (typeof Gore.local.lang === "undefined") {
	Gore.local.lang = "en-US";
}

if (typeof Gore.local.widgetType === "undefined") {
	Gore.local.widgetType = "windchill";
}

if (typeof Gore.local.calcText === "undefined") {
	Gore.local.calcText = "Windstopper Calculator";	
}

if (typeof Gore.local.calcLinkId === "undefined") {
	Gore.local.calcLinkId = "goreCalcLink";
}

if (typeof Gore.local.baseHref === "undefined") {
	Gore.local.baseHref = "";
}



Gore.local.loadGoreDependencies = function () {
	
	var calcLink = document.getElementById(Gore.local.calcLinkId);
	if (calcLink) {
		// Load dependencies
		var hd = document.getElementsByTagName("head")[0];
		if (hd) {
			var css = document.createElement("link");
			css.rel = "stylesheet";
			css.type = "text\/css";
			css.href = Gore.local.baseHref + "container.css";
			hd.appendChild(css);
			
			var ydm = document.createElement("script");
			ydm.type = "text\/javascript";
			ydm.src = Gore.local.baseHref + "yahoo-dom-event.js";
			hd.appendChild(ydm);
	
			var cont = document.createElement("script");
			cont.type = "text\/javascript";
			cont.src = Gore.local.baseHref + "container-min.js";
			hd.appendChild(cont);
			
			var swfo = document.createElement("script");
			swfo.type = "text\/javascript";
			swfo.src = Gore.local.baseHref + "calc/swfobject.js";
			hd.appendChild(swfo);
		}
		Gore.local.dependenciesLoaded = window.setInterval(
			function () {	
				if (typeof YAHOO !== "undefined" && 
				    typeof YAHOO.widget !== "undefined" && 
				    typeof YAHOO.widget.Panel !== "undefined" && 
				    typeof YAHOO.util !== "undefined" && 
				    typeof YAHOO.util.Dom !== "undefined" && 
				    typeof YAHOO.util.Event !== "undefined") {	
					window.clearInterval(Gore.local.dependenciesLoaded);
					Gore.local.createGoreCalc(calcLink);
				}
			}, 250);
	}
}

Gore.local.createGoreCalc = function (calcLink) {
	Gore.local.calcPanel = new YAHOO.widget.Panel(
		"flashPanel", 
		{
			width:"500px",
			height:"500px",
			underlay:"none",
			close:true,
			visible:false,
			draggable:false,
			modal:Gore.local.isModal,
			fixedcenter: false,
			constraintoviewport: false
		}
	);
	
	Gore.local.calcPanel.setHeader("Calculator");
	var swfDiv = document.createElement("div");
	swfDiv.id = "flashCalc";
	Gore.local.calcPanel.setBody(swfDiv);
	Gore.local.calcPanel.render(document.body);
	
	swfURL = Gore.local.baseHref + "calc/calculator.swf";
	
	var so = new SWFObject(swfURL, "socalculator", "500", "500", "8");	
	so.addParam("wmode", "transparent");
	so.addParam("align", "middle");
	so.addParam("salign", "");
	so.addParam("allowscriptaccess", "sameDomain");
	so.addParam("allowfullscreen", "false");
	so.addParam("menu", "true");
	//so.addParam("bgcolor", "transparent");
	so.addParam("devicefont" ,"false");
	so.addParam("scale", "showall");
	so.addParam("loop", "true");
	so.addParam("play", "true");
	so.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer"); 
	so.addVariable("mode", Gore.local.widgetType);
	so.addVariable("cultureID", Gore.local.lang);
	so.addVariable("labelsPath", Gore.local.baseHref + "xml/calculator_" + Gore.local.lang.substring(0,2) + ".xml");
	
	so.write(swfDiv.id);
		
	
	// Create and insert link
	var a = document.createElement("a");
	a.href = "#";
	if (calcLink.title.length > 0) {
		Gore.local.calcText = calcLink.title;
	}
	a.onclick = function (e) {
		e = e || window.event;
		Gore.local.calcPanel.show();
		YAHOO.util.Event.preventDefault(e);
	}
	//a.appendChild(document.createTextNode(Gore.local.calcText));
	a.appendChild(document.createElement("img"));
	a.lastChild.setAttribute("src",Gore.local.calcText);
	a.lastChild.setAttribute("border",0);
	calcLink.appendChild(a);
}
Gore.local.domReady = window.setInterval(
	function () {
		if (document.getElementsByTagName("body")[0]) {
			window.clearInterval(Gore.local.domReady);
			Gore.local.loadGoreDependencies();
		}
	}, 250);