/*LAYOUT*/
var samHighChanges=20;
var isPrint=false;

function bodyOnload()
{
  if(isPrint) return;
  onloadNav('hnRight');
  sameHigh('pol'); 
  initSlideShow('dImage');
}
 														  
function sameHigh()
{
  try{pos=$("dImage").className;}
	catch(e){pos="pnone";}
	
	//Endlosschleife im Fall 4 verhindern
	samHighChanges--;
	if(samHighChanges<1) return false;
	//return;
	//alert("test1");
	//Fall 1 und Fall 2
	if(pos=="pol" || pos=="pul")
	{
  	//setDivsSameHigh(new Array("oL","oR"));
    setDivsSameHigh(new Array("uL","uR"));
		//alert("test2");
		imgs=$("uL").getElements("img");
		if(imgs.length>1) 
		{
  		$("dImage").setStyle("width",239);
  		$("dImage2").setStyle("width",238);
		}
		else $("dImage").setStyle("width",518);
		$("uL").setStyle("overflow","hidden");
	}
	//Fall 1
	if(pos=="pol")
	{
	  $("uL").className="uL green";
		div=$("uL").getElements("div")[0].className;
		if($("uL").getSize().y<231) $("uL").setStyle("height",231);
		$("uR").className="uR gray";
		setDivsSameHigh(new Array("uL","uR"));
	}
	if(pos=="pul")
	{
  	sizeL=$$(".cLeft")[0].getSize();
  	sizeR=$$(".cRight")[0].getSize();
		sizeY=sizeL.y-sizeR.y;
		
		if(sizeY>0) 
		{
  		div=document.createElement("div");
  		div.style.height=sizeY+"px";
			div.id="placeholder";
			div.style.borderLeft="1px solid #fff";
  		$$(".cRight")[0].insertBefore(div,$("uR"));
		}
		else $("content").setStyle("margin-bottom",-sizeY);
	}
	//Fall 3
	if(pos=="pur")
	{
	  try{$("content2").parentNode.removeChild($("content2"));}
		catch(e){;}  
		$("uL").className="uL greenSmall";
		sizeL=$$(".cLeft")[0].getSize();
  	sizeR=$$(".cRight")[0].getSize();
		$("dImage").setStyle("width",sizeR.x-1);
		sizeR=$$(".cRight")[0].getSize();
    sizeY=sizeL.y-sizeR.y;
		if(sizeY>0) $("dImage").setStyle("margin-top",sizeY);
		else $("content").setStyle("margin-bottom",-sizeY);
		$("uR").className="uR gray";
	}
	//Fall 4
	if(pos=="pnone")
	{
  	
		$("uL").className="uL graySmall";
		sizeL=$$(".cLeft")[0].getSize();
  	sizeR=$$(".cRight")[0].getSize();
		sizeUR=$("uR").getSize();
		sizeY=sizeL.y-sizeR.y+sizeUR.y;
		if(sizeY<0) 
		{
  		$("content").setStyle("height",390);
  		sameHigh();
		}
		$("uR").setStyle("height",sizeY);
		$("uR").className="uR green";
		
		/*try
		{
    	nN=$("oL").getElements("h1")[0].firstChild.nodeName;
			if(nN=="Contact" || nN =="Sie erreichen uns")
			{
			$("uL").style.backgroundColor="#89A426";
			$("uR").style.borderBottom="65px solid #565B5F";
			//alert($("uR").getSize().y-130);
			$("uR").style.height=$("uR").getSize().y-130+"px";
			}
		}
		catch(e){;}*/
		try
		{
  		$("thy").firstChild.firstChild.nodeName;
			$("uR").id="xxx";//style.height="320px";
		}
		catch(e){;}
	}
	//alert(pos);
}

function setDivsSameHigh(elids)
{
  height=0;
	for(i=0;i<elids.length;i++)
  {
    size=$(elids[i]).getSize();
		height=(size.y>height)?size.y:height;
  }
	for(i=0;i<elids.length;i++)
  {
    pt=$(elids[i]).getStyle("padding-top").toInt();
		pb=$(elids[i]).getStyle("padding-bottom").toInt();
		mt=$(elids[i]).getStyle("margin-top").toInt();
		mb=$(elids[i]).getStyle("margin-bottom").toInt();
		
		$(elids[i]).setStyle("height",height-pt-pb-mt-mb);
  }
}
function setToBottom(elid)
{
  H=$(elid).parentNode.getStyle("height").toInt();
	$(elid).parentNode.setStyle("height","auto");
	prevH=$(elid).parentNode.getStyle("height").toInt();
	$(elid).parentNode.setStyle("height",H);
	maxH=H-prevH;
	if(top<0 || top==NaN) maxH=0;
	$(elid).setStyle("top",maxH);
	$(elid).setStyle("position","relative");
}


/*SLIDE SHOW*/
var SLIDE_STEPS=4;
var SLIDE_SPEED=80;
var SLIDE_PAUSE=5000;

function initSlideShow(elId)
{
	//alert($(elId).nodeName.toLowerCase());
	try{if($(elId).nodeName.toLowerCase()!="div") return false;}
	catch(e){return;}
	setTimeout("slideIt('"+elId+"',100)",2000);
}

function slideIt(elId,opacity)
{
  imgs=$(elId).getElementsByTagName("img");
	if(opacity<101 && opacity>=0)
	{
  	try{imgs[imgs.length-1].style.filter="Alpha(opacity="+opacity+")";} catch(e){;}
		imgs[imgs.length-1].style.opacity=(opacity/100);
		opacity=opacity-SLIDE_STEPS;
		setTimeout("slideIt('"+elId+"',"+opacity+")",SLIDE_SPEED);
	}
	else
	{
  	img=document.getElementById(elId).removeChild(imgs[imgs.length-1]);
		try{img.style.filter="Alpha(opacity=100)";} catch(e){;}
		img.style.opacity=1;
		
		document.getElementById(elId).insertBefore(img,imgs[0]);
		setTimeout("slideIt('"+elId+"',100)",SLIDE_PAUSE);
	}
}

/*NAVIGATION*/
function normal(img)
{
	if(img.className=="aktiv") n="h";
  else n="n";
  img.src=img.src.substring(0,img.src.length-5)+n+".gif";
}

function hover(img)
{
  img.src=img.src.substring(0,img.src.length-5)+"h.gif";
}


function onloadNav(elId)
{
  //$("logo");
	//alert(Math.round(($(document.body).getSize().x-$("logo").getSize().x)/2));
	//$("logo").setStyle("left",Math.round(($(document.body).getSize().x-$("logo").getSize().x)/2)-17);
	
	imgs=$(elId).getElements("img");
  for(i=0;i<imgs.length;i++) 
  {
    imgs[i].onmouseout=function(e) {normal( this );};
    imgs[i].onmouseover=function(e) {hover( this );};  
    initNav(imgs[i]);
  }
}

function initNav(img)
{
nimg=new Image();
  nimg.src=img.src.substring(0,img.src.length-5)+"h.gif";
  nimg.style.display="none";
  $(document.body).appendChild(nimg);
  normal(img);
}


function lookRef(id)
{
  $("content2").innerHTML="";
	if($("dImage2")!=null) $("uL").removeChild($("dImage2"));
	cN=$("ref"+id).childNodes;
	$("uL").setStyle("height","");
	$("uR").setStyle("height","auto");
	if($("uL").childNodes.length==0)
	{
  	imgg=new Image();
  	imgg.id="dImage";
  	imgg.className="pul";
  	$("uL").appendChild(imgg);
	}
	$("dImage").setStyle("width","auto");
	for(i=0;i<cN.length;i++) $("content2").appendChild(cN[i].cloneNode(true));
	
	$("dImage").src=$("refImg"+id).src;
	if($("refImg"+id).getStyle("width").toInt()==1) refStandard=true;
	else refStandard=false;
	$("dImage").alt=$("refImg"+id).alt;
	$("dImage").title=$("refImg"+id).title;
	$("content").setStyle("margin-bottom",0);
	if($("refImg"+id).getStyle("width").toInt()==1) 
	{
	$("uL").setStyle("height","1px");
	//alert("j");
	}
	else $("uL").setStyle("height","auto");
	//return;
	 
	setDivsSameHigh(Array("uL","uR"));
	sameHigh();
	$("print").href="index.php?id="+id+"&action=print";
	window.scrollTo(0, 1000);
}

function printIt()
{
els=new Array("oL","uL","uR");
els.each(function(it,ind)
{
  //$(it).style.backgroundColor="#fff";
  //$(it).style.color="#000";
  $(it).style.margin="0px";
  $(it).style.padding="10px";
  //$(it).style.float="none";
  $(it).style.width="500px";
  if(mapsIsLoaded!=true && it!="uR") $(it).style.height="auto";
	
  $(it).style.border="0";
	$(it).className="t";
	//itd=$(it).childNodes[0].id;
	//if(itd=="dImage" || itd=="dImage2") 
	its=$(it).parentNode.removeChild($(it));
  $(document.body).appendChild(its);
});
try
{
$("dImage").style.display="none";
$("dImage2").style.display="none";
}
catch(e) {;}
$$(".content").each(function(it,ind){  
it.style.color="#000"; 
it.style.padding="0";
it.style.margin="0";
isPrint=true;
});

//logo=$("logo").removeChild($("logo").getElements("img")[0];

$("main").style.display="none";
$(document.body).style.backgroundColor="#fff";

table=document.createElement("table");
table.style.margin="10px";
table.innerHTML="<tbody><tr><td style='font-size: 14pt; font-weight: bold; vertical-align: middle; width: 410px'>Pipline Ingenieuer Team GmbH</td><td><img src='assets/templates/logoRAW.gif' alt='Logo'></td></tr></tbody>";

$(document.body).insertBefore(table,$(document.body).firstChild)
}
