var site = null;

var trtop = null;
var trmiddle = null;

var tdleft = null;
var tdcenter = null;
var tdright = null;
var tdspacer = null;

var boxspacer = null;
var boxleft = null;
var boxcenter = null;
var boxright = null;
var boxflag = null;
var boxtabsmain = null;
var boxtabsmainbluebox = null;
var boxcontentleft = null;

var imglogotop = null;

var imgleftbottom = null;
var imgcenter = null;
var imgrightbottom = null;

var imgmapdenmark = null;
var imgumbrella = null;

var paddingBottom = 0;

var browsearrows = null;
var browsearrowsupdown = null;
var imgbrowsearrowsupdown = null;

var toplinks = null;

var infobox = null;

var boxbreadcrumb = null;

var downloadbrochure = null;

function initialize()
{
	if (jsres == 0) paddingBottom = crf*-11;
	if (jsres == 1) paddingBottom = crf*-12 - 1;

	trtop = g("tr_top");
	trmiddle = g("tr_middle");

	tdspacer = g("td_spacer");
	tdleft = g("td_left");
	tdcenter = g("td_center");
	tdright = g("td_right");
	tdtop = g("td_top");
	tdspacer = g("td_spacer");

	boxspacer = g("box_spacer");
	boxleft = g("box_left")
	boxcenter = g("box_center")
	boxright = g("box_right");
	boxbreadcrumb = g("box_breadcrumb");

	boxflag = g("box_flag");
	boxtabsmain = g("box_tabs_main");
	boxtabsmainbluebox = g("box_tabs_main_bluebox");
	boxcontentleft = g("box_content_left");

	imglogotop = g("img_logo_top");
	imglinehorizontal = g("img_line_horizontal");

	frameleftbottom = g("frame_left_bottom");
	framerightbottom = g("frame_right_bottom");

	imgleftbottom = g("img_left_bottom");
	/*imgcenter = g("img_center"); */
	imgcenter = g("img_center_content");
	
	imgrightbottom = g("img_right_bottom");

	imgmapdenmark = g("img_mapdenmark");
	imgumbrella = g("img_umbrella");

	textfrontimage = g("img_textfrontimage");

	
	browsearrows = g("browse_arrows");
	browsearrowsupdown = g("browse_arrows_updown");
	imgbrowsearrowsupdown = g("img_browse_arrows_updown");

	toplinks = g("top_links");

	infobox = g("info_box");

	downloadbrochure = g("div_download_brochure");

	site = g("site");
	reposition();
}

function reposition()
{
	siteleft = ( document.body.offsetWidth / 2)  - (site.offsetWidth / 2)
	sitetop  = ( document.body.offsetHeight / 2) - (site.offsetHeight / 2) - (boxbreadcrumb.offsetHeight / 2)
	site.style.left = ( (siteleft > 0)?siteleft-20/2:0 ) + "px";
	site.style.top = ( (sitetop > 0)?sitetop-2:0 ) + "px";
}

function setup_global()
{
	initialize();
	setup_box_top();
	setup_boxes();
	setup_images();
	show_tabs();
	add_png_fix();
	show_first_center_image();



	if (toplinks)
	{
		toplinks.style.left = rxpos(imglogotop.id) + imglogotop.offsetWidth + crf*112 + "px";
		toplinks.style.top = rypos(td_center.id) - crf*7 - toplinks.offsetHeight + "px";
	}

	if (downloadbrochure && toplinks)
	{
		downloadbrochure.style.left = rxpos(toplinks.id) + toplinks.offsetWidth + crf*75 + "px";
		downloadbrochure.style.top  = rypos(toplinks.id) + "px";
	}

	//alert("setup_global, jsimages.length: " + jsimages.length );
	if (jsimages.length == 0) browsearrowsupdown.style.display = "none";

	if (site.style.visibility != "visible") site.style.visibility = "visible";


	//iLeft = (g("img_center_content").offsetWidth + 2*( crf*g("imgFrontFrameLeft").offsetWidth) ) / 3;


	if	(
			intMyCamp == 1
			&& g("imgFrontFrameLeft")
			&& g("imgFrontFrameRight")
			&& g("imgFrontFrameImageLeft")
			&& g("imgFrontFrameImageRight")
			&& g("imgFrontGirl")
			&& g("imgFrontBoy")
			&& g("img_mapdenmark")
			&& g("browse_arrows")
			&& g("img_logo_top")
		)
	{
		iLeft = ( crf*570 - 2*(crf*218) ) / 3;

		g("imgFrontFrameLeft").style.left = rxpos("img_center_content") + iLeft + "px";
		g("imgFrontFrameLeft").style.top  = rypos("box_center") + g("box_center").offsetHeight - g("imgFrontFrameLeft").offsetHeight - crf*30 + "px";

		g("imgFrontFrameRight").style.left = rxpos("box_center") + g("box_center").offsetWidth - iLeft - g("imgFrontFrameRight").offsetWidth + "px";
		g("imgFrontFrameRight").style.top  = rypos("imgFrontFrameLeft") + "px";

		extraX = 0;
		extraY = 0;
		if (jsres == 1)
		{
			extraX = 1;
		}

		if (jsres == 2)
		{
			extraY = 3;
		}

		g("imgFrontFrameImageLeft").style.left = rxpos("imgFrontFrameLeft") + crf*4 + extraX + "px";
		g("imgFrontFrameImageLeft").style.top  = rypos("imgFrontFrameLeft") + crf*60 + extraY + "px";

		g("imgFrontFrameImageRight").style.left = rxpos("imgFrontFrameRight") + crf*4 + extraX + "px";
		g("imgFrontFrameImageRight").style.top  = rypos("imgFrontFrameRight") + crf*60 + extraY + "px";

		g("imgFrontGirl").style.left = rxpos("site") + g("box_left").offsetWidth / 2 - g("imgFrontGirl").offsetWidth / 2 + "px";
		g("imgFrontGirl").style.top  = rypos("site") + g("site").offsetHeight - g("imgFrontGirl").offsetHeight + crf*10 + "px";

		g("imgFrontBoy").style.left = rxpos("box_right") + g("box_right").offsetWidth / 2 - g("imgFrontBoy").offsetWidth / 2 + "px";
		g("imgFrontBoy").style.top  = rypos("site") + crf*125 + "px";

		g("img_mapdenmark").style.visibility = "hidden";
		//g("img_mapdenmark").src = 'gfx/mycamp/map_denmark_' + jsres + '.png';

		setTimeout('g("img_mapdenmark").style.left = rxpos("box_right") + g("box_right").offsetWidth / 2 - g("img_mapdenmark").offsetWidth / 2 + "px"; g("img_mapdenmark").style.top  = rypos("imgFrontBoy") + crf*157 + "px"; g("img_mapdenmark").style.visibility = "visible";', 1);
		
		/*
		g("img_mapdenmark").onload = function()
		{
			g("img_mapdenmark").style.left = rxpos("box_right") + g("box_right").offsetWidth / 2 - g("img_mapdenmark").offsetWidth / 2 + "px";
			g("img_mapdenmark").style.top  = rypos("imgFrontBoy") + crf*157 + "px";
			g("img_mapdenmark").style.visibility = "visible";
		}
		*/

		g("browse_arrows").style.top = rypos("box_center") + g("box_center").offsetHeight / 2 - g("browse_arrows").offsetHeight / 2 - crf*60 + "px";

		g("img_logo_top").src = 'gfx/mycamp/logo_' + jsres + '.png';
		g("img_logo_top").style.left = rxpos("site") + crf*20 + "px";
		g("img_logo_top").style.top  = rypos("site") - crf*1 + "px";


		// hide stuff that we dont need:
		g("frame_left_bottom").style.display = "none";
		g("img_left_bottom").style.display = "none";

		g("frame_right_bottom").style.display = "none";
		g("img_right_bottom").style.display = "none";

	}

	if (g("imgloading")) g("imgloading").style.display = "none";
}

function add_png_fix()
{
	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 setup_boxes()
{
	if (trmiddle)
	{
		boxbreadcrumb.style.left = rxpos(site.id) + "px";
		boxbreadcrumb.style.width = site.offsetWidth + "px";
		//boxbreadcrumb.style.left = rxpos(site.id) + site.offsetWidth - boxbreadcrumb.offsetWidth - crf*5 + "px";
		boxbreadcrumb.style.top = rypos(site.id) + site.offsetHeight + crf*3 + "px";


		if (boxflag)
		{
			LEFTflag = 0;
			TOPflag = -5;
			boxflag.style.paddingTop = crf*2 + "px";

			if (jsres == 1)
			{
				LEFTflag = 0;
				TOPflag = 2*0;
				boxflag.style.paddingTop = crf*3 + "px";
			}
			if (jsres == 2)
			{
				LEFTflag = 0;
				TOPflag = 10*0; // used to be 30
				boxflag.style.paddingTop = crf*4 + "px";
			}

			boxflag.style.left = rxpos(site.id) + site.offsetWidth - boxflag.offsetWidth - LEFTflag + "px";
			boxflag.style.top = rypos(site.id) + crf*21 - crf*14 + crf*TOPflag + "px";
		}

		if (boxtabsmain && tdtop)
		{
			boxtabsmain.style.left = rxpos(tdtop.id) + tdtop.offsetWidth - boxtabsmain.offsetWidth + "px";
			boxtabsmain.style.top = rypos(tdtop.id) + tdtop.offsetHeight - boxtabsmain.offsetHeight + crf*3 + "px";
		}

		if (boxtabsmainbluebox && tdtop)
		{
			boxtabsmainbluebox.style.left = rxpos(tdtop.id) + "px";
			box_tabs_main_bluebox.style.top = rypos(tdtop.id) + tdtop.offsetHeight - boxtabsmainbluebox.offsetHeight + "px";
			box_tabs_main_bluebox.style.width = site.offsetWidth + "px";
		}		
		
		if (boxleft)
		{
			boxleft.style.left = rxpos(tdleft.id) + "px";
			boxleft.style.top = rypos(tdspacer.id) + tdspacer.offsetHeight + "px";
			boxleft.style.width = tdleft.offsetWidth + "px";
			boxleft.style.height = tdleft.offsetHeight + "px";

			boxcenter.style.left = rxpos(tdcenter.id) + "px";
			boxcenter.style.top = rypos(boxleft.id) + "px"; /* center image */
			boxcenter.style.width = tdcenter.offsetWidth + "px";
			boxcenter.style.height = tdcenter.offsetHeight + "px";

			
				LEFTbrowsearrows = crf*6*0;
				browsearrows.style.width = boxcenter.offsetWidth - 2*LEFTbrowsearrows + "px";
				browsearrows.style.left = rxpos(boxcenter.id) + LEFTbrowsearrows + "px";
//				browsearrows.style.top = rypos(boxcenter.id) + boxcenter.offsetHeight - boxcenter.offsetHeight / 2 - browsearrows.offsetHeight + "px";
				browsearrows.style.top = ( ( rypos(boxcenter.id) + boxcenter.offsetHeight ) / 2 + rypos(site.id) ) + "px";

/*
				alert(""
					+ "\n rypos(boxcenter.id): " + rypos(boxcenter.id)
					+ "\n boxcenter.offsetHeight): " + boxcenter.offsetHeight
					+ "\n boxcenter.offsetHeight) / 2: " + (boxcenter.offsetHeight / 2)
					+ "\n browsearrows.offsetHeight: " + browsearrows.offsetHeight
					+ "\n browsearrows.offsetHeight / 2: " + (browsearrows.offsetHeight / 2)
					+ "\n "
					+ "\n" + ( (rypos(boxcenter.id) + boxcenter.offsetHeight) / 2 - browsearrows.offsetHeight / 2 )
					);
*/

/*
-- first run:
202
717
358,5
0
0



-- resize:
201
717
358,5
53
26,5

21x53

*/


				//browsearrows.style.top = (rypos(boxcenter.id) + boxcenter.offsetHeight) / 2 - browsearrows.offsetHeight / 2 /*+ rypos(site.id)*/ + "px";

			
				boxright.style.left = rxpos(tdright.id) + "px";
				boxright.style.top = rypos(boxleft.id) + "px";
				boxright.style.width = tdright.offsetWidth + "px";
				boxright.style.height = tdright.offsetHeight + "px";
		}

		if (boxcenter)
		{
			if (browsearrowsupdown && imgbrowsearrowsupdown)
			{
				browsearrowsupdown.style.left = rxpos(boxcenter.id) + boxcenter.offsetWidth - crf*42 - crf*9 + "px";
				browsearrowsupdown.style.top = rypos(boxcenter.id) + crf*2*0 + "px"; // *0
				browsearrowsupdown.style.display = "";
				if (show_image_instead_of_text == 1) showhideimagelist();
				if (page_has_center_text == 0) imgbrowsearrowsupdown.style.display = "none";
			}
		}
	}
}

function setup_box_top()
{
	if (imglinehorizontal)
	{
		imglinehorizontal.style.left = rxpos(tdtop.id) + "px";
		imglinehorizontal.style.top = rypos(tdtop.id) + tdtop.offsetHeight + "px";

		
		if (imglogotop)
		{
			imglogotop.style.left = rxpos(tdtop.id) + crf*24 - crf*10 + "px";
			imglogotop.style.top = rypos(imglinehorizontal.id) - imglogotop.offsetHeight / 2 - imglogotop.offsetHeight / 4 - crf + "px";
		}

		if (imgumbrella && imglogotop)
		{
			LEFTimgumbrella = 0;
			TOPimgumbrella = crf;
			if (jsres == 0)
			{
				LEFTimgumbrella = -10;
			}
			if (jsres == 1)
			{
				LEFTimgumbrella = 10;
			}
			if (jsres == 2)
			{
				TOPimgumbrella = -22;
			}
			imgumbrella.style.left = rxpos(imglogotop.id) - rxpos(site.id) + imglogotop.offsetWidth + crf*85 + "px";
			//imgumbrella.style.left = rxpos(imglogotop.id) + imglogotop.offsetWidth + crf*83 - boxflag.offsetWidth + LEFTimgumbrella + "px";
			imgumbrella.style.top = rypos(imglinehorizontal.id) - rypos(imglinehorizontal.id) + TOPimgumbrella + "px";
		}
	}
}

function setup_images()
{

	if (frameleftbottom && imgleftbottom)
	{
		if (jsres == 0) paddingBottom = -crf*16;
		if (jsres == 1) paddingBottom = -crf*15;
		if (jsres == 2) paddingBottom = -25;

		frameleftbottom.style.left = rxpos(tdleft.id) + ( ( tdleft.offsetWidth - frameleftbottom.offsetWidth) / 2 ) + "px";
		frameleftbottom.style.top = rypos(boxcenter.id) + boxcenter.offsetHeight - frameleftbottom.offsetHeight + paddingBottom + "px";

		imgleftbottom.style.left = rxpos(frameleftbottom.id) + crf*5 + "px";
		imgleftbottom.style.top  = rypos(frameleftbottom.id) + crf*4 + "px";
	}

	if (framerightbottom && imgrightbottom)
	{
		framerightbottom.style.left = rxpos(tdright.id) + ( ( tdright.offsetWidth - framerightbottom.offsetWidth) / 2 ) + "px";
		framerightbottom.style.top  = rypos(tdright.id) + tdright.offsetHeight - framerightbottom.offsetHeight + paddingBottom + "px";

		imgrightbottom.style.left = rxpos(framerightbottom.id) + crf*5 + "px";
		imgrightbottom.style.top  = rypos(framerightbottom.id) + crf*4 + "px";
	}

	/**
	if (imgcenter)
	{
		TOPimgcenter = 0;
		if (jsres == 2) TOPimgcenter =  20;
		imgcenter.style.left = rxpos(tdcenter.id) + "px";
		imgcenter.style.top  = rypos(tdcenter.id) + TOPimgcenter + "px";
	}
	/**/

	if (imgmapdenmark)
	{
		imgmapdenmark.style.left = rxpos(tdright.id) + ( ( tdright.offsetWidth - imgmapdenmark.offsetWidth) / 2 ) + "px";
		imgmapdenmark.style.top  = rypos(tdright.id) + crf*26 + "px";
	}

	if (boxcontentleft)
	{
		boxcontentleft.style.left = rxpos(boxleft.id) + "px";
		boxcontentleft.style.top = rypos(boxleft.id) + "px";
		boxcontentleft.style.width = boxleft.offsetWidth + "px";
		//boxcontentleft.style.height = boxleft.offsetHeight - rypos(boxcontentleft.id) + crf*-15*3 + "px";
		boxcontentleft.style.height = tdleft.offsetHeight - rypos(boxcontentleft.id) + rypos(tdleft.id) + "px";
//		boxcontentleft.style.backgroundColor = "#ff0000";
		if (frameleftbottom)
		{
			boxcontentleft.style.height = rypos(frameleftbottom.id) - rypos(boxcontentleft.id) - crf*15 + "px";
		}
	}

	if (textfrontimage && tdcenter && imgcenter)
	{
		LEFTtextfrontimage = 0;
		TOPtextfrontimage = -33;
		if (jsres == 1)
		{
			LEFTtextfrontimage = crf * -10;
			TOPtextfrontimage  = crf *  -26;
		}
		if (jsres == 2)
		{
			LEFTtextfrontimage = crf * -14;
			TOPtextfrontimage  = crf * -26;
		}
		
		if (textfrontimage && imgleftbottom)
		{

			//alert("y: " + parseInt(rypos(imgcenter.id) + imgcenter.offsetHeight ) ) ;// + imgcenter.offsetHeight - textfrontimage.offsetHeight + TOPtextfrontimage) );
			//textfrontimage.style.top  = parseInt(rypos(imgcenter.id) + imgcenter.offsetHeight - textfrontimage.offsetHeight + TOPtextfrontimage) + "px";

			//textfrontimage.style.left = parseInt(rxpos(tdcenter.id) + crf*15 + LEFTtextfrontimage) + "px";
			//textfrontimage.style.top  = parseInt(rypos(imgleftbottom.id)) + "px";
		}
		
	}
}

function show_tabs()
{
	divs = document.getElementsByTagName("div");
	for(var i = 0, len = divs.length; i < len; i++)
	{
		div = divs[i];
		if (div.className.indexOf("tab") > -1)
		{
			div.style.display = "";
		}
	}
}

function show_first_center_image()
{
	if (jsimages.length > 0)
	{
		if (jsimages.length > 1 && g("browse_arrows"))
		{
			g("browse_arrows").style.display = "";
		}
		showimage();
	}
}


function infoboxhint(txt, obj)
{
	if (obj == null)
	{
		infobox.style.display = "none";
		infobox.firstChild.nodeValue = "";
		return;
	}
	if (infobox)
	{
		/*
		if (obj.id == "img_browse_arrows_updown")
		{
			t = txt.split("|");
			if (obj.getAttribute("src").toLowerCase().indexOf("down") > -1)
			{
				txt = t[0];
			} else {
				txt = t[1];
			}
		}
		/**/
		infobox.style.display = "";
		if (infobox.childNodes.length == 0) infobox.appendChild(document.createTextNode(""));
		infobox.firstChild.nodeValue = txt;
		if (infobox.offsetWidth > crf*125)  infobox.style.width = crf*125 + "px";
		infobox.style.left = rxposObj(obj) - infobox.offsetWidth / 2 + "px";
		infobox.style.top = ryposObj(obj) + obj.offsetHeight + crf*10 + "px";
	} else {
		alert("info_box does not exist");
	}
}

bUpDown = 0;
if (show_image_instead_of_text == 1) bUpDown = 0;
function showhideimagelist()
{
	path = "gfx/browse_arrows/" + jsres + "/browse_arrow_$dir$.gif";
	if (bUpDown == 1)
	{
		path = path.replace("$dir$","down");
	} else {
		path = path.replace("$dir$","up");
	}

	if (imgbrowsearrowsupdown)
	{
		title = " hello world ";
		//src = imgbrowsearrowsupdown.getAttribute("src").toLowerCase();
		//alert(src);
		//if (src.indexOf("down") > -1)
		if (path.indexOf("up") > -1)
		{
			//src = src.replace("down","up");
			g("img_center_content").style.display = "block";
			textfrontimage.style.display = "block";
			g("content_text_center").style.display = "none";
			boxcenter.style.overflow = "hidden";
			if (jsimages.length > 1) browsearrows.style.display = "block";
			title = " Vis tekst ";
			bUpDown = 1;
		} else {
			//src = src.replace("up","down");
			g("img_center_content").style.display = "none";
			g("content_text_center").style.display = "block";
			boxcenter.style.overflow = "auto";
			browsearrows.style.display = "none";
			textfrontimage.style.display = "none";
			title = " Vis billede ";
			bUpDown = 0;
		}
		//imgbrowsearrowsupdown.setAttribute("src", src);
		imgbrowsearrowsupdown.setAttribute("src", path);
		//imgbrowsearrowsupdown.title = title;
		//alert("done");
	}
}