// Tuksi Frontend - JavaScript
// Version 2006-04-13-AMA

var Tuksi = {
	
	// all onload events are collected here
	Load: function(){
				
		// sIFR setup and replacements
		//if(typeof sIFR == "function"){
			//sIFR.setup();
			//sIFR.replaceElement("div.mainOpeningHours h3", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#585858", sWmode: "Transparent", sCase: "upper"}));
			//sIFR.replaceElement("div.mainProductMenu h3", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#FFFFFF", sWmode: "Transparent", sCase: "upper"}));
			//sIFR.replaceElement("ul.mainContentMenu span.link", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#FFFFFF", sHoverColor: "#585858", sWmode: "Transparent", sCase: "upper", sFlashVars: "textalign=center"}));
			//sIFR.replaceElement("ul.mainContentMenu span.active", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#9dbec1", sHoverColor: "#585858", sWmode: "Transparent", sCase: "upper", sFlashVars: "textalign=center"}));
			//sIFR.replaceElement("ul.mainTopMenu span.link", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#9dbec1", sHoverColor: "#585858", sWmode: "Transparent", sCase: "upper", sFlashVars: "textalign=center"}));
			//sIFR.replaceElement("div.mainOpeningHours h3 span", named({sFlashSrc: "/newsite/flash/helvetica.swf", sColor: "#FF0000", sWmode: "Transparent", sCase: "upper"}));
		//}
		
		// reduce margins in content menu
		//this.calculateDeductionInMenu();
	},
	
	
	
 	loadFlash: function(sMovieUrl, iWidth, iHeight, sAlternativeUrl, sAlternativeImage, sTitle){
		var sReturn = "";
		if(this.FlashVersion() >= 6){
			sReturn += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + iWidth + "\" height=\"" + iHeight + "\" id=\"flashloader\" align=\"middle\">\n";
			sReturn += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
			sReturn += "<param name=\"movie\" value=\"" + sMovieUrl + "\" />\n";
			sReturn += "<param name=\"quality\" value=\"high\" />\n";
			//sReturn += "<param name=\"bgcolor\" value=\"#fbdca3\" />\n";
			sReturn += "<param name=\"wmode\" value=\"transparent\" />\n";
			sReturn += "<embed src=\"" + sMovieUrl + "\" quality=\"high\" wmode=\"transparent\" width=\"" + iWidth + "\" height=\"" + iHeight + "\" name=\"flashloader\" align=\"middle\" allowscriptaccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
			sReturn += "</object>\n";
			document.write(sReturn);
		} else {
			if (sAlternativeImage){
				
				if (sAlternativeUrl) 
					sReturn += "<a href=\"" + sAlternativeUrl + "\" title=\"" + sTitle + "\">\n";
				sReturn += "<img src=\"" + sAlternativeImage + "\" alt=\"" + sTitle + "\" title=\"" + sTitle + "\" />\n";
				
				if (sAlternativeUrl)
					sReturn += "</a>\n";
				document.write(sReturn);
			} else {
				document.location.href = sAlternativeUrl;
			}
		}
	},
	newWindow: function (strPage,strName){  

strSettings = 'fullscreen=yes,scrollbars=no,width=' + screen.width + ',height=' + screen.height + ',top=0,left=0';
 win = window.open(strPage,strName,strSettings)
      if (win.focus){
                    win.focus();
        }
 },


	ShowFocus: function(oThis, sImg){
		var oImg = oThis.getElementsByTagName("img")[0];
		if(oImg){
			if(oThis.className == "" ){
				oThis.className = "over";
			} else {
				oThis.className = "";
			}
			Tuksi.SwapImage(oImg, sImg);
		}
	},
	
	GetElementsByClassName: function(oElm, sTagName, oClassNames){
		var aElements = (sTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(sTagName);
		var aReturnElements = new Array();
		var aRegExpClassNames = new Array();
		if(typeof oClassNames == "object"){
			for(var i=0; i<oClassNames.length; i++){
				aRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
			}
		}
		else{
			aRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
		}
		var oElement;
		var bMatchesAll;
		for(var j=0; j<aElements.length; j++){
			oElement = aElements[j];
			bMatchesAll = true;
			for(var k=0; k<aRegExpClassNames.length; k++){
				if(!aRegExpClassNames[k].test(oElement.className)){
					bMatchesAll = false;
					break;
				}
			}
			if(bMatchesAll){
				aReturnElements.push(oElement);
			}
		}
		return (aReturnElements)
	},

	// Returns the height of an element with sElementId as id
	GetElementHeight: function(sElementId){
		var oElement;
		if (typeof(sElementId) != "object"){
			oElement = document.getElementById(sElementId);
		} else {
			oElement = sElementId;
		}
		if (oElement){ return oElement.offsetHeight }
	},

	// Returns the width of an element with sElementId as id
	GetElementWidth: function(sElementId){
		var oElement;
		if (typeof(sElementId) != "object"){
			oElement = document.getElementById(sElementId);
		} else {
			oElement = sElementId;
		}
		if (oElement){ return oElement.offsetWidth}
	},

	// Sets a specific height (iHeight) on an element with sElementId as id
	GetElementHeight: function(sElementId, iHeight){
		if (typeof(sElementId) != "object"){
			oElement = document.getElementById(sElementId);
		} else {
			oElement = sElementId;
		}
		if (oElement){
			oElement.style.height = iHeight + "px";
		}
	},

	// Sets a specific width (iHeight) on an element with sElementId as id
	GetElementWidth: function(sElementId, iWidth){
		if (typeof(sElementId) != "object"){
			oElement = document.getElementById(sElementId);
		} else {
			oElement = sElementId;
		}
		if (oElement){
			oElement.style.width = iWidth + "px";
		}
	},

	// Returns width of browser window
	GetWindowWidth: function(){
		var oHtml = document.getElementsByTagName("HTML")[0];
		if (oHtml) {
			return oHtml.offsetWidth
		}
	},

	// Returns height of browser window
	GetWindowHeight: function(){
		var oHtml = document.getElementsByTagName("HTML")[0];
		if (oHtml) {
			switch(Tuksi.BrowserData()){
				case "Safari":
				case "MSIE_50":
				case "MSIE_55":
				case "MSIE_60":
				return oHtml.offsetHeight
				break;

				case "Firefox":
				return oHtml.clientHeight
				break;

				case "MSIE_MAC":
				return document.body.clientHeight;
				break;
			}
		}
	},

	// Returns amount of pixels scrolled from the top
	GetScrollWindowHeight: function(){
		var oBody = document.getElementsByTagName("BODY")[0];
		var oHtml = document.getElementsByTagName("HTML")[0];
		if (oBody && oHtml) {
			switch(Tuksi.BrowserData()){
				case "Firefox":
				case "MSIE_60":
				return oHtml.scrollTop;
				break;

				default:
				return oBody.scrollTop;
			}
		}
	},

	// Opens a popup - <a href="http://dwarf.dk/ onclick="return setPopup(this, 300, 300)">
	Popup: function(oThis, sHeight, sWidth, bResize, bScroll, bMenu, bLocation, bToolbar){
		var sUrl;
		if(typeof(oThis) == "string"){sUrl = oThis}else{sUrl=oThis.href}
		if(bResize){bResize="resizable"}else{bResize="resizable=0"}
		if(bScroll){bScroll="scrollbars"}else{bScroll="scrollbars=0"}
		if(bMenu){bMenu="menubar"}else{bMenu="menubar=0"}
		if(bLocation){bLocation="location"}else{bLocation="location=0"}
		if(bToolbar){bToolbar="toolbar"}else{bToolbar="toolbar=0"}
		var dwarfPopup = window.open(sUrl, "dwarfPopup", "width=" + sWidth + ", height=" + sHeight + ", " + bResize + ", " + bScroll + ", " + bMenu + ", " + bLocation + ", " + bToolbar + "");

		return false;
	},

	// Returns x coordinate of mousepointer
	MouseX: function(e){
		var x = e.clientX;
		if (!x){x = 0}
		return x;
	},

	// Returns y coordinate of mousepointer
	MouseY: function(e){
		var y = e.clientY;
		if (!y){y = 0}
		return y;
	},

	// Returns major flash version
	FlashVersion: function(){
		var iMaxFlashVersion = 20;
		var iFlashVersion = 0;
		if (navigator.plugins && navigator.plugins.length) {
			for (var i = 0; i < navigator.plugins.length; i++) {
				if (navigator.plugins[i].name.indexOf('Shockwave Flash') != -1) {
					iFlashVersion = parseInt(navigator.plugins[i].description.split('Shockwave Flash ')[1], 10);
					break;
				}
			}
		} else if (window.ActiveXObject) {
			for (var i = 2; i <= iMaxFlashVersion; i++) {
				try {
					oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");
					if( oFlash ) {
						iFlashVersion = i;
					}
				}
				catch(e) {}
			}
		}
		return iFlashVersion
	},

	

	// Show or hides an element with sElementId as id
	DisplayElement: function(sElementid){
		var oElement = document.getElementById(sElementid);
		if (oElement){
			if(oElement.style.display == "block" || oElement.style.display == ""){
				oElement.style.display = "none";
			} else {
				oElement.style.display = "block";
			}
		}
	},

	// Returns browser name
	BrowserData: function(){
		var sBrowserData = navigator.userAgent + " " + navigator.appVersion
		if (sBrowserData.indexOf("MSIE") != -1 && sBrowserData.indexOf("Macintosh") != -1) { return "MSIE_MAC" }
		else if (sBrowserData.indexOf("MSIE 5.0") != -1 && sBrowserData.indexOf("Windows") != -1) {	return "MSIE_50" }
		else if (sBrowserData.indexOf("MSIE 5.5") != -1 && sBrowserData.indexOf("Windows") != -1) { return "MSIE_55" }
		else if (sBrowserData.indexOf("MSIE 6.0") != -1 && sBrowserData.indexOf("Windows") != -1) { return "MSIE_60" }
		else if (sBrowserData.indexOf("Firefox") != -1) { return "Firefox" }
		else if (sBrowserData.indexOf("Safari") != -1) { return "Safari" }
		else { return "Unknown Browser"	}
	},

	// Have alle images been loaded
	ImagesLoaded: false,
	
	// Object holding images
	ImageObjects: [],
	
	// Preload all images in sImageUrls - url absolute to root e.g. '/images/menu/bn_buttonActive_1.gif'
	PreloadImages: function(sImageUrls){
		if(sImageUrls){
			var aImageUrls = sImageUrls.split(",")
			for (var i=0; i<aImageUrls.length; i++){
				var oTemp = new Image();
				oTemp.src = aImageUrls[i].replace(" ", "");
				Tuksi.ImageObjects[Tuksi.ImageObjects.length] = oTemp;
			}
			Tuksi.ImagesLoaded = true;
		}
	},

	// Swaps source of oThis to a preloaded image in aImageObjects[] - either by directly referring or by image name
	SwapImage: function(oThis, iSwapToImage){
		if(oThis && Tuksi.ImagesLoaded){
			if(typeof(iSwapToImage) == "number"){
				oThis.src = Tuksi.ImageObjects[iSwapToImage].src;
			} else {
				for(var i = 0; i<Tuksi.ImageObjects.length; i++){
					if(Tuksi.ImageObjects[i].src.indexOf(iSwapToImage) != -1 ){
						oThis.src = Tuksi.ImageObjects[i].src;
					}
				}
			}
		}
	},

	// Replace all inline PNGs with filter property and set clear gif as src (only works in ie6)
	ReplacePng: function(){
		if(Tuksi.BrowserData().indexOf("MSIE") != -1 && Tuksi.BrowserData() != "MSIE_MAC"){
			var aImgs = document.getElementsByTagName("IMG");
			var sImgSrc;
			for(var i = 0; i<aImgs.length; i++){
				sImgSrc = aImgs[i].src.toLowerCase()
				if(sImgSrc.lastIndexOf(".png") != -1){
					aImgs[i].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + aImgs[i].src + ', sizingMethod="image")';
					aImgs[i].src = "/images/graphics/gx_blank.gif";
				}
			}
		}
	},

	// Display inline error popup - NOT UPDATED TO TUKSI CLASS
	Alert: function(aAlerts){
		var oBody = document.getElementsByTagName("body")[0];
		var oAlert = document.getElementById("alert");

		if(oBody){
			// remove existing alerts
			if(oAlert){
				oBody.removeChild(oAlert);
			}

			// is alerts array or string?
			// generate html for displaying the errors
			var sAlert = "";
			if(typeof(aAlerts) == "object"){
				for(var i = 0; i<aAlerts.length; i++){
					sAlert += "<li>" + aAlerts[i] + "</li>";
				}
			} else {
				sAlert += "<li>" + aAlerts + "</li>";
			}

			// create elements for alert
			var oAlert = document.createElement("DIV");
			oAlert.id = "alert";

			var oAlertContentList = document.createElement("UL");
			oAlertContentList.innerHTML = sAlert;

			var oAlertContentClose = document.createElement("A");
			oAlertContentClose.innerHTML = "luk";
			oAlertContentClose.onclick = function(){
				document.getElementById("alert").style.display = "none";
				return false;
			}

			var oAlertContent = document.createElement("DIV");
			oAlertContent.className = "alertcontent";
			oAlertContent.appendChild(oAlertContentList);
			oAlertContent.appendChild(oAlertContentClose);

			var oAlertShadow = document.createElement("DIV");
			oAlertShadow.className = "alertshadow";

			// append elements for alert
			oAlert.appendChild(oAlertContent);
			oAlert.appendChild(oAlertShadow);

			// append alert to body
			oBody.appendChild(oAlert);

			// placement of error
			oAlert.style.visibility = "hidden";
			oAlert.style.display = "block";
			oAlert.style.top = getScrollWindowHeight() + 150 + "px";
			oAlert.style.left = (getWindowWidth() / 2) - (getElementWidth(oAlert.getElementsByTagName("DIV")[0]) / 2) + "px";

			// update the height of the shadow
			oAlertShadow.style.height = getElementHeight(oAlertContent) + "px";

			// make alert visible
			oAlert.style.visibility = "visible";
		}
	}
}

//Suckerfish contentTopMenu (textpage.tpl)
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
if (navRoot != null) {
for (i=0; i<navRoot.childNodes.length; i++) {	
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  } }
 }
}
window.onload=startList;
//END Suckerfish
