function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var categoriesOpen = 0;
function dropCategories() {
	if (categoriesOpen == 0) {
		Effect.SlideDown('produkte_categories', {duration:1});
		categoriesOpen = 1;
		return false;
	}
	else {
		Effect.SlideUp('produkte_categories', {duration:1});
		categoriesOpen = 0;
		return false;
	}	
}


var companyOpen = 0;
function slideCompany() {
	if (companyOpen == 0) {
		Effect.SlideDown('unternehmen_list', {duration:1});
		companyOpen = 1;
		return false;
	}
	else {
		Effect.SlideUp('unternehmen_list', {duration:1});
		companyOpen = 0;
		return false;
	}	
}




var ourInterval;
var origColor = "#F3F9F1";
var overColor = "#36FF00";
var scrollSpeed = 50;
var scrollHeight = 5;
var scrollWidth = 5;

function scrollStart(direction, divID){
	ourInterval = setInterval("scroll"+direction+"('"+divID+"')", scrollSpeed);
}

function scrollEnd(which){
	document.getElementById(which).style.backgroundColor = origColor;
	clearInterval(ourInterval);
}

function scrollUp(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop - scrollHeight;
}

function scrollDown(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop + scrollHeight;
}

function scrollRight(which){
	//alert(which+' '+document.getElementById(which).scrollLeft+' '+document.getElementById(which).scrollWidth);
	document.getElementById(which).scrollLeft =document.getElementById(which).scrollLeft + scrollWidth;
	//alert(document.getElementById(which).scrollLeft);
}

function scrollLeft(which){
	var temp = document.getElementById(which);
	temp.scrollLeft = temp.scrollLeft - scrollWidth;
}

function loadProductDetails(pID) {
	new Ajax.Updater('productImage', 'jax/productImage.jax.php', {evalScripts:true,method:'post', postBody:'products_id='+pID});
	new Ajax.Updater('productDescription', 'jax/productDescription.jax.php', {evalScripts:true,method:'post', postBody:'products_id='+pID});
}

function openMoreImages(product_id) {
	alert('more');
}

function load_big_image(id,img_src,gallery_path)
{//alert(img_src);
if (Element.visible('product_big_image'))
	{
	 new Effect.Opacity('product_big_image',
			{ duration: 0.75, 
			  transition: Effect.Transitions.linear, 
			  from: 0.95, to: 0.0, afterFinish:function(){
										Element.hide('product_big_image');				
										$("product_big_image").style.zIndex=-50;
										}
			});
	}
else
	{
	 new Effect.Opacity('product_big_image',
			{ duration: 0.75, 
			  transition: Effect.Transitions.linear, 
			  from: 0.0, to: 0.95, beforeStart:function(){
				  new Ajax.Updater('product_big_image','return_img_content.php',{method:'post',postBody:'img_src='+img_src+'&gallery_path='+gallery_path,onComplete:function(){Element.show('product_big_image');$("product_big_image").style.zIndex=50;}});

			  } });
	}
}

function load_big_image_orig(id, img_src)
	{//alert(img_src);
	if (Element.visible('big_image_'+id))
		{
		 new Effect.Opacity('big_image_'+id,
				{ duration: 1.0, 
				  transition: Effect.Transitions.linear, 
				  from: 0.95, to: 0.0, afterFinish:function(){
				  							Element.hide('big_image_'+id);				
				  							$("big_image_"+id).style.zIndex=-50;
											}
				});
		}
	else
		{
		 new Effect.Opacity('big_image_'+id,
				{ duration: 1.0, 
				  transition: Effect.Transitions.linear, 
				  from: 0.0, to: 0.95, beforeStart:function(){
					  new Ajax.Updater('big_image_'+id,'return_img_content_orig.php',{method:'post',postBody:'img_src='+img_src,onComplete:function(){Element.show('big_image_'+id);$("big_image_"+id).style.zIndex=50;}});
				  } });
		}
	}

function URLEncode(stringDEC)
{
	var SAFECHARS = "0123456789" +	
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";
	var HEX = "0123456789ABCDEF";

	var plaintext = stringDEC;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {

			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} 

	return encoded;
}

function nextImage(imgID,gallery_path,img_src,default_image) {
	new Effect.Opacity('product_big_image',
			{ duration: 0.75, 
			  transition: Effect.Transitions.linear, 
			  from: 0.0, to: 0.95, beforeStart:function(){
				  new Ajax.Updater('product_big_image','return_img_content.php',{method:'post',postBody:'img_src='+img_src+'&gallery_path='+gallery_path+'&currImageID='+imgID+'&default_image='+default_image,onComplete:function(){Element.show('product_big_image');$("product_big_image").style.zIndex=50;}});

			  } });
}

function prevImage(imgID,gallery_path,img_src,default_image) {
	new Effect.Opacity('product_big_image',
			{ duration: 0.75, 
			  transition: Effect.Transitions.linear, 
			  from: 0.0, to: 0.95, beforeStart:function(){
				  new Ajax.Updater('product_big_image','return_img_content.php',{method:'post',postBody:'img_src='+img_src+'&gallery_path='+gallery_path+'&currImageID='+imgID+'&default_image='+default_image,onComplete:function(){Element.show('product_big_image');$("product_big_image").style.zIndex=50;}});

			  } });
}

function showMe(text, ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.scrollTop = 0;
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	theDiv.innerHTML = text;
	theDiv.style.visibility = 'visible';
	theDiv.style.width = "250px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left+document.documentElement.scrollTop) - dWid - 30) + "px";
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top+document.documentElement.scrollTop) - dHei) + "px";
}

var sDir = 5;
var tId;
var runDelay = 20;
var scrollVar;
var stillScroll;


function hideMe() {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.visibility = 'hidden';
	stillScroll = false;
	if (tId)
		clearTimeout(tId);
}

function moveMe(ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left) - dWid - 30) + "px";
		
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top) - dHei) + "px";
}

function sizeMe(x) {
	var theDiv = document.getElementById('showMeDiv');
	if (x != '')
		theDiv.style.width = x + 'px';
	else
		theDiv.style.width = '';
	theDiv.style.height = '';
}

function scrollMe() {
	scrollVar = 0;
	stillScroll = true;
	sDir = 5;
	nextScrollStep();	
	var theDiv = document.getElementById('showMeDiv');
}

function nextScrollStep() {
	var theDiv = document.getElementById('showMeDiv');
		
	runDelay = 20;
	
	theDiv.scrollTop = scrollVar;
	scrollVar += sDir;
	
	if (scrollVar <= 0) {
		scrollVar = 0;
		sDir = -sDir;
		runDelay = 1500;
	}
	
	if (scrollVar >= theDiv.scrollHeight - parseInt(theDiv.style.height) +25 ) {
		scrollVar = theDiv.scrollHeight - parseInt(theDiv.style.height) + 25;
		sDir = -sDir;
		runDelay = 1500;
	}
	
	if (stillScroll)
		tId = setTimeout('nextScrollStep()', runDelay);
}
function getInfo(text_value){
	new Ajax.Updater('showMeDiv','jax/return_img_text.php',{method:'post',postBody:'text_value='+text_value});
}

/*  Show me DIV   -    END*/

var animDuration=0.75;
var resizeDuration=0.95;

var selectedImageGlobal='';

function showAnimation(imgWidth,imgHeight){
	
	 //Element.show('lightbox_content');
	 Element.hide('lightbox_content_inner');
	 var widthCurrent = Element.getWidth('lightbox_content_inner')+4;
	 var heightCurrent = Element.getHeight('lightbox_content_inner')+4;
		// get new width and height
	
	
	 var widthNew = (imgWidth  /*+ (borderSize * 2)*/);
	 var heightNew = (imgHeight+36 /*+ (borderSize * 2)*/);
		
	 var xScale = ( widthNew / widthCurrent) *100 ;
	 var yScale = (heightNew / heightCurrent)*100 ;
	 
	 var xScale_2 = ( (widthNew-6) / (widthCurrent)) *100 ;
	 var yScale_2 = ((heightNew-45) / (heightCurrent))*100 ;
	 
	 wDiff = widthCurrent - widthNew;
	 hDiff = heightCurrent - heightNew;
	 
	 $('lighbox_img').src=selectedImageGlobal;
	 new Effect.Parallel(
			[new Effect.Scale('lightbox_content_2', yScale_2, {sync: true,scaleX: false, duration: resizeDuration,scaleMode: { originalHeight: heightCurrent-2, originalWidth: widthCurrent-2 }}),
			 new Effect.Scale('lightbox_content', yScale, {sync: true,scaleX: false, duration: resizeDuration,scaleMode: { originalHeight: heightCurrent, originalWidth: widthCurrent }})
			]			 
			 );
	new Effect.Parallel(
			[
			 new Effect.Scale('lightbox_content_2', xScale_2, {sync: true,scaleY: false, delay: resizeDuration,scaleMode: { originalHeight: heightCurrent-2, originalWidth: widthCurrent-2 }, duration: resizeDuration}),
			 new Effect.Scale('lightbox_content', xScale, {sync: true,scaleY: false, delay: resizeDuration,scaleMode: { originalHeight: heightCurrent, originalWidth: widthCurrent }, duration: resizeDuration,afterFinish:function(){
				new Effect.Opacity('lightbox_content_inner',
						{ duration: animDuration, 
						  transition: Effect.Transitions.linear, 
						  from: 0.0, to: 0.95, beforeStart:function(){
							  Element.hide('lightbox_content_2');
							  Element.show('lightbox_content_inner');
							  Element.show('footer_line_image');
							  
						  } }); }})			
			]
							 );
	 /*if(!( hDiff == 0)){*/ //new Effect.Scale('lightbox_content', yScale, {scaleX: false, duration: resizeDuration,scaleMode: { originalHeight: heightCurrent, originalWidth: widthCurrent }});// }
	 /*if(!( wDiff == 0)){*/ /*new Effect.Scale('lightbox_content', xScale, {scaleY: false, delay: resizeDuration,scaleMode: { originalHeight: heightCurrent, originalWidth: widthCurrent }, duration: resizeDuration,afterFinish:function(){
				new Effect.Opacity('lightbox_content_inner',
						{ duration: animDuration, 
						  transition: Effect.Transitions.linear, 
						  from: 0.0, to: 0.95, beforeStart:function(){
							  Element.hide('lightbox_content_2');
							  Element.show('lightbox_content_inner');
							  Element.show('footer_line_image');
							  
						  } });																																	   
				 }});*/
	// }
	 
	 
}

function oncomplete_img_preloading(){
	
		imgPreloader=new Image();
		imgPreloader.onload=function(){
			//alert('onloaded');
			showAnimation(imgPreloader.width,imgPreloader.height);
			imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
		}
		imgPreloader.src = selectedImageGlobal;
	
	
	//pause(100);Element.hide('lightbox_content_2');showAnimation();
}

var arrayImageGrouped=Array();
var actual_img_pozition=0;

function removeAllElement(array){
	array.splice(0,array.length);	
}
function findIndexInArray(array,element){
	for(i=0;i<array.length;i++){
			if (array[i]==element) return i;
	}
	return -1;
}

function findGroupedImages(group_name){
	removeAllElement(arrayImageGrouped);
	var anchors = document.getElementsByTagName('img');
	for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var nameAttribute = String(anchor.getAttribute('name'));
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (nameAttribute.toLowerCase().match(group_name.toLowerCase())){
				arrayImageGrouped.push(nameAttribute);
				//anchor.onclick = function () {myLightbox.start(this); return false;}
			}
	}
}

function verifyPressedKey(e){
	if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}
		if (keycode==37){
			previousBigImage();
		}
		if (keycode==39){
			nextBigImage();
		}
		if (keycode==27){
			hide_big_image_lightbox();
		}
}

function loadBigImage(group_name,actual_obj){
	
	findGroupedImages(group_name);
	show_lightbox();
	var arrayPageScroll = getPageScroll();
	var arrayPageScroll = getPageScroll();
	$('lightbox').style.top= arrayPageScroll[1]+100+'px';
	Element.show('lightbox_content_2');
	Element.show('lightbox_content');

	document.onkeydown=verifyPressedKey;//$('lightbox').focus();
	
	actual_img_pozition=findIndexInArray(arrayImageGrouped,actual_obj.getAttribute('name'));
	$('zoom_image_actual_image').innerHTML=actual_img_pozition+1;
	$('zoom_image_total_image').innerHTML=arrayImageGrouped.length;
	if (arrayImageGrouped.length<=1){
		$('zoom_image_previous').style.display='none';
		$('zoom_image_next').style.display='none';
		
		$('zoom_image_actual_image').style.display='none';
		$('zoom_image_separator').style.display='none';
		$('zoom_image_total_image').style.display='none';
	}else{
		$('zoom_image_previous').style.display='block';
		$('zoom_image_next').style.display='block';	
		
		$('zoom_image_actual_image').style.display='block';
		$('zoom_image_separator').style.display='block';
		$('zoom_image_total_image').style.display='block';
	}
	show_big_image($('hidden_'+actual_obj.getAttribute('name')).value);
}
function show_big_image(img_src){
	$('lightbox_content_2').show();
	$('lightbox_content_inner').hide();
	new Ajax.Updater('lightbox_header','jax/return_img_content.php',{evalScripts:true,method:'post',postBody:'img_src='+img_src+'&complete=1'});	 
}
function nextBigImage(){
	if (arrayImageGrouped.length>1){
		if (actual_img_pozition+1>arrayImageGrouped.length-1) actual_img_pozition=0; else actual_img_pozition=actual_img_pozition+1;
		$('zoom_image_actual_image').innerHTML=actual_img_pozition+1;
		 var widthCurrent = Element.getWidth('lightbox_content_inner');
		 var heightCurrent = Element.getHeight('lightbox_content_inner');
		 //alert(widthCurrent+' '+heightCurrent);
		if  (widthCurrent>110){
			//$('lightbox_content_2').style.width=widthCurrent+'px';
		}
		if  (heightCurrent>110){
			//$('lightbox_content_2').style.height=heightCurrent+'px';
		}
		
		show_big_image($('hidden_'+arrayImageGrouped[actual_img_pozition]).value);
	}
}
function previousBigImage(){
	if (arrayImageGrouped.length>1){
		if (actual_img_pozition-1<0) actual_img_pozition=arrayImageGrouped.length-1; else actual_img_pozition=actual_img_pozition-1;
		$('zoom_image_actual_image').innerHTML=actual_img_pozition+1;
		var widthCurrent = Element.getWidth('lightbox_content_inner');
		 var heightCurrent = Element.getHeight('lightbox_content_inner');
		 //alert(widthCurrent+' '+heightCurrent);
		if  (widthCurrent>110){
			//$('lightbox_content_2').style.width=widthCurrent+'px';
		}
		if  (heightCurrent>110){
			//$('lightbox_content_2').style.height=heightCurrent+'px';
		}
		show_big_image($('hidden_'+arrayImageGrouped[actual_img_pozition]).value);
	}
}
function hide_big_image_lightbox(){
	new Effect.Opacity('lightbox_content_inner',
			{ duration: 0.75, 
			  transition: Effect.Transitions.linear, 
			  from: 0.95, to: 0.0, afterFinish:function(){
										Element.hide('lightbox_content');				
										Element.hide('footer_line_image');
										
										$('lightbox_header').innerHTML='';
										} });
	new Effect.Fade('overlay', { duration: 1.2});
	showSelectBoxes();
	showFlash();
	document.onkeydown='';
}

