loaded = "false";
browser = getBrowser();

window.onresize = checkNavSize;
if(browser[0] == "Internet Explorer" && browser[1] < 7) {
window.onscroll = ieScroll;
}

function siteLoad() {
	loaded = "true";
	checkNavSize();
	}


function checkNavSize(){
	if(loaded == "true") {
		var dnc = false;
		if(browser[0] == "Internet Explorer" && browser[1] < 7) {dnc = true;}
		if(dnc == false) {
	divScreen = document.getElementById('screen');
	divNavigation = document.getElementById('navigation');
	if(divNavigation.offsetHeight < divScreen.offsetHeight) {
		divNavigation.style.position = "fixed";
		} else {
		divNavigation.style.position = "absolute";	
			}
	}}}

function openPic(img) {
if(img) {
try {
 	if(document.getElementById('shadow')) {
 		throw "true";
 		} else {
 		throw "false";
 			}
  } catch (e) {
    if (e == "true") {
      createNew = "false";
    } else {
      createNew = "true";
    }
  }

if(createNew == "true") {
	var html = document.getElementById('html');
		
	var divScreen = document.getElementById('body');
	var newDivShadow = document.createElement('div');	
	var newIdShadow = document.createAttribute('id');
		
	newIdShadow.nodeValue = "shadow";
	newDivShadow.setAttributeNode(newIdShadow);
	divScreen.appendChild(newDivShadow);
	
	var divShadow = document.createElement('div');
	var	divShadowId = document.createAttribute('id');
		divShadowId.nodeValue = 'image';
		divShadow.setAttributeNode(divShadowId);
		divShadow.onclick = closePic;
	divShadow.innerHTML = divShadow.innerHTML+'<img src="./artikelimg/gross/'+img+'" alt="Motoforce '+ImgAltProduct+' - '+img+'" title="Motoforce '+ImgAltProduct+' - '+img+'" id="productImage" /><p id="copyright">'+clicktoclose+'<br>'+imgCopyright+'</p>';
	
	document.getElementsByTagName('body')[0].appendChild(divShadow);
	
	if(browser[0] == "Internet Explorer" && browser[1] < 7) {
		var html = document.getElementById('html');
		
		changeStyle('shadow',html.scrollTop,'','absolute');
		changeStyle('image',html.scrollTop+10,'','absolute');
		

		changeStyle2('itemChoose','display:none');
			
		}
		
			
	if(browser[0] == "Internet Explorer" && browser[1] > 6) {
		changeStyle2('shadow','position:fixed');
		}
		
	} else {
		
		var html = document.getElementById('html');
	  	
		var divImgProduct = document.getElementById('productImage');
		var newImgSrc = document.createAttribute('src');
		var newImgId = document.createAttribute('id');
		var newImgAlt = document.createAttribute('alt');
		var newImgTitle = document.createAttribute('title');
				
		newImgSrc.nodeValue = "./artikelimg/gross/"+img;
		newImgId.nodeValue = "productImage";
		newImgAlt.nodeValue = "Motoforce Produkt - "+img;
		newImgTitle.nodeValue = "Motoforce Produkt - "+img;
				
		divImgProduct.setAttributeNode(newImgSrc);
		divImgProduct.setAttributeNode(newImgId);
		divImgProduct.setAttributeNode(newImgAlt);
		divImgProduct.setAttributeNode(newImgTitle);
				
		
		var divShadow = document.getElementById('shadow').style.display = "block";
		var divImage = document.getElementById('image').style.display = "block";
		
			if(browser[0] == "Internet Explorer" && browser[1] < 7) {
		var html = document.getElementById('html');
		
		
		changeStyle2('itemChoose','display:none');
		}
			}
	 }
}

function closePic() {
	document.getElementById('shadow').style.display = "none";
	document.getElementById('productImage').src = "./Bilder/html/px.gif";	
	document.getElementById('image').style.display = "none";
	
	if(browser[0] == "Internet Explorer" && browser[1] < 7) {
	changeStyle2('itemChoose','display:block');}
	}

function changeMail() {
	var mail = document.getElementById('eMail');
	mail.href = "mailto:info@attivo.de";
	mail.innerHTML = "info@attivo.de";
	}
	

function fade(nopacity,id,step,standardOP) {
var obj = document.getElementById(id);
if(standardOP) {fst = standardOP;} else {fst = "1";}
if(!obj.style.opacity || standardOP) {setOpacity(id,fst,fst,false,false,"false");}
if(!step) {step = "0.05";}
actopacity = obj.style.opacity;
if(nopacity != actopacity) {
if(nopacity < actopacity) {
	eval("fadeFunc"+id+" = doFade(id,actopacity,'-"+step+"',nopacity);");
	} else {
	eval("fadeFunc"+id+" = doFade(id,actopacity,'"+step+"',nopacity);");
}} else {
	eval("fadeFunc"+id+" = 'fin';");
	}

}

function doFade(id,opacity, step,nopacity) {
	if(cCalc = step.match(/^-/)) {var pom = "-";} else {var pom = "+";}
	step = step.replace(/^\+/, "");
	step = step.replace(/^-/, "");
	eval("sopacity = "+opacity+" "+pom+" "+step+";");
	return setOpacity(id,sopacity,nopacity,pom,step);
	}

function setOpacity(id,opacity,nopacity,pom,step,fader) {
  if(fader !== "false") {if(pom == "-") {if(opacity < nopacity) {return "fin";}} 
 	if(pom == "+") {if(opacity > nopacity) {return "fin";}}}
 		
  obj = document.getElementById(id);
	obj.style.filter = "alpha(opacity:"+opacity*100+")";
	obj.style.KHTMLOpacity = opacity;
	obj.style.MozOpacity = opacity;
	obj.style.opacity = opacity;
	
	if(fader !== "false") {
	window.setTimeout("fade(\""+nopacity+"\",\""+id+"\",\""+step+"\")", 10);
		}
}

function changeStyle(id,vtop,vleft,position,display) {
	var cpElement = document.getElementById(id);
	cpElement.style.top = vtop+"px";
	if(vleft) {cpElement.style.left = vleft+"px";}
	if(position) {cpElement.style.position = position;}
	if(display) {cpElement.style.display = diyplay;}
	}
	
function changeStyle2(id,styles) {
	if(obj = document.getElementById(id)) {
	var styles = styles.split(';');
		for(i=0;i<styles.length;i++) {
		var styleAt = styles[i].split(':');
		if(styleAt[1]) {
		eval("obj.style."+styleAt[0]+" = '"+styleAt[1]+"';");
		}
		}
	}
	}

function ieScroll() {
	if(document.getElementById('shadow')) {
	var html = document.getElementById('html');
	changeStyle('shadow',html.scrollTop);
	changeStyle('image',html.scrollTop+10);
}
	}

function getBrowser()
{
	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring;
	var browser,version;
	
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	
	if (!version) version = detect.charAt(place + thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
	
	function checkIt(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}
	
	return new Array(browser, version);
}
