﻿var ie5, ie7;
var ns6;
var blnFirstRun = false;
var blnIsPositioning = false;
var strLastTab = "tab8";

function startup() {
	ie5=document.all&&document.getElementById&&!window.XMLHttpRequest;
	ns6=document.getElementById&&!document.all;
	ie7=document.all&&document.getElementById&&window.XMLHttpRequest;
}

function delayPositionThings() {
	if(blnIsPositioning) { 
		return; 
	} else {
		blnIsPositioning = true;
	}
	setTimeout("positionThings()", 750);
}

function positionThings() {
	var pageSize = getPageSize();
	var pageHeight = (ie5 ? pageSize[1] : pageSize[3]);
	var objRel = (intCompanyId==8 ? g("imgTopTabRight") : g("imgTopRedCorner"));

	// *** center the main div to screen
	g("divMain").style.left = p((pageSize[0] - g("divMain").offsetWidth) / 2) + "px";
	if(p(g("divMain").style.left) < 0)
		g("divMain").style.left = "0px";
		
	if(p((pageHeight - g("divMain").offsetHeight) / 2) < 0 ) {
		g("divMain").style.top = "0px";
	} else {
		g("divMain").style.top = p((pageHeight - g("divMain").offsetHeight) / 2) + "px";
	}
	//g("divMain").style.top = "200px";
	
	// *** place IAT Group (with the "Group" text) at the top left of layout
	g("imgLogo").style.left = rxpos("divMain") + p(crf*20) + "px";
	g("imgLogo").style.top = rypos("divMain") + p(crf*9) + "px";
	
	positionTabs()
	
	var intTotalTabWidth = (rxpos(strLastTab) + g(strLastTab).offsetWidth) - rxpos("tab1") + g("imgTopTabRight").offsetWidth;
	
	// *** position the image behind the tabs
	if(intCompanyId > 0) {
		g("divTabBgImage").style.left = rxpos("tab1") + (jsres == 2 ? 2 : 0) + 1 + "px";
		g("divTabBgImage").style.top = rypos("tab1") + p(jsres) + "px";
		g("divTabBgImage").style.height = g("tab1").offsetHeight - 2 + "px"; 		//g("divTabBgImage").style.width = intTotalTabWidth + "px";
		colorizeTab(intCompanyId);
	}
	
	// *** place the red corner (top right) below the tabs
	g("imgTopRedCorner").style.left = rxpos("imgTopTabRight") + g("imgTopTabRight").offsetWidth - g("imgTopRedCorner").offsetWidth + "px";
	g("imgTopRedCorner").style.top = rypos(strLastTab) + g(strLastTab).offsetHeight - 1 + "px";
	
	// *** place the red corder (bottom right) at a given distance from top
	g("imgBottomRedCorner").style.left = rxposObj(objRel) + objRel.offsetWidth - g("imgBottomRedCorner").offsetWidth + "px";
	g("imgBottomRedCorner").style.top = rypos("imgTopTabRight") + g("imgTopTabRight").offsetHeight + p(crf*459) + "px";
	
	// *** if companyId is zero, meaning we're at the front page, then position red lines and hide then tab background image
	if(intCompanyId==0) {
		g("imgRedLineTop2").style.display = "none";
		g("imgRedLineTop1").style.left = rxpos("tab1") + "px";
		g("imgRedLineTop1").style.top = g("imgTopRedCorner").style.top;
		g("imgRedLineTop1").style.height = g("imgRedLineTop1").offsetHeight + "px";
		g("imgRedLineTop1").style.width = rxpos("imgTopRedCorner") - rxpos("tab1") + "px";
		g("divTabBgImage").style.display = "none";
		// *** if companyId is eight (the last one) then alter the last tab image and position red lines
	} else if (intCompanyId==8) {
		g("imgRedLineTop2").style.display = "none";
		g("imgRedLineTop1").style.left = rxpos("tab1") + "px";
		g("imgRedLineTop1").style.top = g("imgTopRedCorner").style.top;
		g("imgRedLineTop1").style.height = g("imgRedLineTop1").offsetHeight + "px";
		g("imgRedLineTop1").style.width = rxpos("tab8") - rxpos("tab1") + "px";
		g("imgTopRedCorner").style.display = "none";
		g("imgRedTopTab").src = "img/top_tab_red_right_" + jsres + ".png";
		// *** if companyId is > 0 and < 8 then wrap the top red lines around the selected tab
	} else {
		g("imgRedLineTop1").style.left = rxpos("tab1") + "px";
		g("imgRedLineTop1").style.top = p(g("imgTopRedCorner").style.top) + (jsres==0 ? 1 : 0) + "px";
		g("imgRedLineTop1").style.height = g("imgRedLineTop1").offsetHeight + "px";
		g("imgRedLineTop1").style.width = rxpos("tab" + intCompanyId) - rxpos("tab1") + "px";
		
		g("imgRedLineTop2").style.left = rxpos("tab" + intCompanyId) + g("tab" + intCompanyId).offsetWidth - 2 + "px";
		g("imgRedLineTop2").style.top = g("imgTopRedCorner").style.top;
		g("imgRedLineTop2").style.height = g("imgRedLineTop2").offsetHeight + "px";
		g("imgRedLineTop2").style.width = rxpos("tab8") + g("tab8").offsetWidth - rxpos("tab" + intCompanyId) - g("tab" + intCompanyId).offsetWidth + g("imgTopTabRight").offsetWidth - g("imgTopRedCorner").offsetWidth + "px";
	}
	// *** if companyId is different from zero position the red "selected tab" on top of the selected tab
	if(intCompanyId!=0) {
		g("imgRedTopTab").style.left = rxpos("tab" + intCompanyId) + "px";
		g("imgRedTopTab").style.top = rypos("tab" + intCompanyId) + "px";
	}
	// *** place the red lines around the main contents area
		g("imgRedLineRight").style.left = rxposObj(objRel) + objRel.offsetWidth - g("imgRedLineRight").offsetWidth + "px";
		g("imgRedLineRight").style.top = ryposObj(objRel) + objRel.offsetHeight - (jsres==2?1:0)+ "px";
		g("imgRedLineRight").style.width = g("imgRedLineRight").offsetWidth + "px";
		g("imgRedLineRight").style.height = rypos("imgBottomRedCorner") - ryposObj(objRel) - objRel.offsetHeight + (jsres==2?1:0) + "px";

		g("imgRedLineLeft").style.left = rxpos("tab1") - (jsres==1 ? 0 : 1) + (jsres==2 ? 1 : 0) + "px";
		g("imgRedLineLeft").style.top = rypos("tab1") + g("tab1").offsetHeight + "px";
		g("imgRedLineLeft").style.width = g("imgRedLineLeft").offsetWidth + "px";
		g("imgRedLineLeft").style.height = rypos("imgBottomRedCorner") - rypos("tab1") - g("tab1").offsetHeight + g("imgBottomRedCorner").offsetHeight - 1 - jsres + (jsres==2?1:0) +  "px";

		g("imgRedLineBottom").style.height = g("imgRedLineBottom").offsetHeight + "px";
		g("imgRedLineBottom").style.left = rxpos("imgRedLineLeft") + (jsres==0 ? 1 : 0) + "px";
		g("imgRedLineBottom").style.top = rypos("imgRedLineLeft") + g("imgRedLineLeft").offsetHeight + "px";
		g("imgRedLineBottom").style.width = rxpos("imgBottomRedCorner") - rxpos("imgRedLineBottom") + "px";
		
		// *** position and resize the white background
		g("divWhiteBackground").style.left = rxpos("imgRedLineLeft") + 1 + "px";
		g("divWhiteBackground").style.top = rypos("imgRedLineLeft") + 2 + "px";
		g("divWhiteBackground").style.width = rxpos("imgRedLineRight") - rxpos("imgRedLineLeft") + "px";
		g("divWhiteBackground").style.height = rypos("imgRedLineBottom") - rypos("imgRedLineTop1") - 3 + "px";
		// / white background
		
		// *** if companyId > zero then place the middle red divider line with a corner on bottom
		if(intCompanyId!=0) {
			g("imgRedDivider").style.width = g("imgRedDivider").offsetWidth + "px";
			g("imgRedDivider").style.top = rypos("divTabBgImage") + p(crf*100) + "px";
			g("imgCornerDivider").style.left = rxpos("imgRedLineLeft") + p(crf*600) + "px";
			g("imgRedDivider").style.left = rxpos("imgCornerDivider") + g("imgCornerDivider").offsetWidth - g("imgRedDivider").offsetWidth - (jsres==2 ? 1 : 0) + "px";
			// *** If resolution is 1600 move then divider corner slightly to the left
			if(jsres==2) {
				g("imgCornerDivider").style.left = p(g("imgCornerDivider").style.left) - 1 + "px";
			}
			g("imgCornerDivider").style.top = g("imgBottomRedCorner").style.top;
			g("imgRedDivider").style.height = rypos("imgCornerDivider") - p(g("imgRedDivider").style.top) + "px";
			// / divider
			
			// *** position and resize the main contents image
			g("divContentsImage").style.left = rxpos("divWhiteBackground") + 1 + "px";
			g("divContentsImage").style.top = rypos("imgRedDivider") + "px";
			g("divContentsImage").style.width = rxpos("imgRedDivider") - rxpos("divWhiteBackground") - 1 + (jsres==2 ? 1 : 0) + "px";
			g("divContentsImage").style.height = rypos("imgRedLineBottom") - rypos("imgRedDivider") - p(crf*25) + "px";
		
			if(g("divBookingImage") ) {
				g("divBookingImage").style.left = rxpos("imgRedLineLeft") + g("imgRedLineLeft").offsetWidth - p(crf*100) + "px";
				g("divBookingImage").style.top = rypos("imgRedLineTop1") + p(crf*380) + "px";
				
			}		
		
		} else {
			// *** if companyId is in fact zero, then resize then main contents image to fill the entire area (except from top and bottom margins).
			g("divContentsImage").style.left = rxpos("imgRedLineLeft") + g("imgRedLineLeft").offsetWidth + "px";
			g("divContentsImage").style.top = rypos("imgRedLineTop1") + p(crf*26) + "px";
			g("divContentsImage").style.width = rxpos("imgRedLineRight") - rxpos("imgRedLineLeft") - g("imgRedLineLeft").offsetWidth + "px";
			g("divContentsImage").style.height = rypos("imgRedLineBottom") - rypos("divContentsImage") - p(crf*24) + "px";
		}
		
		// contents & shit
		// *** if large contents area has been chosen resize the main background and documentContainers
		if(blnIsLargeTextArea) {
			g("divMasterBg").style.left = rxpos("divWhiteBackground") + 1 + "px";
			g("divMasterBg").style.top = rypos("imgRedDivider") + "px";
			g("divMasterBg").style.width = g("divContentsImage").offsetWidth + 0 + "px";
			g("divMasterBg").style.height = rypos("imgRedLineBottom") - rypos("divMasterBg") - p(crf*25) + "px";
		} else {
			g("divMasterBg").style.left = rxpos("divWhiteBackground") + 1 + "px";
			g("divMasterBg").style.top = rypos("imgRedDivider") + p(crf*241) + "px";
			g("divMasterBg").style.width = g("divContentsImage").offsetWidth + 0 + "px";
			g("divMasterBg").style.height = rypos("imgRedLineBottom") - rypos("divMasterBg") - p(crf*25) + "px";
		}
		g("divMasterContainer1").style.left = rxpos("divMasterBg") + "px";
		g("divMasterContainer1").style.top = rypos("divMasterBg") + "px";
		g("divMasterContainer1").style.height = g("divMasterBg").offsetHeight - p(crf*6) + "px";
		g("divMasterContainer1").style.width = g("divMasterBg").offsetWidth + "px";
		g("divDocumentContainer1").style.width = g("divMasterBg").offsetWidth - p(crf*30) + "px";
		// / contents & shit
		
		// icons & arrows
		if(intCompanyId!=0) {
			// *** if companyid > zero position the icons on the bottom and the background image browse arrows on the top right
			// *** also place the logo of the firma currently being viewed
			g("divIcon").style.left = rxpos("imgRedDivider") - g("divIcon").offsetWidth - p(crf*3) + "px";
			g("divIcon").style.top = rypos("divWhiteBackground") + g("divWhiteBackground").offsetHeight - g("divIcon").offsetHeight - p(crf*3) + "px";
			
			g("imgGalleryRight").style.left = rxpos("divContentsImage") + g("divContentsImage").offsetWidth - g("imgGalleryRight").offsetWidth - p(crf*10) + "px";
			g("imgGalleryRight").style.top = rypos("divContentsImage") + p(crf*10) + "px";
			g("imgGalleryLeft").style.left = rxpos("imgGalleryRight") - g("imgGalleryLeft").offsetWidth - p(crf*10) + "px";
			g("imgGalleryLeft").style.top = g("imgGalleryRight").style.top;
			
			// logo
				g("imgLogoCompany").style.left = rxpos("tab8") + g("tab8").offsetWidth - g("imgLogoCompany").offsetWidth - p(crf*10) + "px";
				var intLogoCompanyTop = (rypos("divTabBgImage") + g("divTabBgImage").offsetHeight) - p(crf*61/2) - p(g("imgLogoCompany").offsetHeight / 2);
				intLogoCompanyTop = rypos("imgRedDivider") - p(crf*40) - p(g("imgLogoCompany").offsetHeight / 2);
				g("imgLogoCompany").style.top = intLogoCompanyTop + "px";
			// / logo
		} else {
			// *** if company is zero then hide the icons and position the browse arrows according to the background image (which is now large)
			g("divIcon").style.display = "none";
			g("imgGalleryRight").style.left = rxpos("divWhiteBackground") + g("divWhiteBackground").offsetWidth - g("imgGalleryRight").offsetWidth - p(crf*10) + "px";
			g("imgGalleryRight").style.top = rypos("divWhiteBackground") + p(crf*24) + "px";
			g("imgGalleryLeft").style.left = rxpos("imgGalleryRight") - g("imgGalleryLeft").offsetWidth - p(crf*10) + "px";
			g("imgGalleryLeft").style.top = g("imgGalleryRight").style.top;
		}
		// / icons & arrows
		
		// *** position the left hand menu and the language selection flags
		g("divGroupMenu").style.left = rxpos("imgRedLineLeft") - g("divGroupMenu").offsetWidth + "px";
		g("divGroupMenu").style.top = rypos("imgRedLineTop1") + p(crf*72) + "px";
	
		g("divFlags").style.left = rxpos("divGroupMenu") + g("divGroupMenu").offsetWidth - g("divFlags").offsetWidth - p(crf*15) + "px";
		g("divFlags").style.top = rypos("divWhiteBackground") + g("divWhiteBackground").offsetHeight - g("divFlags").offsetHeight + "px";
		// / menu, language flags
		
		// *** prep the background images for browsing
		if(!blnFirstRun) {
			if(typeof(arrPageImages) == "undefined") {
				g("imgGalleryLeft").style.display = "none";
				g("imgGalleryRight").style.display = "none";
			} else {
				 if(arrPageImages.length < 2) {
						g("imgGalleryLeft").style.display = "none";
						g("imgGalleryRight").style.display = "none";
						if(arrPageImages.length==1) {
							nextImage();
						}
				} else {
					nextImage();
				}
			}
		}
	// *** position the menu at the bottom left belonging to the group thingy
		if(g("divBottomLeftMenu")) {
			g("divBottomLeftMenu").style.left = rxpos("divGroupMenu") + g("divGroupMenu").offsetWidth - g("divBottomLeftMenu").offsetWidth + "px";
			g("divBottomLeftMenu").style.top = rypos("divFlags") - g("divBottomLeftMenu").offsetHeight - p(crf*20) + "px";
		}
	// / bottom left menu
	
	// *** position the scroll arrows to the bottom right of document containers
	g("divScrollArrows").style.left = rxpos("divMasterContainer1") + g("divMasterContainer1").offsetWidth - g("divScrollArrows").offsetWidth - p(crf*4) + "px";
	g("divScrollArrows").style.top = rypos("divMasterContainer1") + g("divMasterContainer1").offsetHeight - g("divScrollArrows").offsetHeight - p(crf*10) + "px";

	// *** 	if companyid is zero then hide the scroll arrows and the document containers background
	if(intCompanyId==0) {
		g("divScrollArrows").style.display = "none";
		g("divMasterBg").style.display = "none";
	}	
	
	if(blnIsLargeTextArea) {
		g("imgContentsDown").style.left = rxpos("divMasterContainer1") + p(g("divMasterContainer1").offsetWidth / 2) - p(g("imgContentsDown").offsetWidth / 2) + "px";
		g("imgContentsUp").style.left = g("imgContentsDown").style.left;
		g("imgContentsDown").style.top = rypos("divMasterContainer1") + p(crf*10) + "px";
		g("imgContentsUp").style.top = rypos("divMasterContainer1") + g("divMasterContainer1").offsetHeight - g("imgContentsUp").offsetHeight - p(crf*10) + "px";

		if(!blnFirstRun) {
			g("imgContentsDown").style.display = "block";
			g("imgContentsUp").style.display = "none";
		}
		
		if(typeof(arrPageImages)=="undefined") {
			g("imgContentsDown").style.display = "none";
		} else {
			if(arrPageImages.length==0) {
				g("imgContentsDown").style.display = "none";
			}
		}
	}
		// *** Following the non-group specific things!!!!!!!
		if(intCompanyId > 0 ) {
			g("divSiteMenu").style.left = rxpos("imgRedLineRight") - g("divSiteMenu").offsetWidth + "px";
			g("divSiteMenu").style.top = rypos("imgRedDivider") + "px";
			g("divCompanyAddress").style.left = rxpos("imgRedLineRight") - g("divCompanyAddress").offsetWidth - p(crf*18) + "px";
			g("divCompanyAddress").style.top = rypos("divContentsImage") + g("divContentsImage").offsetHeight - g("divCompanyAddress").offsetHeight + "px";
			if(g("smiley") ) {
			g("smiley").style.left = rxpos("imgRedLineRight") - g("smiley").offsetWidth - p(crf*18) + "px";
			g("smiley").style.top = rypos("divContentsImage") + g("divContentsImage").offsetHeight - g("divCompanyAddress").offsetHeight - p(crf*45) + "px";
			}	

		}

		//**************** 29-09-2009 11:40
		if(g("divCompanyAddressbottom") ) {
			// venstrestillet:
			//g("divCompanyAddressbottom").style.left = rxpos("divMain") + p(crf*0) + "px"; 
			// højrestillet:
			g("divCompanyAddressbottom").style.left = rxpos("divMain")+ g("divMain").offsetWidth - g("divCompanyAddressbottom").offsetWidth + p(crf*0) + "px";
			g("divCompanyAddressbottom").style.top = rypos("divMain") + p(crf*562) + "px";
		}
		//****************	

	// *** if this is the first run-through and the browser is Internet Exploder 6 (I know, I know the variable is called ie5)
	// *** then add classNames to png images
	if(!blnFirstRun&&ie5) {
		addPngFix();
	}
	
	// *** set first run-through var and position the front page info boxes
	blnFirstRun = true;
	blnIsPositioning = false;
}

function positionTabs() {
	var startX = rxpos("divMain") + p(crf*43);
	var startY = rypos("divMain") + p(crf*36);

	for(var i = 0; i < 9; i++) {
		if(g("tab" + i)) {
			g("tab" + i).style.left = startX + (i * p(crf*102)) + "px";
			g("tab" + i).style.top = startY + "px";
			g("divTab" + i).style.left = g("tab" + i).style.left;
			g("divTab" + i).style.top = rypos("tab" + i) + p((g("tab" + i).offsetHeight - g("divTab" + i).offsetHeight) / 2) + "px";
		}
	}
	g("imgTopTabRight").style.left = rxpos(strLastTab) + g(strLastTab).offsetWidth - 2 + "px";
	g("imgTopTabRight").style.top = g(strLastTab).style.top;
}

function colorizeTab(cid) {
	if(!g("divTab" + cid)) { return; }
	var obj = g("divTab" + cid);
	g("tab" + cid).src = "img/top_tab_trans_" + jsres + ".png";
	obj.style.color = "#EC2428";
	obj.style.color = "#f00";
	obj.childNodes[0].style.color = "#f00";
			
	if(ns6) {
		obj.childNodes[0].childNodes[2].style.color = "#f00";
	} else {
		obj.childNodes[0].childNodes[2].style.color = "#f00";	
	}

//	for(var i = 0; i < obj.childNodes.length; i++) {
//		obj.childNodes[i].style.color = "#EC2428";
//		if(obj.childNodes[i].tagName) {
//			if(obj.childNodes[i].tagName.toString().toLowerCase() == "div") {
//				obj.childNodes[i].style.color = "#EC2428";
//			}
//		}
//	}
	if(cid==8) {
		g("imgTopTabRight").src = "img/top_tab_right_trans_" + jsres + ".png";
	}
}

function addPngFix() {
	var arr = document.getElementsByTagName("img");
	for(var i = 0; i < arr.length; i++) {
		if(arr[i].src) {
			if(arr[i].src.toLowerCase().indexOf("png") > 0) {
				if(arr[i].className == "") {
					arr[i].className = "overlay";
				} else {
					if(arr[i].className != "overlay" || arr[i].className != "overlaystay") {
						arr[i].className += " overlay";
					}
				}
			}
		}
	}
}

function toggleContents() {
	if(g("divMasterContainer1").style.display=="block") {
		g("divMasterContainer1").style.display = "none";
		g("divDocumentContainer1").style.display = "none";
		g("divMasterBg").style.display = "none";
		g("imgContentsDown").style.display = "none";
		g("imgContentsUp").style.display = "block";
		g("divScrollArrows").style.display = "none";
	} else {
		g("divMasterContainer1").style.display = "block";
		g("divDocumentContainer1").style.display = "block";
		g("divMasterBg").style.display = "block";
		g("imgContentsDown").style.display = "block";
		g("imgContentsUp").style.display = "none";
		g("divScrollArrows").style.display = "block";
	}
}

var intCurrImg = -1;
function nextImage() {
	if(typeof(arrPageImages)!="undefined") {
		if(arrPageImages.length==0) return;
		intCurrImg += 1;
		if(intCurrImg>=arrPageImages.length) {
			intCurrImg = 0;
		}
		g('imgContentsBackground').src = arrPageImages[intCurrImg];
	}
}

function prevImage() {
	if(typeof(arrPageImages)!="undefined") {
		if(arrPageImages.length==0) return;
		intCurrImg -= 1;
		if(intCurrImg<0) {
			intCurrImg = arrPageImages.length - 1;
		}
		g('imgContentsBackground').src = arrPageImages[intCurrImg];
	}
}

function printThis() { 
	document.forms.printform.printwhat.value = document.getElementById("divDocumentContainer1").innerHTML;
	document.forms.printform.submit();
}

function printerfocus()
{
	printframe.focus();
	printframe.print();
}

