////////////////////////////////////////////////////////////////////////////////////////
//
//	 Part for changing the images in the menus
//
////////////////////////////////////////////////////////////////////////////////////////

// toggle image (given is an img object)
function toggleImage(object,status){
	toggleImageSrc(object.name,status);
}
function toggleImage2(name,status){
	toggleImageSrc(name,status);
}
// toggle image (given is an img name)
var menuItemObj = new Object();

/**
* function to toggle image
* @param string name : image name with ending e.g. kontakt.jpg 
* @param int status : 1 for active, 0 for passiv 
*/
function toggleImageSrc(name,status){
	
	//name = (img.name == undefined) ?  img : img.name;
	// store the image source in an object
	if (menuItemObj[name]==undefined){
		menuItemObj[name] = new Object();
		menuItemObj[name]['imageSrc'] = document.images[name].src;
	}
	// get the suffix of the file name and the image name without suffix (which is also the name of the image tag)
	imageSrc = menuItemObj[name]['imageSrc'];
	
	var imagePathParts = imageSrc.split("/");
	var imageNameParts = imagePathParts[imagePathParts.length-1].split(".");
	var imageSuffix = imageNameParts[1];
	var imageName = imageNameParts[0];
	/* for IE 6: if the image is a png and there is a workaround to display it in IE 6, 
		the png is replaced by a blank.gif image and the png is put into the background.
		The result is that the image source is  the blank.gif and not the png anymore. #
		For that case it is checked if the imageName is 'blank' and if it is nothing should be done.
		Then there will be no image toggle.
	*/
	// start fix
	if (imageName == 'blank') return false;
	//end fix
	
	// check if the current image is an active one
	var bool_CurrentIsActiveImage = (imageName.search(/_a$/)!=-1) ? true : false;
	// remove the _a at the end if there is one (to get the image name independed of the status)
	//var name = imageName.replace(/_a$/,'');

	// remove the file-ending from the path 
	var imagePath = imageSrc.replace(/\..{1,4}$/,'');
	// remove the _a at the end if there is one
	imagePath = imagePath.replace(/_a$/,'');
			
	// set image path
	var activeImage = imagePath + "_a." + imageSuffix;
	var passivImage = imagePath + "." + imageSuffix;
				
	menuItemObj[name]['statusChecked'] = (menuItemObj[name]['statusChecked'] != undefined)? menuItemObj[name]['statusChecked'] : false;
	if(status == 1 && bool_CurrentIsActiveImage == true && menuItemObj[name]['statusChecked'] == false) {
		menuItemObj[name]['active'] = true;
	}
	else if (status == 1 && bool_CurrentIsActiveImage == false && menuItemObj[name]['statusChecked'] == false){
		menuItemObj[name]['active'] = false;
	}
	menuItemObj[name]['statusChecked'] = true;
	
	// set the correct image
	// toggle only images back from menuitems that are not active
	if (status!=1 && menuItemObj[name]['active'] == false){
		imageName = passivImage;
	}
	else{
		imageName = activeImage;
	}
	theImage = new Image(); 
	theImage.src = imageName;
	document.images[name].src = theImage.src;
	
}
/** function to open a url in a popup
 **/
function openWindow (url,width,height) {
	fenster = window.open(url, "Win", "width="+width+",height="+height+",status=yes,scrollbars=yes,resizable=yes");
	fenster.focus();
}








