﻿var ie5;
var ns6;
var blnFirstRun = false;

function g(v) {
	return document.getElementById(v);
}
function p(v) {
	return parseInt(v);
}

function rxpos(v) {
	var obj = g(v);
	var cx = 0;
	if (obj.offsetParent) {
		cx = obj.offsetLeft
		while (obj = obj.offsetParent) {
			cx += obj.offsetLeft
		}
	}
	return cx;
}

function rypos(v) {
	var obj = g(v);
	var cy = 0;
	if (obj.offsetParent) {
		cy = obj.offsetTop
		while (obj = obj.offsetParent) {
			cy += obj.offsetTop
		}
	}
	return cy;
}

function rxposObj(v) {
	var obj = v;
	var cx = 0;
	if (obj.offsetParent) {
		cx = obj.offsetLeft
		while (obj = obj.offsetParent) {
			cx += obj.offsetLeft
		}
	}
	return cx;
}

function ryposObj(v) {
	var obj = v;
	var cy = 0;
	if (obj.offsetParent) {
		cy = obj.offsetTop
		while (obj = obj.offsetParent) {
			cy += obj.offsetTop
		}
	}
	return cy;
}

function startup() {
	ie5=document.all&&document.getElementById;
	ns6=document.getElementById&&!document.all;
}

function delayPositionThings() {
		setTimeout("positionThings()", 750);
}

function positionThings() {
	var pageSize = getPageSize();
	var pageHeight = (ie5 ? pageSize[1] : pageSize[3]);
	g('mainDiv').style.top = ((pageHeight - g('mainDiv').offsetHeight) / 2) + "px";
	if(p(g('mainDiv').style.top) < 0) {
		g('mainDiv').style.top = "0px";
	}
	
	g('mainDiv').style.left = ((pageSize[0] - g('mainDiv').offsetWidth) / 2) + "px";
	if(p(g('mainDiv').style.left) < 0) {
		g('mainDiv').style.left = "0px";
	}
	
	g('imgSun').style.left = rxpos('tblMain') + g('tblMain').offsetWidth - g('imgSun').offsetWidth - p(crf*20) + "px";
	g('imgSun').style.top = rypos('tblMain') + g('tblMain').offsetHeight - g('imgSun').offsetHeight - p(crf*55) + "px";
	
	g('imgTopWave').style.left = rxpos('tdTopWaveAligner') + "px";
	g('imgTopWave').style.top = rypos('tdTopWaveAligner') + "px";
	
	g('langDiv').style.left = rxpos('tblMain') + g('tblMain').offsetWidth - g('langDiv').offsetWidth - p(crf*10) + "px";
	g('langDiv').style.top = rypos('imgTopWave') + g('imgTopWave').offsetHeight - p(crf*35) + "px";
	
	g('subMenuDiv').style.left = rxpos('tblMain') + g('tblMain').offsetWidth - g('subMenuDiv').offsetWidth + "px";
	g('subMenuDiv').style.top = rypos('imgTopWave') + g('imgTopWave').offsetHeight - p(crf*10) + "px";
	
	g('subMenuContents').style.left = rxpos('subMenuDiv') + p(crf*10) + "px";
	g('subMenuContents').style.top = rypos('subMenuDiv') + p(crf*20) + "px";
	
	g('menuDiv').style.left = rxpos('tblMain') + p(crf*20) + "px";
	g('menuDiv').style.top = rypos('imgTopWave') + p(crf*35) + "px";
		
	g('btnInfo').style.left = rxpos('mainTD') + g('mainTD').offsetWidth - g('subMenuDiv').offsetWidth  - p(crf*70) + "px";
	g('btnInfo').style.top = rypos('mainTD') + p(crf*00) + "px";
	
	if(jsres!=0) {
		g('subMenuDiv').style.left = p(g('subMenuDiv').style.left) + 1 + "px";	
		g('subMenuDiv').style.width = p(g('subMenuDiv').style.width) - 0 + "px";
	}
	if(jsres==0) {
		g('imgSun').style.top = p(g('imgSun').style.top) - 1 + "px";
	}
	if(jsres==2) {
		g('imgSun').style.top = p(g('imgSun').style.top) + 3 + "px";
	}
		
	g('bgImage').style.left = rxpos('imgTopWave') + "px";
	g('bgImage').style.top = rypos('imgTopWave') + g('imgTopWave').offsetHeight - p(crf*30) + "px";
	
	g('imgArrowLeft').style.left = rxpos('bgImage') + "px";
	g('imgArrowLeft').style.top = rypos('tblMain') + p(crf*430) + "px";
	
	g('imgArrowRight').style.left = rxpos('imgArrowLeft') + p(crf*738) - g('imgArrowLeft').offsetWidth + "px";
	g('imgArrowRight').style.top = g('imgArrowLeft').style.top;
	
	g('klikogse').style.left = rxpos('imgArrowRight') + p(crf*35) + "px";
	g('klikogse').style.top = rypos('imgArrowRight') + p(crf*15) + "px";
	
	if(blnIsLargeTextArea) {
		g('imgTextArea').style.left = rxpos('mainDiv') + p(crf*50) + "px";
		g('imgTextArea').style.top = rypos('imgTopWave') + p(crf*120) + "px";
		g('masterContainer1').style.width = p(crf*390) + "px";
		g('masterContainer1').style.height = p(crf*190) + "px";
		g('masterContainer1').style.left = p(g('imgTextArea').style.left) + p(crf*95) + "px";
		g('masterContainer1').style.top = p(g('imgTextArea').style.top) + p(crf*60) + "px";
		g('documentContainer1').style.width = g('masterContainer1').offsetWidth - p(crf*12) + "px";

		g('lukknap').style.left = p(g('imgTextArea').style.left) + p(crf*85) + "px";
		g('lukknap').style.top = p(g('imgTextArea').style.top) + p(crf*72) + "px";
	}
	else {
		g('imgTextArea').style.left = rxpos('mainDiv') + p(crf*100) + "px";
		g('imgTextArea').style.top = rypos('imgTopWave') + p(crf*150) + "px";
		g('masterContainer1').style.width = p(crf*230) + "px";
		g('masterContainer1').style.height = p(crf*110) + "px";
		g('masterContainer1').style.left = p(g('imgTextArea').style.left) + p(crf*55) + "px";
		g('masterContainer1').style.top = p(g('imgTextArea').style.top) + p(crf*37) + "px";
		g('documentContainer1').style.width = g('masterContainer1').offsetWidth - p(crf*12) + "px";
		
		g('lukknap').style.left = p(g('imgTextArea').style.left) + p(crf*45) + "px";
		g('lukknap').style.top = p(g('imgTextArea').style.top) + p(crf*48) + "px";		

	}
	
	g('arrowContainer1').style.left = rxpos('masterContainer1') + g('masterContainer1').offsetWidth + p(crf*20) + "px";
	g('arrowContainer1').style.top = rypos('masterContainer1') + p((g('masterContainer1').offsetHeight / 2) - (g('arrowContainer1').offsetHeight / 2)) + "px";
	
	
	if(g('tblMenu').rows[0].cells.length > 6 && !blnFirstRun) {
		var intDistance = rxposObj(g('tblMenu').rows[0].cells[6]) - rxpos('tblMain');
		if(intDistance < p(crf*300)) {
			intDistance = p(crf*300) - intDistance;
			g('tblMenu').rows[0].cells[7].childNodes[0].style.width = intDistance + "px";
		}
	}
	
	if(g('tblMenu').rows[0].cells.length > 17 && !blnFirstRun) {
		var intCellToAlter = g('tblMenu').rows[0].cells.length - 7;
		var intDistance = g('tblMenu').offsetWidth - rxposObj(g('tblMenu').rows[0].cells[intCellToAlter]);
		var intPadding = rxpos('tblMenu') - rxpos('tblMain');
		var intSpace = g('tblMain').offsetWidth - (intPadding * 2) - g('tblMenu').offsetWidth;
		if(intSpace > 0) {
			g('tblMenu').rows[0].cells[intCellToAlter].childNodes[0].style.width = intSpace + g('tblMenu').rows[0].cells[g('tblMenu').rows[0].cells.length - 1].offsetWidth + "px";
		}
	}
	
	if(!blnFirstRun) { 
		blnFirstRun = true; 
	}
}

function toggleInfo() {
	if(g('masterContainer1').style.display=="block") {
		g('masterContainer1').style.display = "none";
		g('documentContainer1').style.display = "none";
		g('arrowContainer1').style.display = "none";
		g('imgTextArea').style.display = "none";
		g('lukknap').style.display = "none";
	}
	else {
		g('masterContainer1').style.display = "block";
		g('documentContainer1').style.display = "block";
		g('arrowContainer1').style.display = "block";
		g('imgTextArea').style.display = "block";
		g('lukknap').style.display = "block";
	}
}
var intCurrImg = 0;

function nextImage() {
	if(typeof(arrPageImages)!="undefined") {
		intCurrImg += 1;
		if(intCurrImg>=arrPageImages.length) {
			intCurrImg = 0;
		}
		g('bgImage').src = arrPageImages[intCurrImg];
	}
}

function prevImage() {
	if(typeof(arrPageImages)!="undefined") {
		intCurrImg -= 1;
		if(intCurrImg<0) {
			intCurrImg = arrPageImages.length - 1;
		}
		g('bgImage').src = arrPageImages[intCurrImg];
	}
}


function printThis(v)
{ 
	if(v!=0) {
		document.forms.printform.printboat.value = v;
	}
	document.forms.printform.printwhat.value = document.getElementById("documentContainer").innerHTML;
	document.forms.printform.submit();
}

function printerfocus()
{
	printframe.focus();
	printframe.print();
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function wheel(event) {
    var delta = 0;
    if (!event) 
            event = window.event;
    if (event.wheelDelta) { 
            delta = event.wheelDelta/120;
            if (window.opera)
                    delta = -delta;
    } else if (event.detail) { 
            delta = -event.detail/3;
    }
    if (delta)
            handle(delta);
    if (
    event.preventDefault)
    event.preventDefault();
		event.returnValue = false;
		}

function handle(delta) {
	var o = document.getElementById("documentContainer1");
		if(delta < 0) {	
				if(parseInt(o.style.top) > parseInt(o.offsetHeight*-1) + document.getElementById("masterContainer1").offsetHeight) {
					tempmove = delta * -3
					o.style.top = parseInt(o.style.top) - tempmove + "px";
					scroller1.ileftpos = parseInt(o.style.top) - tempmove;
				}
		}
		else {
			if(parseInt(document.getElementById("documentContainer1").style.top) < 0) {
			 	tempmove = delta * -3
				o.style.top = parseInt(o.style.top) - tempmove + "px";
				scroller1.ileftpos = parseInt(o.style.top) - tempmove;
			}
		}
	}