var curImage;
var sLan;
var iNewsCount = 0;
var iCurNewsCount = 1;

url = document.location.href;
sLan = url.substr(url.indexOf('www.eqd.')+8,2);

function init()
{
	objNews = document.getElementById('newsslide');
	if(objNews)
	{
		objNews.style.marginLeft = '0px';
		iNewsCount = objNews.getElementsByTagName('div').length;

		if(iNewsCount > 1)
			window.setInterval("slideNews()", 8000);	
	}	

	return;
	// Framesperre
	if(parent.frames[0])
	{	
		topLoc = parent.frames[0].document.location.href;

		if(topLoc != 'about:blank' && topLoc.indexOf('http://www.eqd.') == -1)
		{
			parent.frames.location.href = document.location.href;
		}
	}	
}

function slideNews()
{
	objNews = document.getElementById('newsslide');
//	marginLeft = objNews.style.marginLeft;
//	marginLeft = marginLeft.substr(0,marginLeft.indexOf('px'));

	var iWidth = -145;

	iCount = 0;

	for(i = (iCurNewsCount-1) * (iWidth); i > iCurNewsCount * (iWidth); i-= 10)
	{
		window.setTimeout('doSlide(\''+i+'\')' , iCount*30);
		iCount++;
	}

	window.setTimeout('doSlide(\''+iCurNewsCount * (iWidth)+'\')' , iCount*30);


//	objNews.style.marginLeft = iCurNewsCount * (iWidth) + 'px';

	iCurNewsCount++;

	if(iCurNewsCount >= iNewsCount)
		iCurNewsCount = 0;
}

function doSlide(iMargin)
{
	objNews = document.getElementById('newsslide');
	objNews.style.marginLeft = iMargin + 'px';
}

function mailTo(email,subject) 
{
	var sMailto = 'mailto:'+email+'@eqd.'+sLan;
	if(subject)
		sMailto += '?subject='+subject;

	sMailto = sMailto.replace(/ä/g, "%E4");
	sMailto = sMailto.replace(/ö/g, "%F6");

	document.location.href = sMailto;
}

function setWait()
{
	document.getElementById('bestellen').style.display = 'none';
	document.getElementById('ok').style.display = 'inline';
}

function goTo(sUrl)
{
	document.location.href = sUrl;
}

function setHeight(idToSet, iHeight)
{
	iHeight *= 3;
	document.getElementById(idToSet).style.height = iHeight;
}

function hideImg()
{
	curImage.style.display = 'none';
	document.getElementById('overlay').style.display = 'none';
	document.getElementById('xbutton').style.display = 'none';
}

function checkImgOver(idSearch,path)
{
	imgObj = document.getElementById(idSearch);
	imgSrc = imgObj.src;

	if(imgObj.className == 'no')
		return;


	
	var sFind = 'pictures/';

	// vielleicht als background versteckt
	if(imgSrc.indexOf('dot.gif') != -1)
	{
		objParent = imgObj.parentNode;
	//	imgSrc = objParent.style.getAttribute("background",false);

		for(i=0; objParent.attributes[i] && objParent.attributes[i].nodeValue; i++)
		{
			if(objParent.attributes[i].nodeValue.indexOf('url') != -1)
				imgSrc = objParent.attributes[i].nodeValue;		
		}

		if(imgSrc.indexOf('dot.gif') != -1)
			imgSrc = objParent.style.getAttribute("background",false);
		
	}

	
	if(imgSrc.indexOf(sFind) != -1 || 1==1)
	{
		// sImgName = imgSrc.slice(imgSrc.indexOf(sFind) + sFind.length);
		//sNewImgName = sImgName.slice(0,8);
		//sNewImgName += 'F.jpg';
		sNewImgName = path;
		
		// Objekt zuerst suchen ob es schon da ist
		objSearchImg = document.getElementById(sNewImgName);
		if(objSearchImg)
		{
			if(objSearchImg.style.display == 'none')
				objSearchImg.style.display = 'inline';							
			else
			{	objSearchImg.style.display = 'none';
				document.getElementById('overlay').style.display = 'none';
				document.getElementById('xbutton').style.display = 'none';
				return;
			}
				
			newImage = objSearchImg;
		}
		else
		{		
			newImage = document.createElement("img");
			newImage.src = path;
			if(newImage.height > 400)
			{	
				newImage.style.height = '400px';
				newImage.style.width = newImage.width/newImage.height*400+'px';
			}

			newImage.setAttribute('id',sNewImgName);
			newImage.style.position = 'absolute';
			newImage.style.zIndex = '50';
			newImage.style.border = '4px solid white';
			newImage.style.borderTopWidth = '40px';			
//			newImage.style.display = 'none';
		}
				
		iYScroll = getScrollXY();
/*
		aPos = findPos(imgObj);
		
		aX = new Array(aPos[0], aPos[0] + imgObj.offsetWidth);
		aY = new Array(aPos[1], aPos[1] + imgObj.offsetHeight);		
		
		iPixelLeft = aX[0];
		iPixelRight = screen.availWidth - aX[1];
	
		iPixelTop = aY[0] - iYScroll;
		iPixelBottom = screen.availHeight + iYScroll - aY[1];	

		iPosX = iPixelLeft > iPixelRight ? iPixelLeft : aX[1] - newImage.width;
		iPosY = iPixelTop > iPixelBottom ? aY[0] - newImage.height-10: aY[1]+10;
*/
		document.body.appendChild(newImage);	

		newImage = document.getElementById(sNewImgName);			

		iImageWidth = 490;
		iImageWidth = newImage.width;

		iImageHeight = newImage.height;
		if(iImageHeight < 100)
			iImageHeight = 320;


		iPosX = (document.body.clientWidth - iImageWidth ) / 2;
		iPosY = ((document.body.clientHeight- iImageHeight) / 2) + iYScroll;	

		if(!document.all)
			iPosY -= 200;

		if(iPosY < 0)
			iPosY = 0;

		endElem = document.getElementById('stopfloat');
		if(endElem)
		{
			endPos = findPos(endElem);
			iPosY = endPos[1];
		}
	

		newImage.style.top = iPosY+'px';
		newImage.style.left = iPosX+'px';

		lastDot = findPos(document.getElementById('lastdot'));
		
		objOverlay = document.getElementById('overlay');
		if(document.body.offsetHeight < lastDot[1])
			objOverlay.style.height = lastDot[1] + 5+'px';


		xButton = document.getElementById('xbutton');
		xButton.style.top = iPosY + 2 +'px';
		xButton.style.left = iPosX + 4 +'px';

		
		sTitle = path;
		while(sTitle.indexOf('/') != -1)
			sTitle = sTitle.slice(sTitle.indexOf('/') +1);

		setText('title',sTitle);

		document.getElementById('overlay').style.display = 'inline';
		xButton.style.display = 'inline';
	//	newImage.style.display = 'inline';			

		curImage = newImage;
	//	addEvent(newImage,'click',checkImgOut);
	//	newImage.addEventListener('click',checkImgOut,false);

		if (newImage.addEventListener) 
		{
			newImage.addEventListener( 'click', hideImg, false );
		} 
		else if (newImage.attachEvent) 
		{

			newImage.attachEvent( 'onclick', hideImg );
		}
	}	
}

function setText(id,text)
{
	if(document.all)
		document.getElementById(id).innerText = text;	
	else
		document.getElementById(id).textContent = text;
}

function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
			
		return [curleft,curtop];
	}
}

function checkImgOut(evt)
{
	imgObj = (evt.target) ? evt.target : evt.srcElement;
	checkImgOver(imgObj.src, imgObj.src);
}

function getScrollXY() 
{  

	var scrOfX = 0, scrOfY = 0;  

	if( typeof( window.pageYOffset ) == 'number' ) 
	{  
		//Netscape compliant  

		scrOfY = window.pageYOffset;  

		scrOfX = window.pageXOffset;  

	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{  
		//DOM compliant  

		scrOfY = document.body.scrollTop;  

		scrOfX = document.body.scrollLeft;  

	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{  
		//IE6 standards compliant mode  

		scrOfY = document.documentElement.scrollTop;  

		scrOfX = document.documentElement.scrollLeft;  

	}  

	return scrOfY;  

} 

function eraseSearch(searchBox) 
{
	if(searchBox.value == "Suchbegriff")
		searchBox.value = "";
	
}

function rebuildSearch(searchBox) 
{
	if(searchBox.value.length == 0)
		searchBox.value = "Suchbegriff";
}

function show(id)
{
	if(!document.getElementById(id))
		alert('ID '+id+' nicht gefunden');
	else
		document.getElementById(id).style.display = "inline";		
}

function hide(id)
{	
	document.getElementById(id).style.display = "none";
}
