// Tuksi Frontend - JavaScript
// Version 2005-06-27-AMA

// Rollover on projekts

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// activate using <body onload="init()">
function init(){
	centerLayoutVertical();
}


function centerLayoutVertical(){
	var oLayout = document.getElementById("layoutholder");
	var oBody = document.getElementsByTagName("BODY")[0];
	var iWindowHeight = getWindowHeight();
	if (oLayout){
		oLayout.style.visibility = "hidden";
		if ((iWindowHeight / 2) - (getElementHeight("layout") / 2) > 0){
			oLayout.style.paddingTop = (iWindowHeight / 2) - (getElementHeight("layout") / 2) + "px";
		}
		oLayout.style.visibility = "visible";
	}	
}


/*
Tuksi Frontend basic JavaScript functions

getElementHeight(sElementId)
getElementWidth(sElementId)
setElementHeight(sElementId, iHeight)
setElementWidth(sElementId, iWidth)
getWindowWidth()
getWindowHeight()
getScrollWindowHeight()
setPopup(oThis, sHeight, sWidth)
getMouseX(oEvent)
getMouseY(oEvent)
getFlashStatus()
getFlashVersion()
getBrowserData()
setDisplayElement(sElementId)
*/


// Returns the height of an element with sElementId as id
function getElementHeight(sElementId){
	var oElementId = document.getElementById(sElementId)
	if (oElementId){
		return oElementId.offsetHeight;
	}
}

// Returns the width of an element with sElementId as id
function getElementWidth(sElementId){
	var oElementId = document.getElementById(sElementId)
	if (oElementId){
		return oElementId.offsetWidth;
	}
}

// Sets a specific height (iHeight) on an element with sElementId as id
function setElementHeight(sElementId, iHeight){
	var oElementId = document.getElementById(sElementId)
	if (oElementId){
		oElementId.style.height = iHeight + "px";
	}
}

// Sets a specific width (iHeight) on an element with sElementId as id
function setElementWidth(sElementId, iWidth){
	var oElementId = document.getElementById(sElementId)
	if (oElementId){
		oElementId.style.width = iWidth + "px";
	}
}

// Returns width of browser window
function getWindowWidth(){
	var oHtml = document.getElementsByTagName("HTML")[0];
	if (oHtml) {
		return oHtml.offsetWidth
	}
}

// Returns height of browser window
function getWindowHeight(){
	var oHtml = document.getElementsByTagName("HTML")[0];
	if (oHtml) {
		switch(getBrowserData()){
			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
function getScrollWindowHeight(){
	var oBody = document.getElementsByTagName("BODY")[0];
	var oHtml = document.getElementsByTagName("HTML")[0];
	if (oBody && oHtml) {
		switch(getBrowserData()){
			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)">
function setPopup(oThis, sHeight, sWidth){
	var popupWin = window.open(oThis.href, "popWin", "width=" + sWidth + ", height=" + sHeight + ", status=0, resizable=0");
	return false;
}

// Returns x coordinate of mousepointer
function getMouseX(oEvent){
	var x = oEvent.clientX;
	if (!x){x = 0}
	return x;
}

// Returns y coordinate of mousepointer
function getMouseY(oEvent){
	var y = oEvent.clientY;
	if (!y){y = 0}
	return y;
}

// Returns true if flash is installed
function getFlashStatus(){
	var iMaxFlashVersion = 20;
	var bFlashInstalled = false;
	if (navigator.plugins && navigator.plugins.length) {
		for (x=0; x < navigator.plugins.length; x++) {
			if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
				bFlashInstalled = true;
				break;
			}
		}
	} else if (window.ActiveXObject) {
		for (x=2; x <= iMaxFlashVersion; x++) {
			try {
				oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
				if( oFlash ) {
					bFlashInstalled = true;
				}
			}
			catch(e) {}
		}
	}
	return bFlashInstalled
}

// Returns major flash version
function getFlashVersion(){
	var iMaxFlashVersion = 20;
	var iFlashVersion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		for (x=0; x < navigator.plugins.length; x++) {
			if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
				iFlashVersion = navigator.plugins[x].description.split('Shockwave Flash ')[1].charAt(0);
				break;
			}
		}
	} else if (window.ActiveXObject) {
		for (x=2; x <= iMaxFlashVersion; x++) {
			try {
				oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
				if( oFlash ) {
					iFlashVersion = x;
				}
			}
			catch(e) {}
		}
	}
	return iFlashVersion
}

// Show or hides an element with sElementId as id
function setDisplayElement(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
function getBrowserData(){
	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"	}
}
