// globale Variablen f�r...
// ...AJAX-Anfragen
var http_request = false;
var ajax_type = 1;
var ajax_tmp = "";
// ...Fading
var isGray = false;
// ...Effekte
var effectBlocked = false;
var currentEffect = null;
// ...Mausposition
var posx = 0;
var posy = 0;
// ...Popup
var popupShown = false;

var aktive = window.setInterval("checkhash()", 100);
var oldhash = window.location.hash;

function checkhash () {
	if(typeof(oldhash) == "undefined"){
		oldhash = window.location.hash;
	}
	else if(window.location.hash != oldhash){
		window.location.reload();
 		oldhash = window.location.hash;
	}
}

// Fenstergr��e zur�ckliefern als Array [breite, h�he]
function getWindowSize() {
	// Ausma�e des Fensterbereichs bestimmen
	width = window.innerWidth;
	height = window.innerHeight;
	// f�r IE6 standardkonformen Modus anpassen
	if (typeof width=='undefined') {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
	// f�r IE anpassen
	if (typeof width=='undefined') {
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	return Array(width, height);	
}

// L�dt die nach der Fenstergr��e passende Version der Produktbilder dynamisch nach
function setProductPictureDimensions() {
	windowSize = getWindowSize();
	width = windowSize[0];
	height = windowSize[1];

	// Eigenschaften setzen
	smallPostFix = "400";
	bigPostFix = "560";
	// Schwellwert f�r Anzeige des anderen Bildes
	borderHeight = 795;
	borderWidth = 700;
	
	// Ausma�e des Fensterbereichs bestimmen
	width = window.innerWidth;
	height = window.innerHeight;
	// f�r IE6 standardkonformen Modus anpassen
	if (typeof width=='undefined') {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
	// f�r IE anpassen
	if (typeof width=='undefined') {
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	
	if (width >= borderWidth && height >= borderHeight) {
		currentPostFix = bigPostFix;
	    newSource = current_small_picture;
	}
	else {
		currentPostFix = smallPostFix;
	    newSource = current_big_picture;
	}
		
	for (pic_i = 0; pic_i < document.getElementsByClassName("productPicture").length; pic_i++) {
		currentObject = document.getElementsByClassName("productPicture")[pic_i];
		currentObjectStyle = document.getElementsByClassName("productPicture")[pic_i].style;
		currentFileName	= currentObjectStyle.backgroundImage;
		currentFileName = currentFileName.substr(4, (currentFileName.length-5));
		// IE 6 anpassen
		if (vIE()==6) {
			if (currentFileName=="") {
				currentFileName = currentObjectStyle.filter;
				currentFileName = currentFileName.substr(57, currentFileName.length-80);
			}
		}
	
		currentObjectStyle.backgroundRepeat = 'no-repeat';
		currentObjectStyle.width = currentPostFix + "px";;
		currentObjectStyle.height = currentPostFix + "px";
		 document.getElementsByClassName("productPictureBox")[pic_i].style.height = currentPostFix + "px";
		currentObjectStyle.backgroundImage =  "url(" + newSource + ")";
		// IE 6 anpassen
		if (vIE()==6) {
			currentObjectStyle.backgroundImage =  "none";
			currentObjectStyle.filter =  "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" + newSource+ "', sizingMethod='crop')";
			currentEffectFade = new Effect.Opacity('productOuterContainer', { to: 0.99, duration: 0.6 });
		}
		currentObjectStyle.display='block';
	}
	setVerticalAlignMiddle(currentPostFix, height);
	slideOutFooters(height);
	window.scrollTo(0, 1);
}


// Slidet Footer und Produkt-Switcher nach unten, wenn niedrige H�he erreicht
function slideOutFooters(height) {
	if (navigator.userAgent.toLowerCase().indexOf("iphone")<0) {
		borderHeight = 630;
		if (height < borderHeight) {
			pageHeight = getElementHeight('body');
			offsetY = height-pageHeight-136;
			document.getElementById('footer').style.position = 'absolute';
			document.getElementById('footer').style.marginBottom = offsetY+'px';
			document.getElementById('productSwitcherOuter').style.position = 'absolute';
			document.getElementById('productSwitcherOuter').style.marginBottom = (offsetY)+'px';
		}
		else {
			if (vIE()!=6) document.getElementById('footer').style.position = 'fixed';
			document.getElementById('footer').style.bottom = '0px';
			if (vIE()!=6) document.getElementById('productSwitcherOuter').style.position = 'fixed';
			document.getElementById('productSwitcherOuter').style.bottom = '61px';
			document.getElementById('footer').style.marginBottom = '0px';
			document.getElementById('productSwitcherOuter').style.marginBottom = '0px';
		}
	}
	else {
		document.getElementById('productSwitcherOuter').style.position = 'absolute';
		//if (Math.abs(window.orientation)==90) {
			siteHeight = document.getElementById('productOuterContainer').offsetHeight;
			document.getElementById('productSwitcherOuter').style.top = (102+siteHeight)+'px';
		//}
		//else document.getElementById('productSwitcherOuter').style.bottom = '0px';
	}
}

// Elementh�he in Pixeln zur�ckliefern
function getElementHeight(Elem) {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} 
		else if (document.all){
			var elem = document.all[Elem];
		}
		if (elem.style.pixelHeight) { 
			xPos = elem.style.pixelHeight;
		} 
		else {
			xPos = elem.offsetHeight;
		}
		return xPos;
}


// setzt das Produktbild vertikal in die Mitte
function setVerticalAlignMiddle(picHeight, clientHeight) {
	
	// dazu TopPadding ( >= 0) setzen auf:
	// ((ClientH�he - (H�heHeader+H�heFooter+H�heSwitcher))/2) * (H�heHeader / (H�heFooter+H�heSwitcher))
	
	if (navigator.userAgent.toLowerCase().indexOf("iphone")<0) topPadding = ((clientHeight-234-picHeight)/2)*(106/128);
	else topPadding = 50;
	if (topPadding < 0) topPadding = 0;
	document.getElementById('productBlock').style.paddingTop = topPadding + 'px';
}


// setzt Elemente anderer Seiten vertikal in die Mitte
function setVerticalAlignMiddleAll(element, elementHeight, paddingOffset) {
	
	// dazu TopPadding ( >= 0) setzen auf:
	// ((ClientH�he - (H�heHeader+H�heFooter))/2) + BottomPadding
	clientHeight = window.innerHeight;
	
	// f�r IE6 standardkonformen Modus anpassen
	if (typeof clientHeight=='undefined') {
		clientHeight = document.documentElement.clientHeight;
	}
	// f�r IE anpassen
	if (typeof clientHeight=='undefined') {
		clientHeight = document.body.clientHeight;
	}

	
	topPadding = (((clientHeight-51)-(elementHeight))/2)+37;
	if (topPadding < paddingOffset) topPadding = paddingOffset;

	document.getElementById(element).style.paddingTop = (topPadding) + 'px';
	if (document.getElementById(element).style.display=='none') document.getElementById(element).style.display='block';
}


// liefert die Version des IE oder -1 falls anderer Browser
function vIE(){
	return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
}

// Ajax-Anfrage durchf�hren
function doAjax(a_type, target, parameters, values) {
	ajax_type = a_type;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml;charset=ISO-8859-15');
		}
	} 
	else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	if (!http_request) {
		alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
		return false;
	}

url = target+"?";
	for (param_i = 0; param_i < parameters.length; param_i++) {
		if (param_i > 0) url += "&";
		url += parameters[param_i]+"="+values[param_i];
	}

	error = false;

	if (ajax_type==1 || ajax_type==4) {
		ajax_tmp = values[0];	
	}
	if (ajax_type==3) {
		// Feldpr�fungen Tell-A-Friend-Popup
		if (document.getElementById('message').value=="" || document.getElementById('message').value==" ") {
			document.getElementById('message').style.border = '1px solid #aa0000';
			document.getElementById('messageBlock').style.fontWeight = 'bold';
			error = true;
		}
		else {
			document.getElementById('message').style.border = '1px solid #c3c3c3';
			document.getElementById('messageBlock').style.fontWeight = 'normal';
		}
		if (document.getElementById('toEmail').value=="" || !check_email(document.getElementById('toEmail').value, false)) {
			document.getElementById('toEmail').style.border = '1px solid #aa0000';
			document.getElementById('toEMailBlock').style.fontWeight = 'bold';
			error = true;
		}
		else {
			document.getElementById('toEmail').style.border = '1px solid #c3c3c3';
			document.getElementById('toEMailBlock').style.fontWeight = 'normal';
		}
		if (document.getElementById('fromEmail').value=="" || !check_email(document.getElementById('fromEmail').value, false)) {
			document.getElementById('fromEmail').style.border = '1px solid #aa0000';
			document.getElementById('fromEMailBlock').style.fontWeight = 'bold';
			error = true;
		}
		else {
			document.getElementById('fromEmail').style.border = '1px solid #c3c3c3';
			document.getElementById('fromEMailBlock').style.fontWeight = 'normal';
		}
		url += "&toEmail=" + document.getElementById('toEmail').value + "&fromEmail=" + document.getElementById('fromEmail').value + "&message=" + document.getElementById('message').value;
	}
	
	// URL aktualisieren
	if (ajax_type==1) {
		window.location.hash = '/?product_id=' + values[1];
		oldhash = window.location.hash;
	}
	
	if (!error) {
		http_request.onreadystatechange = processAjax;
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}

// Fertige Ajax-Anfrage verarbeiten
function processAjax() {
	if (http_request.readyState == 4) {
		var answer = http_request.responseText;
		answer = answer.replace(/\\n/, "\n");
		// Produktbild und -text aktualisieren
		if (ajax_type==1) {
			document.getElementById('productOuterContainer').innerHTML = answer;
			performFade2(ajax_tmp);
		}
		// Event-Bild und -text aktualisieren
		if (ajax_type==4) {
			document.getElementById('productOuterContainer').innerHTML = answer;
			performFade2Gallery(ajax_tmp);
		}
		// Popup aktualisieren
		if (ajax_type==2 || ajax_type==3) {
			document.getElementById('popupBody').innerHTML = answer;
		}
		if (ajax_type==5) {
			document.getElementById('body').innerHTML = answer;
			setProductPictureDimensions();
			initialize();
		}
	}
}

// Pr�fen, ob Mailadresse g�ltig
function check_email(email, maybeempty) {
		if (email=="" && maybeempty) return true;
		else if (email.indexOf("@") < 1 || email.indexOf(".") < 1 || email.substr(email.lastIndexOf("."), email.length).length <= 2) return false;
		else return true;
}

function getParamNameFromHash(hashstring) {
	hashentries = hashstring.substr(3, hashstring.length).split('&');
	hashblock = hashentries[0].split('=');
	return hashblock[0];
}

function getParamValueFromHash(hashstring) {
	hashentries = hashstring.substr(3, hashstring.length).split('&');
	hashblock = hashentries[0].split('=');
	return hashblock[1];

}

// Thumbnail-Ansicht sliden
function slideThumbs(direction, elementid) {
	elementwidth = 924;
	if (!effectBlocked) {
		pages = Math.ceil(number_product_pictures/12);
		current = document.getElementById('thumbList').style.left;
		current = current.substr(0, current.indexOf('px'));
		if (direction < 0) restPictures = number_product_pictures - (((-current/elementwidth)+1)*12);
		else restPictures =  ((-current/elementwidth)*12);
		if (restPictures > 12) restPictures = 12;
		offset = 77*restPictures;
		sDuration = (slideDuration)*(Math.log((restPictures/12)+1)+0.306852819);
		if (	(
					(direction > 0 && -current > 0) || 
					(direction < 0 && -current < (elementwidth*(pages-2)+offset))
				)
			
			) {
			effectBlocked = true;
			someEffect = new Effect.Move('thumbList', { x: (direction*offset), y: 0, duration: sDuration, transition: slideEffect, afterFinish: function() { effectBlocked=false; hoverImage('leftArrowLink', false, 1); hoverImage('rightArrowLink', false, -1); } });
		}
		// Setze Button inaktiv
		if (	(
					(direction > 0 && (-current-offset) <= 0) || 
					(direction < 0 && (-current+offset) >= (elementwidth*(pages-2)+offset))
				)
			) {
			
				inactiveEffect = new Effect.Opacity(elementid, { to: 0.4, duration: 1 });
				document.getElementById(elementid).style.cursor = 'default';
				// unset hover here
		}
		// Setze Button aktiv
		else {
			activeEffect = new Effect.Opacity(elementid, { to: 0.9, duration: 1 });
			document.getElementById(elementid).style.cursor = 'pointer';
		}
	}
}

// Produkt-Slider ausfaden
function switchGrayscale(gray) {
	if (!effectBlocked && !popupShown) {
		if (gray && !isGray) {
			if (currentEffect!=null) currentEffect.cancel();
			currentEffect = new Effect.Opacity('productSwitcherOuter', { to: 0.5, duration: 1, afterFinish: function() { currentEffect=null;  } });
		}
		else if (!gray && isGray) {
			if (currentEffect!=null) currentEffect.cancel();
			currentEffect = new Effect.Opacity('productSwitcherOuter', { to: 0.99, duration: 1, afterFinish: function() { currentEffect=null;  } });
		}
		if (vIE()==7) document.getElementById('productSwitcherOuter').style.position = 'absolute';
		isGray = gray;
	}
}

function hoverArrow(elementid, hover) {
	if (hover && document.getElementById(elementid).style.cursor=='pointer') document.getElementById(elementid).className = elementid.substr(0, elementid.indexOf('Link')) + 'Active';	
	else document.getElementById(elementid).className = elementid.substr(0, elementid.indexOf('Link'));	
}

function hover_splash_image(elementid, offelementid) {
	document.getElementById(elementid).style.display='block';
	document.getElementById(offelementid).style.display='none';
}

// Hover-Effekt auf Sliding-Pfeile legen
function hoverImage(elementid, hover, direction) {
	
	elementwidth = 924;
	pages = Math.ceil(number_product_pictures/12);
	current = document.getElementById('thumbList').style.left;
	current = current.substr(0, current.indexOf('px'));
	if (direction < 0) restPictures = number_product_pictures - (((-current/elementwidth)+1)*12);
	else restPictures =  ((-current/elementwidth)*12);
	if (restPictures > 12) restPictures = 12;
	offset = 77*restPictures;

	if (	(
				(direction > 0 && -current > 0) || 
				(direction < 0 && -current < (elementwidth*(pages-2)+offset))
			)
		) {
	document.getElementById(elementid).style.cursor = 'pointer';
	
	activeEffect = new Effect.Opacity(elementid, { to: 0.9, duration: 1 });
	}
	else {
		document.getElementById(elementid).style.cursor = 'default';
		inactiveEffect = new Effect.Opacity(elementid, { to: 0.4, duration: 1 });
		src = document.getElementById(elementid).src;
	}
}

// Hover-Effekt f�r Produkt-Thumbnails ausf�hren
function setHover(elementnum, hover) {
	currentObjectStyle = document.getElementById('thumb_block_hover_' + elementnum).style;
	if (hover) {
		currentObjectStyle.backgroundImage = 'url(../_images/buttons/product_hover.png)';
		if (vIE()==6) {
			currentObjectStyle.zIndex = '1';
			currentObjectStyle.backgroundImage = 'none';
			currentObjectStyle.filter =  "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='_images/buttons/product_hover.png', sizingMethod='crop')";
		}
	}
	else if (document.getElementById('thumb_block_hover_' + elementnum).className!='productThumbOuterActive') {
		currentObjectStyle.backgroundImage = 'none';
		if (vIE()==6) {
			currentObjectStyle.filter = 'none';
			currentObjectStyle.position = 'static';
			currentObjectStyle.zIndex = '0';
		}
	}
}

// Produktseite: Altes Produkt ausfaden
function performFade(elementid, blockid, picture_id, smallpicture, bigpicture, s, category, lang) {
	if (!effectBlocked) {
		current_small_picture = smallpicture;
		current_big_picture = bigpicture;
		effectBlocked = true;
		// Alle "aktiv"-Markierungen zur�cksetzen
		for (block_i = 0; block_i < document.getElementsByClassName("productThumbOuterActive").length; block_i++) {
			if (document.getElementsByClassName("productThumbOuterActive")[block_i].id!=blockid) {
				currentObject = document.getElementById(document.getElementsByClassName("productThumbOuterActive")[block_i].id);
				currentObjectStyle = currentObject.style;
				currentObjectStyle.background='none';
				currentObject.className='productThumbOuter';
				if (vIE()==6) {
					currentObjectStyle.filter = 'none';
					currentObjectStyle.position = 'static';
					currentObjectStyle.zIndex = '0';
				}
			}
		}
		document.getElementById(blockid).className = 'productThumbOuterActive';
		if (vIE()==6) {
			new Effect.Opacity('productText', { to: 0, duration: 0.55 }); 
		}
		currentEffectFade = new Effect.Opacity(elementid, { to: 0, duration: 0.6, afterFinish: function() { doAjax(1, '../_ajax/product_container.php', Array('elementid', 'product_id', 's', 'category', 'lang'), Array(elementid, picture_id, s, category, lang)) } });
	}
}

// Galerieseite (Events): Altes Produkt ausfaden
function performFadeGallery(elementid, blockid, picture_id, smallpicture, bigpicture, s, category) {
	if (!effectBlocked) {
		current_small_picture = smallpicture;
		current_big_picture = bigpicture;
		effectBlocked = true;
		// Alle "aktiv"-Markierungen zur�cksetzen
		for (block_i = 0; block_i < document.getElementsByClassName("productThumbOuterActive").length; block_i++) {
			if (document.getElementsByClassName("productThumbOuterActive")[block_i].id!=blockid) {
				currentObject = document.getElementById(document.getElementsByClassName("productThumbOuterActive")[block_i].id);
				currentObjectStyle = currentObject.style;
				currentObjectStyle.background='none';
				currentObject.className='productThumbOuter';
				if (vIE()==6) {
					currentObjectStyle.filter = 'none';
					currentObjectStyle.position = 'static';
					currentObjectStyle.zIndex = '0';
				}
			}
		}
		document.getElementById(blockid).className = 'productThumbOuterActive';
		if (vIE()==6) {
			new Effect.Opacity('productText', { to: 0, duration: 0.55 }); 
		}
		currentEffectFade = new Effect.Opacity(elementid, { to: 0, duration: 0.6, afterFinish: function() { doAjax(4, '../_ajax/gallery_container.php', Array('elementid', 'picture_id', 's', 'category'), Array(elementid, picture_id, s, category)) } });
	}
}

// Produktseite: Neues Produkt einfaden
function performFade2(elementid) {
	if (vIE()==6) {
		document.getElementById('productText').style.display = 'none';
	}
	setProductPictureDimensions();
	if (vIE()==6) {
		new Effect.Opacity('productText', { to: 0, duration: 0, afterFinish: function() { document.getElementById('productText').style.display = 'block';  }  });
		new Effect.Opacity('productText', { from: 0, to: 0.99, duration: 1.1 });
	}
	currentEffectFade = new Effect.Opacity(elementid, { to: 0.99, duration: 1.2, afterFinish: function() { effectBlocked=false; setProductPictureDimensions(); window.scrollTo(0, 1); } });

}

// Galerieseite (Events): Neues Produkt einfaden
function performFade2Gallery(elementid) {
	if (vIE()==6) {
		document.getElementById('productText').style.display = 'none';
	}
	setProductPictureDimensions();
	if (vIE()==6) {
		new Effect.Opacity('productText', { to: 0, duration: 0, afterFinish: function() { document.getElementById('productText').style.display = 'block';  }  });
		new Effect.Opacity('productText', { from: 0, to: 0.99, duration: 1.1 });
	}
	currentEffectFade = new Effect.Opacity(elementid, { to: 0.99, duration: 1.2, afterFinish: function() { effectBlocked=false; setProductPictureDimensions(); window.scrollTo(0, 1); } });

}

// Scrollbar-Position des vertikalen Scrollbars abfragen
function getScrollTop() {
	winsize = getWindowSize();
	borderHeight = 600;
	if (winsize[1] < borderHeight) {
		pageHeight = getElementHeight('body');
		yOffset = winsize[1]-pageHeight-106;
		if (document.body !=null && document.body.scrollTop!=null) return document.body.scrollTop-yOffset;
		else return document.documentElement.scrollTop-yOffset;
	}
	else return 0;
}

// Mausposition bestimmen und Maus-Events verarbeiten
function getMouseEvents(e) {

	// Mausposition
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		if (document.body !=null && document.body.scrollLeft!=null && e.clientX!=null) posx = e.clientX + document.body.scrollLeft;
		if (document.documentElement) posx += document.documentElement.scrollLeft;
		if (document.body !=null && document.body.scrollTop!=null && e.clientY!=null) posy = e.clientY + document.body.scrollTop;
		if (document.documentElement) posy += document.documentElement.scrollTop;
	}
	
	if (document.getElementById('productSwitcherOuter')!=null && document.getElementById('productSwitcherOuter')!='undefined') {
		windowSize = getWindowSize();
		width = windowSize[0];
		height = windowSize[1];
		// Wenn Position der Maus im Bereich des Productswitchers, dann highlighte Produkte, sonst mache Highlighting weg
		if (posy > height-138+getScrollTop() && posy < height-52+getScrollTop() && posx > (width/2)-486 && posx < (width/2)+486) {
			switchGrayscale(false);	
		}
		else {
			switchGrayscale(true);	
		}
	}
}

// Scrollrad-Event ausf�hren
function handle(delta) {
	if (posy > height-138+getScrollTop() && posy < height-52+getScrollTop() && posx > (width/2)-486 && posx < (width/2)+486) {
		if (delta < 0) slideThumbs(-1);
		if (delta > 0) slideThumbs(1);
	}
}

// Scrollrad-Event abfangen
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

// Popup �ffnen
function openPopup(picture_id, parameter1, parameter2) {
	effect_end = 0.4;
	popupShown = true;
	winsize = getWindowSize();
	document.getElementById('popup').style.paddingTop = ((winsize[1]/2)-175)+'px';
	document.getElementById('popup').style.height = ((winsize[1]/2)+175)+'px';
	// Fill popupBody per ajax here
	doAjax(2, '../_ajax/tell_a_friend_popup_body.php', Array('product_id', 'parameter1', 'parameter2'), Array(picture_id,parameter1, parameter2));
	new Effect.Opacity('productSwitcherOuter', { to: effect_end, duration: 1 });
	new Effect.Opacity('footer', { to: effect_end, duration: 1 });
	new Effect.Opacity('productOuterContainer', { to: effect_end, duration: 1, afterFinish: function() { document.getElementById('popup').style.display = 'block';  }  });
}

// Popup schlie�en
function closePopup(picture_id) {
	if (popupShown) {
		popupShown = false;
		document.getElementById('popup').style.display = 'none';
		new Effect.Opacity('productSwitcherOuter', { to: 0.99, duration: 1 });
		new Effect.Opacity('footer', { to: 0.99, duration: 1 });
		new Effect.Opacity('productOuterContainer', { to: 0.99, duration: 1, afterFinish: function() {  }  });	
	}
}

// Popup bei Klick au�erhalb des Popups schlie�en
function closePopupIfNotInside(picture_id) {
	// Pr�fe ob nicht im PopUp
	windowSize = getWindowSize();
	isInsideQuery = (posx >= ((windowSize[0]/2)-(543/2)) && posx <= ((windowSize[0]/2)+(543/2)) && posy >= ((windowSize[1]/2)-175)  && posy <= ((windowSize[1]/2)+175)) ;
	if (!isInsideQuery)	closePopup(picture_id);	
}

function resetVars(value, productarray, picpath) {
	
	pos = 0;
	
	for (pa_i = 0; pa_i < productarray.length; pa_i++) {
		if (productarray[pa_i][0] == value) pos = pa_i;
	}
	
	current_small_picture = picpath+productarray[pos][4];	
	current_big_picture =  picpath+productarray[pos][3];	
	
	number_product_pictures = productarray.length;

}

var registeredSubnavis = new Array();

// Zeigt das Subnavi-Popup an
function show_subnavi_popup(pid) {
	
	subnavi = document.getElementById('subnavi_' + pid);
	subnaviLink = document.getElementById('subnavi_link_' + pid);

	popupWasHidden = false;
	if (subnavi.style.display!='block') {
			popupWasHidden = true;
			subnavi.style.display='block';
			offsetHeight = subnavi.offsetHeight;
			subnavi.style.display='none';
	}
	else  offsetHeight = subnavi.offsetHeight;
	
	// Positioned by mouse position
	// used_posx = posx;
	// used_posy = posy;

	// Positioned by link position
	linkPosition = getElementPosition(subnaviLink);
	used_posx = linkPosition.x + (subnaviLink.offsetWidth/2);
	used_posy = linkPosition.y;
	
	var scrollPos = getScrollXY();
	
	subnavi.style.left = (used_posx - 84) + 'px';
	if (navigator.userAgent.toLowerCase().indexOf("iphone")<0) subnavi.style.top = (used_posy - offsetHeight - 1 + scrollPos.y) + 'px';
	else subnavi.style.top = '34px';
	
	// with effect: var effectFade = new Effect.Appear('subnavi_' + pid);
	subnavi.style.display='block';
	
	registeredSubnavis['subnavi_' + pid] = true;
	hide_all_subnavi_popups('subnavi_' + pid);
}


function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	var scrollPos = new Object();
	scrollPos.x = scrOfX;
	scrollPos.y = scrOfY;
	return scrollPos;
}

/**
 * Liefert die Position eines HTML-Elements zur�ck
 * @param HTMLElement element
 * @return object object.x = x-Position, object.y = y-Position
 */
function getElementPosition(element) {
	var elem=element,tagname="",x=0,y=0;
	
	while (elem!=null && (typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined")) {
		y+=elem.offsetTop;
		x+=elem.offsetLeft;
		tagname=elem.tagName.toUpperCase();
		if (tagname=="BODY") elem=0;
		if (typeof(elem)=="object")
		if (typeof(elem.offsetParent)=="object") elem=elem.offsetParent;
	} // end while

	position=new Object();
	position.x=x;
	position.y=y;
	return position;
}

// Versteckt alle Subnavi-Popups
function hide_all_subnavi_popups(exclude) {
	for (key in registeredSubnavis) {
		if (key.indexOf('subnavi_') >= 0 && key!=exclude) {
			hide_subnavi_popup(key.substr(8, key.length));
		}
	}
}

// Versteckt das Subnavi-Popup
function hide_subnavi_popup(pid) {
	// with effect: var effectFade = new Effect.Fade('subnavi_' + pid);	
	subnavi = document.getElementById('subnavi_' + pid);
	subnavi.style.display='none';
}

// Liefert zur�ck, ob ein Element ein Kindelement von parent ist
function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}

// Wendet ein MouseOut-Event auf den gesamten Inhalt eines Blocks an
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}