////////////////////////////////////////////////
/////////////// globale Variablen //////////////
////////////////////////////////////////////////

//Console
c = null;
// URL, wird vom Pageloader geladen
url = "";
loadedHash = "";

//Image Preloader
ip = null;


// Browsererkennung für den Ajax-Zurück-Button-
// Hack mit iframe
window.ActiveXObject ? ie = true : ie = false;
iframeTitle = "";

// Browserdetect für Modal
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
getBrowserInfo();


var yPos4IE = 0;

// Seitenstatus-Variablen
statusSub = "";
statusSubsub = "";
statusContent = "";
statusDetail = "";
oldstatusSub = "";
oldstatusSubsub = "";
oldstatusContent = "";
oldstatusDetail = "";

////////////////////////////////////////////////
//////////////////// ONLOAD ////////////////////
////////////////////////////////////////////////
function pngfix(icons) {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	var showMyDetails = false;
	if ((version >= 5.5) && (document.body.filters)) 
	{
		var alledetailicons = icons;
		for(var i=0; i<alledetailicons.length; i++)
		{
			var img = alledetailicons[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				showMyDetails = true;
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:block; overflow:hidden;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
};

window.onload = function() {
//addLightboxMarkup();

	// Console starten
	initConsole();

	initLinks();

	//Seitenaufruf (Bookmark)
	//hashWatcher();
	//Überwachung für Bookmark und Back-Button starten
	//window.setInterval("hashWatcher();", 500);

	//Behaviour
	//Behaviour.apply();
	
	if(document.getElementById("detailicons")) {
		var elemente = document.getElementById("detailicons").getElementsByTagName("img");
		pngfix(elemente);
		
		var detailiconsDiv = document.getElementById("detailicons");
		detailiconsDiv.style.visibility = "visible";
		detailiconsDiv.style.cursor = "pointer";
		
		if(document.getElementById("kuechenbild")) {
			var bild = document.getElementById("kuechenbild");
			//bild.style.cursor = "pointer";
			var filename = bild.src;
			//var valid = new ModalWindow(bild, "/modal_zoom.php?file="+filename, true);
		};
	};
	if(document.getElementById("png")) {
		var elemente = document.getElementsByTagName("img");
		pngfix(elemente);
		
	};
	
	addLightboxMarkup();
	//new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "../includes/ajax/autocomplete.php", {});
	
	
	// Tooltips init
	$$('a[rel="tooltip"]').each( function(link) {
		new Tooltip(link, {mouseFollow: false});
	});

	
	
};


////////////////////////////////////////////////
/////////////// Console-Objekt /////////////////
////////////////////////////////////////////////

Console = function(el) {
this.el = document.getElementById(el);
	this.clear = function() {
		if(this.el) {
			while(this.el.firstChild) {
			this.el.removeChild(this.el.firstChild);
			};
		};
	};
	this.log = function(message) {
		if(this.el) {
		  var domEl = toDOMElement(message);
		  this.el.appendChild(domEl);
		  //new Insertion.Top(this.el, "<div>"+message+"</div>");
		}
	};
}

toDOMElement = function(obj) {
	var result = null;
	var txtNode = document.createTextNode(String(obj));
	var wrapper = document.createElement('div');
	wrapper.appendChild(txtNode);

	result = wrapper;
	return result;
}

initConsole = function () {
	c = new Console("consoleLog");
	if(ie) {
		c.log("IE DETECTED!");
	} else {
		c.log("NON-IE DETECTED!");
	};
}



////////////////////////////////////////////////
/////////////// ImagePreloader /////////////////
////////////////////////////////////////////////

function ImagePreloader(image, frontenbutton, bgImage) {

	this.bildobjekt = new Image();
	this.bildobjekt.onload = function() {
		bilderTauschen(image, frontenbutton, bgImage);
	};
	this.bildobjekt.src = image;
}

function bilderTauschen(neuerbildname, ankersI, bgImage) {
	setTimeout(function() {
		var altesBild = $('kuechenbild');
		altesBild.src = neuerbildname;
		ankersI.style.backgroundImage = bgImage;
	}, 500)
}


////////////////////////////////////////////////
////////////////// initlinks ///////////////////
////////////////////////////////////////////////

function initLinks() {

	var ankers = $$('a');
	var ankersAnzahl = ankers.length;
	for (i=0; i < ankersAnzahl; i++) {

		if (ankers[i].className == "frontenButton") {
			ankers[i].onclick = function() {
				if (!document.getElementById('frontIsLoading')  &&  this.style.backgroundImage != "url(/bilder/ajaxLoading_fronten.gif)") {
					//alert(this.style.backgroundImage)
					// neuen Bildnamen bauen
					var pnr = $('getpnr').innerHTML;
					var idname = $('getidname').innerHTML;
					var frontname = this.id;
					var neuerbildname = pnr + "_" + idname + "_" + frontname + ".jpg";
					//alert(neuerbildname);
					// neuen Bild-Tag einfügen

					var pfad = "/bilder/ek/kuechen/view/";
					//this.innerHTML = "frontIsLoading";

					// Preisbeispielbild aktualisieren
					if(document.getElementById('preisgruppe'))
					{
						pglink = document.getElementById('preisgruppe');
						if(this.rel && this.rel != '')
						{
							pglink.rel = this.rel;
							pglink.style.display = 'block';
						}
						else
						{
							pglink.style.display = 'none';
						}
					}
					
					// Küchen-Detailbild aktualisieren
						if(document.getElementById('kuechenbild'))
						{
							img = document.getElementById('kuechenbild');
							src = 'http://62.146.110.67/bilder/ek/kuechen/zoom/'+neuerbildname;
							
							
							//alert(src + "\n" + detail_width + "\n" + detail_height );
							Event.stopObserving('kuechenbild');
							valid = new lightbox(img, "/modal_ek_zoom.php?img="+src, detail_width, detail_height);
						};
					
					
					originalBGimage = this.style.backgroundImage;
					this.style.backgroundImage = "url(/bilder/ajaxLoading_fronten.gif)";

					ip = new ImagePreloader(pfad+neuerbildname, this, originalBGimage);

				}
				return false;
			}
		};
				
		if(ankers[i].id == "toggleBesch") {
			ankers[i].onclick = function() {
				var beschreibungsDiv = $('kuecheBeschreibung');
				if(beschreibungsDiv.className == "open") {
					this.innerHTML = "Beschreibung einblenden";
					beschreibungsDiv.className = "closed";
					$('kuecheBeschreibung').morph('top:331px; width:616px; height:51px; opacity:0.7; -moz-opacity:0.7; -khtml-opacity:0.7; filter:alpha(opacity=70);');
				} else {
					this.innerHTML = "Beschreibung ausblenden";
					$('kuecheBeschreibung').morph('top:141px; width:616px; height:240px; opacity:0.9; -moz-opacity:0.9; -khtml-opacity:0.9; filter:alpha(opacity=90);');
					beschreibungsDiv.className = "open";
				}
				return false;
			}
		}
		
		if(ankers[i].id == "optionFront" || ankers[i].id == "optionDetail")
		{
			ankers[i].onclick = switchAddons;
		}
		if(ankers[i].className == "closeAddon")
		{
			ankers[i].onclick = closeSingleAddon;
		}
		
		if(ankers[i].id == "optionKKBestellen" || ankers[i].id == "optionEinzelteile") {
			ankers[i].onclick = function() {
				$('footerContainer').style.display = "none";
				new Effect.toggle('bestellen_bloecke', 'blind', {
					afterFinish: function() {
						$('footerContainer').style.display = "block";
						helpIE();
					}
				});
				
				return false;
			}
		}
		if(ankers[i].id == "edetail3") {
			valid = new lightbox(ankers[i], ankers[i].href, 885, 475);
		}
		
		
		if(ankers[i].id == "optionSparsets1") {
			valid = new lightbox(ankers[i], ankers[i].href, 772, 263);
		}
		if(ankers[i].id == "optionSparsets2") {
			valid = new lightbox(ankers[i], ankers[i].href, 772, 484);
		}
		if(ankers[i].id == "optionKKDetail") {
			valid = new lightbox(ankers[i], ankers[i].href, 885, 475);
		}
		if(ankers[i].id == "egereat_detail" || ankers[i].id == "egereat_kf_detail" || ankers[i].className == "kompakt_zubehoer")
		{
			var url = ankers[i].href;
			var teile = url.split("/");
			var spalten = Number(teile[teile.length-1].substr(0,1));
			switch(spalten)
			{
				case 1:		var breite = 350; break;	
				case 2:		var breite = 595; break;	
				case 3:		var breite = 885; break;	
				default:	var breite = false; break;	
			}
			if(breite)
			{
				valid = new lightbox(ankers[i], ankers[i].href, breite, 480);
			}
		}
		if(ankers[i].id == "optionKatalogHaushalt") {
			valid = new lightbox(ankers[i], ankers[i].href, 784, 447);
		}
		if(ankers[i].id == "optionPlaneraufrufe") {
			valid = new lightbox(ankers[i], ankers[i].href, 995, 625);
		}
		if(ankers[i].id != "pcvideo" && (ankers[i].className == "kuechendetail" || ankers[i].className == "detailicon"))
		{
			valid = new lightbox(ankers[i], "/modal_details.php?id="+ankers[i].rel, 770, 390);
		}
		if(ankers[i].id == "preisgruppe") {
			valid = new lightbox(ankers[i], "/preisgruppen.php?img="+ankers[i].rel, 880, 525);
		}
		if(ankers[i].id == "pcvideo")
		{
			ankers[i].onclick = function() {
				open_katalog(this.href, 500, 380);
				return false;
			};
		}


	};
	
	
	// Mouseovers für Warenkorb
	
	if(document.getElementById("wk")) {
		
		var inputs = document.getElementsByTagName("input");
		var inputsAnzahl = inputs.length;
		for(i=0; i<inputsAnzahl; i++) {
			if(inputs[i].name == "loeschen") {
				inputs[i].onmouseout = function() {
					this.src = "/bilder/wk/btn_loeschen_normal.gif";
				};
				inputs[i].onmouseover = function() {
					this.src = "/bilder/wk/btn_loeschen_over.gif";
				};
			};
			if(inputs[i].name == "aendern") {
				inputs[i].onmouseout = function() {
					var inputfeld = $(this.parentNode).firstDescendant();
					inputfeld.style.backgroundImage = "url(/bilder/wk/input_aendern_normal.gif)";
					this.src = "/bilder/wk/button_aendern_normal.gif";
				};
				inputs[i].onmouseover = function() {
					var inputfeld = $(this.parentNode).firstDescendant();
					inputfeld.style.backgroundImage = "url(/bilder/wk/input_aendern_over.gif)";
					this.src = "/bilder/wk/button_aendern_over.gif";
				};
			};
			if(inputs[i].name == "absenden") {
				inputs[i].onmouseout = function() {
					this.src = "/bilder/wk/btn_absenden_normal.gif";
				};
				inputs[i].onmouseover = function() {
					this.src = "/bilder/wk/btn_absenden_over.gif";
				};
			};
		};
		
	};
	
	
	//helpIE();
	initMainMenue();
	initSubs();
	return false;

};
function switchAddons()
{
	if(this.id == "optionFront")
	{
		var einblenden = $("addons_fronten");
		var ausblenden = $("addons_details");
	}
	else
	{
		var einblenden = $("addons_details");
		var ausblenden = $("addons_fronten");
	}
	
	if(einblenden.style.display != "block")
	{
		deactivateEKButtons();
		
		$('footerContainer').style.display = "none"; // IE6
		
		if(einblenden.style.display == "none" && ausblenden.style.display == "none")
		{
			new Effect.toggle(einblenden, 'blind', {
				afterFinish: function(){
					helpIE();
					activateEKButtons();
					einblenden.style.display = "block";
					ausblenden.style.display = "none";
				}
			});
		}
		else
		{
			new Effect.toggle(ausblenden, 'blind', {
				afterFinish: function(){
					new Effect.toggle(einblenden, 'blind', {
						afterFinish: function() {
							helpIE();
							activateEKButtons();
							einblenden.style.display = "block";
							ausblenden.style.display = "none";
						}
					});
				}
			});
		};
	};	
	
	$('footerContainer').style.display = "block"; // IE6
	
	return false;
};

function closeSingleAddon()
{
	deactivateEKButtons();
	
	var addonContainer = $(this).up(1);					
	
	new Effect.toggle(addonContainer, 'blind', {
		afterFinish: function()
		{
			var ausblenden1 = $("addons_details");
			var ausblenden2 = $("addons_fronten");
			ausblenden1.style.display = "none";
			ausblenden2.style.display = "none";
			helpIE();
			activateEKButtons();
		}
	});
	return false;
};

function deactivateEKButtons()
{
	var buttonFronten = $("optionFront");
	var buttonDetails = $("optionDetail");
	buttonFronten.onclick = function() { return false; };
	buttonDetails.onclick = function() { return false; };
};
function activateEKButtons()
{
	var buttonFronten = $("optionFront");
	var buttonDetails = $("optionDetail");
	buttonFronten.onclick = switchAddons;
	buttonDetails.onclick = switchAddons;
};



function toogleAddonsHelperNOT(obj) {

		obj.className="NOT"
		//alert(obj.className)
}

function helpIE() {
	var footerId = "footerContainer";
	var footer = document.getElementById(footerId); // für IE6
	footer.style.bottom = "-1000px";
	footer.style.bottom = "0";
};


////////////////////////////////////////////////
/////////////// getBrowserInfo /////////////////
////////////////////////////////////////////////

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
	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;
}

////////////////////////////////////////////////
////////////// MODAL GONE WILD /////////////////
////////////////////////////////////////////////

var lightbox = Class.create();

lightbox.prototype = {

	yPos : 0,
	xPos : 0,

	initialize: function(ctrl, passedURL, width, height) {
		this.content = passedURL || ctrl.href;
		this.width = width || 400;
		this.height = height || 300;
		Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
		ctrl.onclick = function(){return false;};
	},
	
	// Turn everything on - mainly the IE fixes
	activate: function(){
		if (browser == 'Internet Explorer'){
			this.getScroll();
			this.prepareIE('100%', 'hidden');
			//this.setScroll(0,0);
			this.hideSelects('hidden');
		}
		this.displayLightbox("block");
		centerElement($('lightbox'));
		yPos4IE = this.yPos;
		window.onresize = function() {
           centerElement($('lightbox'));
        }	
		},
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	prepareIE: function(height, overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow; 
	},
	
	// In IE, select elements hover on top of the lightbox
	hideSelects: function(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	},
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	getScroll: function(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	},
	
	setScroll: function(x, y){
		window.scrollTo(x, y); 
	},
	
	displayLightbox: function(display){
		//alert("hauweg");
		$('overlay').style.display = display;
		newBox = $('lightbox')
		newBox.style.display = display;
		newBox.style.width = this.width + "px";
		newBox.style.height = this.height + "px";
		if(display != 'none') this.loadInfo();
	},
	
	// Begin Ajax request based off of the href of the clicked linked
	loadInfo: function() {
		var myAjax = new Ajax.Request(
        this.content,
        {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
		);
		
	},
	
	// Display Ajax response
	processInfo: function(response){
		info = "<div id='lbContent'>" + response.responseText + "</div>";
		new Insertion.Before($('lbLoadMessage'), info)
		$('lightbox').className = "done";	
		this.actions();			
	},
	
	// Search through new links within the lightbox, and attach click event
	actions: function(){
		lbActions = document.getElementsByClassName('lbAction');
		for(i = 0; i < lbActions.length; i++) {
			Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
			lbActions[i].onclick = function(){return false;};
		}

	},
	
	// Example of creating your own functionality once lightbox is initiated
	insert: function(e){
	   link = Event.element(e).parentNode;
	   if(document.getElementById('lbContent')) {
	   Element.remove($('lbContent'));
								  } else {
									  //alert("des fehlt");
								  };
	 
	   var myAjax = new Ajax.Request(
			  link.href,
			  {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
	   );
	 
	},
	
	// Example of creating your own functionality once lightbox is initiated
	deactivate: function(){
		if(document.getElementById('lbContent')) {
		Element.remove($('lbContent'));
								   } else {
									 //alert("lbContent fehlt");  
								   };
		
		if (browser == "Internet Explorer"){
			//this.setScroll(0,this.yPos);
			
			bod = document.getElementsByTagName('body')[0];
			bod.style.height = "100%";
			bod.style.overflow = "";
	  
			htm = document.getElementsByTagName('html')[0];
			htm.style.height = "100%";
			htm.style.overflow = "";
			
			this.hideSelects("visible");
			helpIE();
		}
		window.onresize = null;
		this.displayLightbox("none");
	}
}


function addLightboxMarkup() {
	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.createElement('div');
	overlay.id		= 'overlay';
	overlay.className = "lbAction";
	overlay.rel = "deactivate";
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.className 	= 'loading';
	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<p>Loading</p>' +
						  '</div>';
	bod.appendChild(overlay);
	bod.appendChild(lb);
}


// Weil der IE ein Krüppel ist...
function getViewportDimensions() {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}


function getScrollOffset() {
	var yPosition = 0;
	if (self.pageYOffset) {
		yPosition = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yPosition = document.documentElement.scrollTop; 
	} else if (document.body) {
		yPosition = document.body.scrollTop;
	}
	return yPosition;
}



function centerElement(elem) {
    var viewport = getViewportDimensions();
    var left = (viewport.width == 0) ? 50 : parseInt((viewport.width - elem.offsetWidth) / 2, 10);
    var top = (viewport.height == 0) ? 50 : parseInt((viewport.height - elem.offsetHeight) / 2, 10);
	var scroller = getScrollOffset();
	if(IE == 6) {
		top = top + scroller;
	};
	//alert(scroller);
    elem.style.left = left + 'px';
    elem.style.top = top + 'px';

    viewport, left, top, elem = null;    
}


////////////////////////////////////////////////
////////////// Menue-Funktionen ////////////////
////////////////////////////////////////////////

function setToActive(ident) {
	var items = $$('#mainmenue a');
	for (i=0; i<items.length; i++) {
		//c.log(items[i].id + " to normal");
		if (items[i].id == ident) {
			//c.log("setToActive() -> "+items[i].id);
			items[i].style.backgroundPosition = "left bottom";
		} else {
			items[i].style.backgroundPosition = "left top";
		};
	};

};


function initMainMenue() {
	var items = $$('#mainmenue a');
	for (i in items) {
		items[i].onmouseover = function() {
			if(this.style.backgroundPosition != "left bottom") {
				this.style.backgroundPosition = "left center";
			};
		};
		items[i].onmouseout = function() {
			if(this.style.backgroundPosition != "left bottom") {
				this.style.backgroundPosition = "left top";
			};
		};
	}
};
function initSubs() {
	if (document.getElementById('sub')) {
		var neuesMenue = new Submenue('sub');
	};
	if (document.getElementById('knamen')) {
		var nocheinneuesMenue = new Subsubmenue('knamen');
	};
	if (document.getElementById('frontenContent')) {
		var nocheinneuesMenue = new Submenue('frontenContent');
	};
};

var Submenue = Class.create();
Submenue.prototype = {
	initialize: function(containerDiv) {
		this.menueItems = $$('#'+containerDiv+' a');
		var iterations = this.menueItems.length;
		c.log("Submenue.create() -> "+iterations);
		for (i=0; i<iterations; i++) {
			this.menueItems[i].observe('mouseover', this.toOver.bindAsEventListener(this.menueItems[i]));
			this.menueItems[i].observe('mouseout', this.toNormal.bindAsEventListener(this.menueItems[i]));
			this.menueItems[i].observe('click', this.toActive.bindAsEventListener(this.menueItems[i], this));
		};
	},
	toActive: function(mItem, obj) {
		var iterations = obj.menueItems.length;
		for (i=0; i<iterations; i++) {
			obj.menueItems[i].style.backgroundPosition = "left top";
		};
		this.style.backgroundPosition = "left bottom";
	},
	toOver: function() {
		if(this.style.backgroundPosition != "left bottom") {
			this.style.backgroundPosition = "left center";
		};
	},
	toNormal: function() {
		if(this.style.backgroundPosition != "left bottom") {
			this.style.backgroundPosition = "left top";
		};
	}
};
var Subsubmenue = Class.create();
Subsubmenue.prototype = {
	initialize: function(containerDiv) {
		this.menueItems = $$('#'+containerDiv+' a');
		var iterations = this.menueItems.length;
		c.log("Subsubmenue.create() -> "+iterations);
		for (i=0; i<iterations; i++) {
			if(this.menueItems[i].id != "zurueck" && this.menueItems[i].id != "weiter" && this.menueItems[i].className != "zurueck" && this.menueItems[i].className != "weiter")
			{
				c.log("Subsubmenue.create() -> "+this.menueItems[i].id);
				this.menueItems[i].observe('mouseover', this.toOver.bindAsEventListener(this.menueItems[i]));
				this.menueItems[i].observe('mouseout', this.toNormal.bindAsEventListener(this.menueItems[i]));
				this.menueItems[i].observe('click', this.toActive.bindAsEventListener(this.menueItems[i], this));
			};
		};
	},
	toActive: function(mItem, obj) {
		var iterations = obj.menueItems.length;
		for (i=0; i<iterations; i++) {
			if(obj.menueItems[i].id != "zurueck" && obj.menueItems[i].id != "weiter" && obj.menueItems[i].className != "zurueck" && obj.menueItems[i].className != "weiter")
			{
			obj.menueItems[i].style.backgroundImage = "url(/bilder/ek/blank.gif)";
			var p = obj.menueItems[i].down();
			p.style.backgroundImage = "url(/bilder/ek/blank.gif)";
			p.style.color = "#134071";
			p.className = "normal";
			}
		};
		this.style.backgroundImage = "url(/bilder/ek/kname_a_bg_active.gif)";
		var p = this.down();
		p.style.backgroundImage = "url(/bilder/ek/kname_p_bg_active.gif)";
		p.style.color = "#ffffff";
		p.className = "active";
		//return false;
	},
	toOver: function() {
		if(this.style.backgroundImage != "url(/bilder/ek/kname_a_bg_active.gif)") {
			this.style.backgroundImage = "url(/bilder/ek/kname_a_bg_over.gif)";
			var p = this.down();
			p.style.backgroundImage = "url(/bilder/ek/kname_p_bg_over.gif)";
			p.style.color = "#134071";
			p.className = "over";
		};
	},
	toNormal: function() {
		if(this.style.backgroundImage != "url(/bilder/ek/kname_a_bg_active.gif)") {
			this.style.backgroundImage = "url(/bilder/ek/blank.gif)";
			var p = this.down();
			p.style.backgroundImage = "url(/bilder/ek/blank.gif)";
			p.style.color = "#134071";
			p.className = "normal";
		};
	}
};

function menueListitemActive(obj) {
	if(!obj) return;	
	obj.style.backgroundImage = "url(/bilder/ek/kname_a_bg_active.gif)";
	var p = obj.down();
	c.log(obj.style.backgroundImage);
	p.style.backgroundImage = "url(/bilder/ek/kname_p_bg_active.gif)";
	p.style.color = "#ffffff";
};


function activateMenueItems(mainID, subNr, subsubNr) {
	
	if(mainID == "a")
	{
		setToActive("a");
	}
	else 
	{
		var subItems    = $$('#sub a');
		var subsubItems = $$('#subsub a');
		for(i=0; i<subItems.length; i++) {
			subItems[i].style.backgroundPosition = "left top";
		}
		for(i=0; i<subsubItems.length; i++) {
			if(subsubItems[i].id != "zurueck" && subsubItems[i].id != "weiter")	{
				subsubItems[i].style.backgroundPosition = "left top";
				var p = $(subsubItems[i]).down();
				if(p)
				{
						p.className = "normal";
				}
			};
		}
		var subItem    = $('sub'+String(subNr));
		if (document.getElementById('subsub'+String(subsubNr)))
		{
			var subsubItem = $('subsub'+String(subsubNr));
			var p = $(subsubItem).down();
			p.className = "active";
			subItem.style.backgroundPosition    = "left bottom";
			menueListitemActive(subsubItem);
		}
		setToActive(mainID);
		//c.log("activateMenueItems("+mainID+", "+subNr+", "+subsubNr+")");
	};
};




 function bildladen() {c.log("start")
	var url = "includes/ajax/returnImage.php?img=arezzo_2";

	var hans2 = $("hans2");
	new Ajax.Request(url, {
							method: 'post',
							requestHeaders: 'image/jpeg',
							onSuccess: function(transport) {c.log("succ")
							var boddy = $(document.getElementsByTagName("body")[0]);
								var hans = new Image();
								c.log(hans)
								hans2.src = transport.responseText;
								c.log("bild da?");
								hans2.insert(hans, { position: before })

							}
	});
	c.log("end")
};
function open_planer(was)
{
	try
	{
		fenster = window.open(was,"_blank","width=995,height=600,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,left=0,top=0");
		fenster.focus();
	}
	catch(e)
	{
		alert("Bitte ändern Sie die Sicherheitsstufe des Popupblockers\n\rIhres Browsers von >>hoch<< auf >>mittel<< um das Problem zu lösen.")	
	}
};
function open_katalog(was,weite,hoehe,type)
{
	try
	{
		fenster = window.open(was+'?type='+type,"_blank","width="+weite+",height="+hoehe+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,left=0,top=0");
		fenster.focus();
	}
	catch(e)
	{
		alert("Bitte ändern Sie die Sicherheitsstufe des Popupblockers\n\rIhres Browsers von >>hoch<< auf >>mittel<< um das Problem zu lösen.")	
	}
};
