var is_ie6 = (navigator.userAgent.toLowerCase().indexOf("msie 6") > -1)?true:false;
var site = null;

function setup_global()
{
	initialize();
}

function initialize()
{
	if (window.location.href.toLowerCase().indexOf("print.asp")  > -1 ) return;

	site = g("tblSite");
	if (blnFirstRun) nextImage();
	reposition();
	setupBoxes();
	setupContents();
	addPngFix();
	
	//g("Imgtxt").style.display = "none";
	//g("photoinfoClose").style.display = "none";
	//setupGradient();
	//createTransImages();
}



//******************************************* Slide show

var intCurrImg = 0;
function nextImage2() {
	//alert('next');
	if(typeof(arrPageImages2)!="undefined") {
		intCurrImg += 1;
		if(intCurrImg>=arrPageImages2.length) {
			intCurrImg = 0;
		}
		g('MainImage').style.backgroundImage = "url(\"" + arrPageImages2[intCurrImg] + "\")";
		g('Imgtxt').innerHTML = arrPageImagestxt[intCurrImg];
		
		if( arrPageImages2txt[intCurrImg] != "<br><br>" ){
			g("photoinfo").style.display = "block";
		}else{
			g("photoinfo").style.display = "none";
		}							
	}	
}

function prevImage2() {
	//alert('prev');
	if(typeof(arrPageImages2)!="undefined") {
		intCurrImg -= 1;
		if(intCurrImg<0) {
			intCurrImg = arrPageImages2.length - 1;
		}
		g('MainImage').style.backgroundImage = "url(\"" + arrPageImages2[intCurrImg] + "\")";
		g('Imgtxt').innerHTML = arrPageImagestxt[intCurrImg];
		
		if( arrPageImages2txt[intCurrImg] != "<br><br>" ){
			g("photoinfo").style.display = "block";
		}else{
			g("photoinfo").style.display = "none";
		}				
	}
}
//********** show/hide imagetext
var lukstateimg=2;
function toggleImgTxt() {	
	if (lukstateimg == 1) {
		lukstateimg=2;	
		g("Imgtxt").style.display = "none";
		g("photoinfoClose").style.display = "none";
		g("photoinfoOpen").style.display = "block";
		
			
	}else{		
		lukstateimg=1;		
		g("Imgtxt").style.display = "block";
		g("photoinfoClose").style.display = "block";
		g("photoinfoOpen").style.display = "none";		
		//g('Imgtxt').style.top = rypos('photoinfo') - g("Imgtxt").offsetHeight + g("photoinfo").offsetHeight - p(jsRF * 1) + "px";

		
	}
}
//******************************************* END Slide show

function reposition()
{
	siteleft = ( pageWidth / 2)  - (site.offsetWidth / 2);
	sitetop  = ( pageHeight / 2) - (site.offsetHeight / 2) ; //- (boxbreadcrumb.offsetHeight / 2)
	site.style.left = ( (siteleft > 0)?siteleft :0 ) + "px";
	site.style.top  = ( (sitetop  > 0)?sitetop-2:0 ) + "px";
}

function addPngFix()
{
	if (navigator.userAgent.toLowerCase().indexOf("msie 7") > -1) return;
	pngimg = document.getElementsByTagName("img");
	for(var i = 0, len = pngimg.length; i < len; i++)
	{
		if (pngimg[i].src.toLowerCase().indexOf(".png") > -1)
		{
			pngimg[i].className += " overlay";
		}
	}
}

function createLine(X,Y,W,H,bgcolor,zindex,line_id)
{
	var line = null;
	var is_new_line = (document.getElementById(line_id) == null);
	if (is_new_line)
	{
		line = document.createElement("img");
		line.setAttribute("id", line_id);
		line.setAttribute("src", "gfx/space.gif");
		line.style.position = "absolute";
		document.body.appendChild(line);
	} else {
		line = document.getElementById(line_id);
	}
	line.style.left = ((X)?X:1) + "px";
	line.style.top = ((Y)?Y:1) + "px";
	line.style.width  = ((W)?W:1) + "px";
	line.style.height = ((H)?H:1) + "px";
	line.style.backgroundColor = ((bgcolor)?bgcolor:'#000000');
	if (zindex) line.style.zIndex = zindex;
}

function resValue(r0,r1,r2)
{
	if (jsres == 0)
	{
		return r0;
	} else {
		if (jsres == 1)
		{
			return r1;
		} else {
			return r2;
		}
	}
}

function setFocusInput(obj) { obj = (typeof(obj) == "string")?g(obj):obj; if (obj != null) obj.focus(); }

function right(obj) {  obj = (typeof(obj) == "string")?g(obj):obj; return rxpos(obj.id) + obj.offsetWidth; }

function bottom(obj) { obj = (typeof(obj) == "string")?g(obj):obj; return rypos(obj.id) + obj.offsetHeight; }

function centerVert(objToCenter, objCenterTo)
{
	objCenterTo = (typeof(objCenterTo) == "string")?g(objCenterTo):objCenterTo;
	objToCenter = (typeof(objToCenter) == "string")?g(objToCenter):objToCenter;
	return (rypos(objCenterTo.id) + objCenterTo.offsetHeight / 2) - (objToCenter.offsetHeight /2);
}

function centerHori(objToCenter,objCenterTo)
{
	objCenterTo = (typeof(objCenterTo) == "string")?g(objCenterTo):objCenterTo;
	objToCenter = (typeof(objToCenter) == "string")?g(objToCenter):objToCenter;
	return (rypos(objCenterTo.id) + objCenterTo.offsetWidth / 2) - (objToCenter.offsetWidht /2);
}

// -----


function setupBoxes()
{

	g("site").style.left = rxpos("tdTop") + "px";
	g("site").style.top  = rypos("tdTop") + "px";


	g("divBottomTextLeft").style.left = rxpos("tdBottom") + crf*20 + "px";
	g("divBottomTextLeft").style.top  = rypos("tdBottom") + crf*3 + "px";

	g("divBottomTextRight").style.left = right("tdBottom") - g("divBottomTextRight").offsetWidth - crf*10 + "px";
	g("divBottomTextRight").style.top  = rypos("divBottomTextLeft") + "px";
	
	topExtra = 0;
	g("divMenuTop").style.left = right("tdMenuLeft") - crf*1 + "px";

	g("divMenuLeft").style.left = rxpos("tdMenuLeft") + "px";
	g("divMenuLeft").style.top  = rypos("tdMenuLeft") + "px";

	g("divTopLogo").style.left = rxpos("tdTop") + "px";
	g("divTopLogo").style.top  = rypos("tdTop") + crf*25 + "px";

	//g("divTopImageRight").style.left = right("tdTop") - g("divTopImageRight").offsetWidth + "px";
	//g("divTopImageRight").style.top  = rypos("tdTop") + "px";

	g("top_img_div").style.left = right("tdTop") - g("top_img_div").offsetWidth + "px";
	g("top_img_div").style.top  = rypos("tdTop") + "px";


	g("divHomePrint").style.left = rxpos("top_img_div") - g("divHomePrint").offsetWidth - crf*7 + "px";
	g("divHomePrint").style.top  = rypos("tdTop") + crf*5 + "px";

	// extra adjustments
	tds = g("tblTopMenu").getElementsByTagName("td");
	//g("divTopImageRight").style.overflow = "hidden";
	if (ie5)
	{
		topExtra = -1;
		for(var i = 0, len = tds.length; i < len; i++) tds[i].style.height = resValue(17,22,27) + "px";
//		if (jsres == 2) g("divTopImageRight").style.height = 166 + "px";
		g("divTopImageRight").style.height = resValue(105,131,164) + "px";
	} else if (ns6)	{
		if (jsres == 2) topExtra = -1;
		for(var i = 0, len = tds.length; i < len; i++) tds[i].style.height = resValue(20,25,31) + "px";
		//g("divTopImageRight").style.height = crf*105 + "px";
		g("divTopImageRight").style.height = resValue(105,131,165) + "px";
	} else {
		for(var i = 0, len = tds.length; i < len; i++) tds[i].style.height = resValue(16,21,26) + "px";
		g("divTopImageRight").style.height = resValue(105,131,164) + "px";
	}
	g("divMenuTop").style.top  = rypos("tdTopMenu")  + crf + topExtra + "px";


	// resize menu2, menu3:
	var menu2width = resValue(143,179,223);
	var menu3width = resValue(130,163,203);
	ds = document.getElementsByTagName("div");
	for(var i = 0, len = ds.length; i < len; i++)
	{
		d = ds[i];

		if (d.className == "menu2" || d.className == "menu2sel")
		{
			d.style.width = menu2width + "px";
		} else if (d.className == "menu3" || d.className == "menu3sel")
		{
			d.style.width = menu3width + "px";
		}
	}

	
	if (g("imgGradientTop"))
	{
		g("imgGradientTop").style.left    = rxpos("tblSite") + crf*resValue(2,2,1.5) + "px";
		g("imgGradientTop").style.top     = rypos("tdTopMenu") + "px";
		g("imgGradientTop").style.height  = g("tdTopMenu").offsetHeight + "px";
	}

	if (g("imgGradientBottom"))
	{
		g("imgGradientBottom").style.left    = rxpos("tblSite") + crf*resValue(2,2,1.5) + "px";
		g("imgGradientBottom").style.top     = rypos("tdBottom") + "px";
		g("imgGradientBottom").style.height  = g("tdBottom").offsetHeight + "px";
	}

	if (g("imgGradientTopSelected") && g("tdTop"))
	{
		if (template_backgroundimage != "")
		{
			g("tdTop").style.backgroundImage = "url('img_template/" + template_backgroundimage + "')";
			g("tdTop").style.backgroundRepeat = "repeat-y";
		}
		
		tds = document.getElementsByTagName("td");
		for(i=0,len=tds.length;i<len;i++)
		{
			if (tds[i].className.toLowerCase().indexOf("menu1seltd") > -1)
			{
				g("imgGradientTopSelected").style.left				= rxpos(tds[i].id) + 0*crf*resValue(2,2,1.5) + "px";
				g("imgGradientTopSelected").style.top				= rypos("tdTopMenu") + "px";
				g("imgGradientTopSelected").style.width				= g(tds[i].id).offsetWidth + "px";
				g("imgGradientTopSelected").style.height			= g("tdTopMenu").offsetHeight + "px";
				//g("imgGradientTopSelected").style.backgroundColor	= menu1_selected_background_color;

				top_menu_border = 1;
				if ( top_menu_border )
				{
					g("imgGradientTopSelected").style.border		= "1px solid #ffffff";
					g("imgGradientTopSelected").style.top			= rypos("tdTopMenu") - 1 + "px";
				}
				break;
			}
		}
	}


}

function setupContents()
{
	
	if (intPageType == 2){intFullPage=2}
	switch (intFullPage)
	{
	case 0:

		if ( g("divBoxContents") && g("tdContentsRight") )
		{

			g("divBoxContents").style.left   = rxpos("tdContentsRight") + crf*35 + "px";
			g("divBoxContents").style.top    = rypos("tdContentsRight") + crf*60-2 + "px";
			g("divBoxContents").style.width  = crf*312 + "px";
			g("divBoxContents").style.height = crf*270 + "px";

			if ( g("divArrowsUpDownContents") && g("divBoxContents") )
			{
				if ( g("divBoxContentsDocument").offsetHeight > g("divBoxContents").offsetHeight )
				{
					g("divArrowsUpDownContents").style.display = "";
					g("divArrowsUpDownContents").style.left = right("divBoxContents") + crf*10 + "px";
					g("divArrowsUpDownContents").style.top  = centerVert("divArrowsUpDownContents","divBoxContents") + "px";
				}
			}

			if ( g("imgRight") )
			{
				g("imgRight").style.width  = crf*400 + "px";
				g("imgRight").style.height = crf*270 + "px";
				g("imgRight").style.left   = right("tdContentsRight") - g("imgRight").offsetWidth - crf*26 + "px";
				g("imgRight").style.top    = rypos("divBoxContents") + 100*0 + "px";
				//alert(g("imgRight").style.left);


				g("divImgRightDescription").style.left   = rxpos("imgRight") + "px";
				g("divImgRightDescription").style.top    = bottom("imgRight") + crf*5 + "px";
				g("divImgRightDescription").style.width  = g("imgRight").offsetWidth + crf*resValue(0,1,0.5) - crf*(2*2) + "px";
				g("divImgRightDescription").style.height = crf*resValue(48,44,42) - crf*(2*2) + "px";
			
				if (arrPageImages.length > 1 && g("divArrowsRightLeftImageSeries") && g("divImgRightCounter") )
				{
					if (arrPageImages[0] == "img/x.gif") return;
					g("divArrowsRightLeftImageSeries").style.display = "";
					g("divImgRightCounter").style.display            = "";

					g("divArrowsRightLeftImageSeries").style.left = right("imgRight") - g("divArrowsRightLeftImageSeries").offsetWidth + "px";
					g("divArrowsRightLeftImageSeries").style.top  = rypos("imgRight") - g("divArrowsRightLeftImageSeries").offsetHeight - crf*7 + "px";

					g("divImgRightCounter").style.left = rxpos("divArrowsRightLeftImageSeries") - g("divImgRightCounter").offsetWidth - crf*10 + "px";
					g("divImgRightCounter").style.top  = rypos("divArrowsRightLeftImageSeries") + "px";
				}
			}
		}
		break;

	case 1:
		if ( g("divBoxContents") && g("tdContentsRight") )
		{
			// one big div, HTML
			g("divBoxContents").style.left   = rxpos("tdContentsRight") + crf*35 + "px";
			g("divBoxContents").style.top    = rypos("tdContentsRight") + crf*60-2 + "px";
			g("divBoxContents").style.width  = g("tdContentsRight").offsetWidth - ( rxpos("divBoxContents") - rxpos("tdContentsRight") )*2 + "px";
			g("divBoxContents").style.height = g("tdContentsRight").offsetHeight - ( rypos("divBoxContents") - rypos("tdContentsRight") )*2 + "px";

			if ( g("divArrowsUpDownContents") && g("divBoxContents") )
			{
				g("divArrowsUpDownContents").style.left = right("divBoxContents") + crf*10 + "px";
				g("divArrowsUpDownContents").style.top  = centerVert("divArrowsUpDownContents","divBoxContents") + "px";
			}

		}
		break;
		
		
		
	case 2:
		if ( g("MainImage") && g("imgArrowLeft") && g("imgArrowRight") && g("Imgtxt") )
		{
			g("MainImage").style.left = rxpos("site") + crf*157 + "px";
			g("MainImage").style.top  = rypos("site") + crf*127 + "px";
				
				//alert(g("tblSite"));
			//alert(arrPageImages2.length);	
				//return;
				
			if (arrPageImages2.length > 1){
				g('imgArrowLeft').style.left = rxpos('MainImage') + crf*15 + "px";
				g('imgArrowLeft').style.top = rypos('site')+ crf*320 + "px";
				//g("imgArrowLeft").style.display = "none";			
		
				g('imgArrowRight').style.left = rxpos('MainImage') + g("MainImage").offsetWidth - crf*45 + "px";
				g('imgArrowRight').style.top = rypos('site')+ crf*320 + "px";
				//g("imgArrowRight").style.display = "none";
			}
			
			if (g("Imgtxt").style.display != "none")
			{
				g("Imgtxt").style.height = crf*60 + "px";
				g('Imgtxt').style.left = rxpos('MainImage') + g("MainImage").offsetWidth - g("Imgtxt").offsetWidth +"px";//- crf*0 + "px";
				g('Imgtxt').style.top = rypos('MainImage') + g("MainImage").offsetHeight - g("Imgtxt").offsetHeight + crf*0 + "px";
			}
	
			if (g("photoinfoClose").style.display != "none")
			{		
				g("photoinfoClose").style.height = crf*10 + "px";
				g('photoinfoClose').style.left = rxpos('MainImage') + g("MainImage").offsetWidth - g("photoinfoClose").offsetWidth - crf*0 + "px";
				//g('photoinfoClose').style.top = rypos('MainImage') + g("MainImage").offsetHeight - g("Imgtxt").offsetHeight - crf*10 + "px";
				g('photoinfoClose').style.top = rypos('Imgtxt') - crf*10 + "px";
			}
	
			g("photoinfoOpen").style.display = "block";
			g('photoinfoOpen').style.left = rxpos('MainImage') + g("MainImage").offsetWidth - g("photoinfoOpen").offsetWidth - crf*0 + "px";
			g('photoinfoOpen').style.top = rypos('MainImage') + g("MainImage").offsetHeight - g("photoinfoOpen").offsetHeight + crf*0 + "px";
			
			if (blnFirstRun){
				g("photoinfoClose").style.display = "none";
				g("Imgtxt").style.display = "none";
			}
	
		}
	
		break; // case 2
	
		
		
		
		
		
		
		
	}
	

blnFirstRun = false;
}

function setupGradient()
{
	tds = document.getElementsByTagName("td");
	for(i=0,len=tds.length;i<len;i++)
	{
		if (tds[i].className.toLowerCase().indexOf("menu1seltd") > -1)
		{
			if (!ie5) tds[i].style.backgroundImage = "url(img/gradient_04_0.png)";
			break;
		}
	}
}

function createTransImages()
{
	createTransImage("t_top",0,rypos("tblSite"),document.body.offsetWidth,rypos("tdTopMenu") - rypos("tdTop"),"#49205D",-1);
	createTransImage("t_topmenu",0,rypos("t_top")+g("t_top").offsetHeight+1,document.body.offsetWidth,g("tdTopMenu").offsetHeight,"#EE9221",-1);
	createTransImage("t_leftmenu",0,rypos("tdMenuLeft"),rxpos("tdMenuLeft")+g("tdMenuLeft").offsetWidth,g("tdMenuLeft").offsetHeight,"#009900",-1);
	createTransImage("t_bottom",0,rypos("tdBottom"),document.body.offsetWidth,g("tdBottom").offsetHeight,"#49205D",-1);
}

function createTransImage(ID,X,Y,W,H,BGCOLOR,ZINDEX)
{
	BGCOLOR = "" + BGCOLOR;

	img = document.createElement("img");
	img.setAttribute("id", ID);
	img.setAttribute("src", "img/x.gif");
	img.style.position = "absolute";
	img.style.left = X + "px";
	img.style.top = Y + "px";
	img.style.width = W + "px";
	img.style.height = H + "px";
	img.style.backgroundColor = (BGCOLOR.indexOf("#") == -1)? "#" + BGCOLOR:BGCOLOR;
	if (ZINDEX) img.style.zIndex = ZINDEX;

	document.body.appendChild(img);
}



