var actHref;

var myImages = new Array();

function preloadImages() {
   for (i=0;i<preloadImages.arguments.length;i++) {
       myImages[i] = new Image();
       myImages[i].src = preloadImages.arguments[i];
   }
}

function extractStuff(theString,theStart,theEnd) {
	stringArray = theString.split(theStart);
    arrayLength = stringArray.length - 1; 
    var thisFilename = stringArray[arrayLength];
    
    filenameArray = thisFilename.split(theEnd);
    thisFilename = filenameArray[0];
    
    return(thisFilename);
}

function extractFilename() {
    var thisUrl = window.location.href;    
    thisFilename = extractStuff(thisUrl,"/",".");
    
    if(!thisFilename) {
        thisFilename = "index";
    }
    
    return(thisFilename);
}

function extractImgName(theElement) {
	theFilename = extractStuff(theElement.src,"/","_");
	return(theFilename);
}

function cleanHref() {
	windowHref = window.location.href;
	if(windowHref.indexOf(".php") > -1)	{
		windowHrefArray = windowHref.split(".php");
		windowHref = windowHrefArray[0] + ".php";
	}
	else {
		windowHref += "index.php";
	}
	
	return(windowHref);	
}


function nav1over(theElement) {
	theImgName = extractImgName(theElement);
	//alert(extractStuff(theElement.src,"/",".jpg"));
	//theImgPath = theElement.src.replace(extractStuff(theElement.src,"/",".jpg"), "");
	//theImgPath = theImgPath.replace(".jpg","");
	//alert(theImgPath);
	imgPathArray = theElement.src.split("/"+theImgName);
	theImgPath = imgPathArray[0];
	
	//theElement.src = "images/nav/"+theImgName+"_act_"+lang+".jpg";
	theElement.src = theImgPath+"/"+theImgName+"_act_"+lang+".jpg";

	// subnavi einblenden	
	toggleSubnav("block",theElement);
}

function nav1out(theElement) {
	if(theElement.parentNode.href != cleanHref() && theElement.parentNode.href != actHref) {
		theImgName = extractImgName(theElement);
		
		/*theImgPath = theElement.src.replace(extractStuff(theElement.src,"/",".jpg"), "");
		theImgPath = theImgPath.replace(".jpg","");	*/
		imgPathArray = theElement.src.split("/"+theImgName);
		theImgPath = imgPathArray[0];
		
		//theElement.src =  "images/nav/"+theImgName+"_pas_"+lang+".jpg";
		theElement.src = theImgPath+"/"+theImgName+"_pas_"+lang+".jpg";
	}
		
	// subnavi ausblenden
	toggleSubnav("none",theElement);
}


function toggleSubnav(displayParam,theElement) {
	var images = document.getElementsByTagName('img');
	var countIndex = 1;
	
	for(var i = 0; tag = images[i]; ++i) {
   	    if(tag.className == 'navbutton') {  
			if(images[i] == theElement && document.getElementById("subnav"+countIndex)) {
				document.getElementById("subnav"+countIndex).style.display = displayParam;
		/*		if(displayParam == "none") {
					document.getElementById("subnav"+countIndex).style.zIndex = "1"; // ie 6
				}
				else {
					document.getElementById("subnav"+countIndex).style.zIndex = "88"; // ie 6
				}				*/
			}
			countIndex++;
		}
	}
}


function subOver(theElement) {
	theElement.style.display = "block";
}

function subOut(theElement) {
	theElement.style.display = "none";
	//theElement.style.zIndex = "1"; // ie 6
}


function makeNavActive() {
	//navi aktivieren, wenn die href des aktuellen navi-punkts der window.location.href entspricht
	windowHref = cleanHref();
	var isActive = false;
	nav1images = new Array();
	
	var images = document.getElementsByTagName('img');
    
    for(var i = 0; tag = images[i]; ++i) {
   	    if(tag.className == 'navbutton') {   	       	    
   	    	if(images[i].parentNode.href == windowHref) {				
   	    		images[i].src = "images/nav/"+extractImgName(images[i])+"_act_"+lang+".jpg";
   	    		isActive = true;
   	    	}
   	    	
   	    	nav1images.push(images[i]);
   	    }
    }
    
    if(!isActive) {
		makeActiveSub(windowHref,nav1images);    
    }
    
    //document.getElementById("navibar").style = "none";
    document.getElementById("navibar").style.zIndex = "100";        
}

function makeActiveSub(windowHref,nav1images) {	
	var links = document.getElementsByTagName('a');

	for(var i = 0; tag = links[i]; ++i) {
		if(tag.className == 'nav2link') {
			if(links[i].href == windowHref) {			
				// nav1 aktivieren - dazu muss die id des parent-parent elements ausgelesen werden
				divId = links[i].parentNode.parentNode.parentNode.id;
				divIndex = divId.substr(6);
				nav1images[divIndex-1].src = "images/nav/"+extractImgName(nav1images[divIndex-1])+"_act_"+lang+".jpg";
				actHref = nav1images[divIndex-1].parentNode.href;
			}
		}
	}
}

// impressionen vergroessern:

function enlargeMe(theFoto) {
	if(typeof imgwin != 'undefined' && !imgwin.closed) {
		imgwin.close();
	}	

	imgwin = window.open(theFoto, 'imgwindow', 'width=1000,height=900, top=25, left=25');
	imgwin.focus();	
	setTimeout("checkAndResize()",650);
}

function checkAndResize() {
	if(imgwin.document.images[0]) {
		hoehe = imgwin.document.images[0].height + 20;
		breite = imgwin.document.images[0].width + 20;
			
		hoehe2 = hoehe+90;
	    breite2 = breite+30;
		
		if (window.innerHeight) {
			imgwin.resizeTo(breite2,hoehe2);    //fuer opera
			imgwin.innerWidth = breite;     //mozilla
			imgwin.innerHeight = hoehe;
		}
		else {
			imgwin.resizeTo(breite2,hoehe2); //ie
		}				
	}
	else {
		setTimeout("checkAndResize()",500);
	}
}
