function initialColorChange() {
	// Kategorie im ersten Menü einfärben
	if (document.getElementById(currentCategoryName) && categoryColors) {
		document.getElementById(currentCategoryName).style.backgroundColor = categoryColors[currentCategoryName]['bg'];
		document.getElementById(currentCategoryName).firstChild.style.color = categoryColors[currentCategoryName]['fg'];
	}
	
	// Zweites Menü in seiner Farbe einfärben
	if (document.getElementById('second_menu')) {
		for (i=0;i<document.getElementById('second_menu').getElementsByTagName('li').length;i++) {
			document.getElementById('second_menu').getElementsByTagName('li')[i].style.backgroundColor = categoryColors[currentCategoryName]['bg'];
			document.getElementById('second_menu').getElementsByTagName('li')[i].firstChild.style.color = categoryColors[currentCategoryName]['fg'];
		}
	}
	
	
	// Falls vorhanden und aktiviert, Aktivierte Menübox im 2. Menü einfärben
	if (document.getElementById('secondmenu_item'+currentPageId)) {
		document.getElementById('secondmenu_item'+currentPageId).style.backgroundColor = calcDifferentColor(getColor('secondmenu_item'+currentPageId),0.3);
		// alert("neue Farbe: "+calcDifferentColor(getColor('secondmenu_item'+currentPageId)));
	}
	
	// Falls vorhanden und aktiviert, Aktivierte Menübox im rechten Menü einfärben
	if (document.getElementById('rightmenu_item'+currentPageId)) {
		document.getElementById('rightmenu_item'+currentPageId).style.backgroundColor = '#DDDDDD';				
	}
	
	// Falls vorhanden und aktiviert, Aktivierte Menübox im Home einfärben
	if (document.getElementById('homebar_item'+currentPageId)) {
		document.getElementById('homebar_item'+currentPageId).style.backgroundColor = calcDifferentColor('#a53451',-0.2); // 				
	}
	
}


function chgCol(where) {
	
	whereId = where.getAttribute('id');
	currentColor = getColor(whereId);
	
	// Wenn das aktuell aufgerufene Objekt ein 2.-Menü-ListItem ist...
	if (whereId.match(/^secondmenu_item[0-9]+$/)) {
		if (currentColor == categoryColors[currentCategoryName]['bg']) {
			$(whereId).setStyle('background-color',categoryColors[currentCategoryName]['bghover']);
		}
		if (currentColor == categoryColors[currentCategoryName]['bghover']) {
			$(whereId).setStyle('background-color',categoryColors[currentCategoryName]['bg']);
		}
	}
	// Sonst ist es ein Hauptmenüeintrag
	else {
		if (currentColor == 'transparent' && categoryColors) {
			$(whereId).setStyle('background-color',categoryColors[whereId]['bg']);
		}
		else {
			if (where != document.getElementById(currentCategoryName)) 
				$(whereId).setStyle('background-color','');
		}
	}
}

/**
 * this chgCol2 is for more "static" page links
 */
function chgCol2(where,fg,bg,bghover) {
	whereId = where.getAttribute('id');
	currentColor = getColor(whereId);
	
	if (currentColor == 'transparent') {
		 where.style.backgroundColor = bghover;
		 if (where.getElementsByTagName('a').length >0) where.firstChild.style.color = fg;
	}
	else {
		if (currentColor == bghover) {
			where.style.backgroundColor = bg;
			if (where.getElementsByTagName('a').length >0) where.firstChild.style.color = '';
		}
	}
}


function getColor (where) {
	/*  Autor 1999, 2002 (c) Kristof Lipfert, Duesseldorf      */
	/* http://www.lipfert-malik.de/webdesign/tutorial/bsp/getcomputedstyle-4all.html */
	
	if(window.getComputedStyle)	Farbe=window.getComputedStyle(document.getElementById(where),"" ).getPropertyValue("background-color");
	else if(document.getElementById(where).currentStyle)	Farbe= document.getElementById(where).currentStyle.backgroundColor;
	else if(document.ids)	Farbe=document.layers[where].bgColor;
	else if(document.all)	{
		evalString = 'document.all.'+where+'.style.backgroundColor;';
		eval('Farbe = '+evalString);
	}
	
	if( document.ids )	Farbe="#000000".substr( 0,(7-Farbe.toString(16).length)+Farbe.toString(16) );
		else if( Farbe.indexOf('rgb')>-1){
			Farbe=Farbe.split("(")[1].split(")")[0].split(",");
		for(i=0;i<3;i++){
			Farbe[i]=(Farbe[i]*1).toString(16);
			if (Farbe[i]<10) Farbe[i] = '0'+Farbe[i];
		}
		Farbe="#"+Farbe.join("");
	}
	return Farbe;
}

function calcDifferentColor (color,change) {	// color is always given in String "#RRGGBB"
	

	colorArray 	= Array(parseInt(color.substring(1,3),16),parseInt(color.substring(3,5),16),parseInt(color.substring(5,7),16));
	// change = Math.floor(change/10);
	
	ret = ''
	
	for (i=0;i<colorArray.length;i++) {
		newColor = Math.floor(colorArray[i]+(colorArray[i]*change));
		if (newColor > 255) newColor = 255;
		else if (newColor<0) newColor = 0;
		/*
		if (colorArray[i]<128) {
			newColor = Math.floor(colorArray[i]+(colorArray[i]*factor));
			if (newColor > 255) { alert('okay, fang ich ab');  newColor = 255; }
		}
		else {
			newColor = Math.floor(colorArray[i]-(colorArray[i]*factor));
			if (newColor<0) newColor = 0;
		}
		*/
		
		// alert("index: "+i+"\nAlte farbe "+colorArray[i]+"\nNeue Farbe: "+newColor+"\nHex: "+dechex(newColor));
		colorArray[i] = dechex(newColor);
		
	}
	
	
	ret = colorArray.join('');
	// alert("neu: "+ret+"\nalt: "+color);
	
	return '#'+ret;
}




function dechex(dec) {
	// from here: http://dbcf.de/farbauswahl/
	var i, j, hex;
	var temp=new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');

	// ix
	i=Math.floor(dec/16);
	// xj
	j=dec%16;

	i=temp[i];
	j=temp[j];

	// ij
	hex=i+j;

	return hex;
}

function showDiv(where) {
	element = document.getElementById(where);
	if (!element.style.display || element.style.display == 'none')
		element.style.display='block';
	else element.style.display='none';
	return true;
}


/******** AJAX STUFF ***********/
function urlencode (str) {
 var code = "";
 for (var i = 0; i < str.length; i++) {
  if (str.charAt(i) == " ") {
   code += "+";
  } else if (str.charAt(i) == "+") {
   code += "%2B";
  } else if (str.charCodeAt(i) > 127) {
   code += encodeURI(str.charAt(i));
  } else {
   code += escape(str.charAt(i));
  }
 }
 return code;
}


function warenkorbUpdate() {
	var initialWarenkorbUpdate = new Ajax('/warenkorb.php',{method: 'post', data: 'showWarenKorbInfo=1', update:$('warenkorbinfo')}).request();
}
function warenkorbEmpty() {
	var warenkorbEmpty = new Ajax('/warenkorb.php',{method: 'post', data: 'showWarenKorbInfo=1&empty=1',update:$('warenkorbinfo')}).request();
}
