function parseJSONResult(data) {
  data = data.replace(/<\!--(.*)-->/g, '');				  	
  data = data.replace(/\t/g, '');
  data = data.replace(/\n/g, '');
  data = dojo.trim(data);
	data = String(data);
	var jsonRes = null;
	if((data != null) && (data != '')) {
		jsonRes = dojo.fromJson(data);
	}
	if(jsonRes != null) {
		return jsonRes;
	}
	else {
		return false;
	}
}

function trimAJAXResult(data) {
	if(data != '') {
	  data = data.replace(/<\!--(.*)-->/g, '');				  	
	  data = data.replace(/\t/g, '');
	  data = data.replace(/\n/g, '');
	  data = dojo.trim(data);
		data = String(data);
		return data;
	}
	else {
		return false;
	}
}

window.createBasketHover = function() {
	dojo.query("input[class='LinkBasket']").onclick(
		function() {
			var BBHN = dojo.byId("BasketHoverNotifierID");
			var vp = dijit.getViewport();
			dojo.style(BBHN, 'display', 'block');
			dojo.fadeIn({node:"BasketHoverNotifierID",duration: 100}).play();
			var xPosition = vp.w/2 - 150 + vp.l;
			var yPosition = vp.h/2 - 100 + vp.t;
			dojo.marginBox(BBHN, {l:xPosition , t:yPosition });
	});
	dojo.query("button[class='AddToBasket']").onclick(
		function() {
			var BBHN = dojo.byId("BasketHoverNotifierID");
			var vp = dijit.getViewport();
			dojo.style(BBHN, 'display', 'block');
			dojo.fadeIn({node:"BasketHoverNotifierID",duration: 100}).play();
			var xPosition = vp.w/2 - 150 + vp.l;
			var yPosition = vp.h/2 - 100 + vp.t;
			dojo.marginBox(BBHN, {l:xPosition , t:yPosition });
	});
	dojo.query("input[class='ButtonBasket LeftSmallMargin']").onclick(
		function() {
			var BBHN = dojo.byId("BasketHoverNotifierID");
			var vp = dijit.getViewport();
			dojo.style(BBHN, 'display', 'block');
			dojo.fadeIn({node:"BasketHoverNotifierID",duration: 100}).play();
			var xPosition = vp.w/2 - 150 + vp.l;
			var yPosition = vp.h/2 - 100 + vp.t;
			dojo.marginBox(BBHN, {l:xPosition , t:yPosition });
	});
}
dojo.addOnLoad( window.createBasketHover );

window.createIE6Notifier = function() {
	IE6Notifier=dojo.doc.createElement("div");
	IE6Notifier.id = 'IE6Notifier';
	IE6Notifier.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="380">'+
		'  <tr>'+
		'   <td><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r1_c1.png" width="380" height="177" border="0" alt="" /></td>'+
		'  </tr>'+
		'  <tr>'+
		'   <td><table align="left" border="0" cellpadding="0" cellspacing="0" width="380">'+
		'	  <tr>'+
		'	   <td><a href="http://www.microsoft.com/germany/windows/internet-explorer/download-ie.aspx" target="_blank"><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r2_c1.png" width="102" height="114" border="0" alt="" /></a></td>'+
		'	   <td><a href="http://www.mozilla-europe.org/de/firefox/" target="_blank"><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r2_c2.png" width="89" height="114" border="0" alt="" /></a></td>'+
		'	   <td><a href="http://www.apple.com/de/safari/" target="_blank"><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r2_c3.png" width="94" height="114" border="0" alt="" /></a></td>'+
		'	   <td><a href="http://www.google.de/chrome" target="_blank"><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r2_c4.png" width="95" height="114" border="0" alt="" /></a></td>'+
		'	  </tr>'+
		'	</table></td>'+
		'  </tr>'+
		'  <tr>'+
		'   <td><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r3_c1.png" width="380" height="18" border="0" id="Hover_r3_c1" alt="" /></td>'+
		'  </tr>'+
		'  <tr>'+
		'   <td><img style="cursor: pointer;" onclick="dojo.byId(\'IE6Notifier\').style.display=\'none\';" src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r4_c1.png" width="380" height="35" border="0" alt="" /></td>'+
		'  </tr>'+
		'  <tr>'+
		'   <td><img src="#Shop.MediaGallery.WebPath/IE6/Images/Hover_r5_c1.png" width="380" height="36" border="0" id="Hover_r5_c1" alt="" /></td>'+
		'  </tr>'+
		'</table>';



	var vp = dijit.getViewport();
	dojo.style(IE6Notifier, 'position', 'absolute');
	dojo.style(IE6Notifier, 'display', 'block');
	dojo.style(IE6Notifier, 'zIndex', '10000');
	dojo.body().appendChild(IE6Notifier);
	var xPosition = vp.w/2 - 190 + vp.l;
	var yPosition = vp.h/2 - 190 + vp.t;
	dojo.marginBox(IE6Notifier, {l:xPosition , t:yPosition });
}

window.ICPrecalcSize = function(node,start) {
	slidewidth = dojo.style(dojo.query('div.IC_VisibleBrands')[0],'width');	// Breite des Sliders (auch nicht sichtbarer 
																																								// Bereich)
	elem = dojo.byId(node);
	counter = start;	// Zähler, welcher zählt, wie viele Elemente er schon verschoben hat und nun verschiebt
	tWidth = 0;				// errechnet die benötigte Breite
	i = 0;						// Zähler, welcher zählt, wie viele Elemente insgesamt vorhanden sind
	dojo.query('a',elem).forEach(
		function(tNode)
		{
			tW = dojo.style(tNode,'width');	// Breite des aktuellen Elements
			if ( i >= start && slidewidth > (tWidth + tW) && counter < (start+4))
			{
				tWidth += tW;
				counter++;
				// Wenn sichtbarer Bereich erreicht ist, bisherige Breite und Breite des aktuellen Elements die Breite des 
						// sichtbaren Bereichs übersteigen und nicht mehr als 4 Elemente gezählt wurden, wird die benötigte Breite angepasst
						// und der Zähler erhöht
			}
			i++;
		}
	);
	
	spaceLeft = slidewidth - tWidth;	// Platz, der nicht durch die 4 anzuzeigenden Elemente in Anspruch genommen wird
	tPadding = (spaceLeft / counter);	// Platz wird auf die anzuzeigenden Elemente aufgeteilt
	restPadding = spaceLeft - (Math.floor(tPadding) * counter);	// Margin, die auf das letzte anzuzeigende Element 
																																		// aufgeschlagen wird, die von ungeraden tPadding übrig beleibt
	counter = start;
	i = 0;
	dojo.query('a',elem).forEach(
		function(tNode)
		{
			if (i >= start && counter < (start+4))
			{
				if ((i+1) == (start+4))
				{
					tPadding = Math.floor(tPadding) + restPadding;
				}
				dojo.style(tNode,'marginRight',Math.floor(tPadding)+'px');
				counter++;
			}
			i++;
		}
	);
	return counter;
}
var icpos = 0; // Variable, die insgesamt speichert, ab welchem Element die Elemente angezeigt werden sollen

window.ICSlide = function(direction) {
	if (ICcanSlide == 1)	// verhindert mehrmaliges Sliden, bevor zuende geslidet
	{
 		ICcanSlide = 0;
 		var slideelem = dojo.byId('IC_VisibleBrands');
 		var maxwidth = 0;		// Breite des gesamten Sliders
 		var maxElems = 0;		// Anzahl aller Elemente
 		dojo.query('#IC_VisibleBrands a').forEach(function(node)
 			{
	 			maxwidth += dojo.style(node,'width');
	 			maxElems++;
 			}
 		);
 		
 		
 		var curLeft	  = dojo.style(slideelem,'left');  // Wo ist der Slider aktuell
 		var slidewidth = dojo.style(dojo.query('div.IC_VisibleBrands')[0],'width'); // Größe der Schrittweite
 		
 		if (direction == 'right')
 		{
 			newLeft = curLeft - slidewidth;	// neue Position, zB. 0 - 670
 			icpos = window.ICPrecalcSize('IC_VisibleBrands',icpos);	// Errechnung der anzuzeigenden Elemente (inkl. ausgleichender Margin)
 		}
 		else
 		{
 			newLeft = curLeft + slidewidth;	// 0 + 670
 			
 			icpostemp = (maxElems - icpos);	// temporäre Position, ab dem angezeigt werden soll
 			if (icpostemp > 4)
 			{
 				icpostemp = 4;
 			}
 			icpos = window.ICPrecalcSize('IC_VisibleBrands',(icpos-1)+icpostemp);
 		}
 		
 		if (newLeft <= ((maxwidth - slidewidth) * -1))
 		{
 			dojo.style(dojo.byId('icright'),'visibility','hidden'); // Ist letztes Element erreicht, wird rechter Sliderknopf verborgen
 		}
 		else
 		{
 			dojo.style(dojo.byId('icright'),'visibility','visible');	
 		}
 		
 		if (newLeft >= 0)
 		{
 			dojo.style(dojo.byId('icleft'),'visibility','hidden');	// Ist erstes Element erreicht, wird linker Sliderknopf verborgen
 		}
 		else
 		{
 			dojo.style(dojo.byId('icleft'),'visibility','visible');	
 		}
 		
 		
 		dojo.fx.slideTo(
 			{
				node: slideelem,
				duration:1000,
				unit: "px",
				left: newLeft,
				onStart:function(e)
				{
					ICPrecalcSize('IC_VisibleBrands',start);	// ,start+3);
				},
				onEnd:function(e)
				{
						ICcanSlide = 1;
				}
			}
		).play(); 
	}
}

dojo.require("dojo.fx");
var ICcanSlide = 1;


/* SelectBoxen hübschen */
var icDDBCounter = 0;

window.initICCreateDDB = function() {
	var targetFkt;
	var tmpNodeID = 0;
	dojo.query('.ICCreateDDB').forEach (
		function(node)
		{
			// auszuführende Aktion bei onchange etc. speichern
			var targetFkt = node.getAttribute('targetfkt');
			
			// alte SelectBox verstecken
			node.className = 'HideElement';
			
			// Option-Elemente in einem Array speichern
			var icOptions = new Array();
			dojo.query('option', node).forEach (
				function(icOption)
				{
					icOptions.push(icOption);
				}
			);
			
			// Anker-Div erzeugen
			var anchorDiv = document.createElement("div");
			anchorDiv.id = "IC_SelectDiv"+icDDBCounter;
			anchorDiv.className = "IC_SelectDiv";
			
			// Listen-Div erzeugen
			var listDiv = document.createElement("div");
			listDiv.id = "IC_OptionsDiv"+icDDBCounter;
			listDiv.className = "IC_OptionsDiv";
			listDiv.style.display = "none";
			
			var selectedElem = 0;
			
			// Anker-Div befüllen
			for(var i = 0; i < icOptions.length; i++)
			{
				if((icOptions[i].getAttribute("selected") == 'selected') || (icOptions[i].getAttribute("selected") == true))
				{
					// Unterscheidung nur für Produktdetailansicht in ABS Täubner nötig
					if (icOptions[i].getAttribute('icimages') && icOptions[i].getAttribute('icimagem') != null && icOptions[i].getAttribute('icimagel') != null)
					{
						//cs - anchorDiv.innerHTML = '<div id="'+node.id+'" '+
						anchorDiv.innerHTML = '<div id="IC_SelectBox'+icDDBCounter+'" '+
						'name="'+node.name+'" '+
						'class="IC_SelectBox" '+
						'onclick="toggleDDList(\''+listDiv.id+'\');" '+
						//'value="'+icOptions[i].getAttribute('value')+'" '+
						'value="'+icOptions[i].value+'" '+
						'abbr="'+icOptions[i].getAttribute('abbr')+'" '+
						'icimages="'+icOptions[i].getAttribute('icimages')+'" '+
						'icimagem="'+icOptions[i].getAttribute('icimagem')+'" '+
						'icimagel="'+icOptions[i].getAttribute('icimagel')+'" >'+
						icOptions[i].innerHTML+
						'</div>';
					}
					else
					{
						anchorDiv.innerHTML = '<div id="IC_SelectBox'+icDDBCounter+'" '+
						'name="'+node.name+'" '+
						'class="IC_SelectBox" '+
						'onclick="toggleDDList(\''+listDiv.id+'\');" '+
						'abbr="'+icOptions[i].getAttribute('abbr')+'" '+
						'value="'+icOptions[i].value+'" >'+
						icOptions[i].innerHTML+
						'</div>';
						//'value="'+icOptions[i].getAttribute('value')+'"';						
					}
					
					/*if (node.name != null)
					{
						anchorDiv.innerHTML += ' name="'+node.name+'"';
					}
					
					// zusätzliches Attribut für Länderauswahl
					if (icOptions[i].getAttribute('abbr') != null)
					{
						anchorDiv.innerHTML += ' abbr="'+icOptions[i].getAttribute('abbr')+'"';
					}*/
					
					anchorDiv.innerHTML += '<div class="IC_SelectArrowDiv" '+
						'onclick="toggleDDList(\''+listDiv.id+'\');" >'+
						'&nbsp;'+
						'</div>';
					selectedElem = 1;
				}
			}
			
			// wurde kein selektiertes Element gefunden, wird das erste ins Anker-Div geschrieben
			if(selectedElem == 0)
			{
				// Unterscheidung nur für Produktdetailansicht in ABS Täubner nötig
				if (icOptions[0].getAttribute('icimages') && icOptions[0].getAttribute('icimagem') != null && icOptions[0].getAttribute('icimagel') != null)
				{
					anchorDiv.innerHTML = '<div id="IC_SelectBox'+icDDBCounter+'" '+
						'name="'+node.name+'" '+
						'class="IC_SelectBox" '+
						'onclick="toggleDDList(\''+listDiv.id+'\');" '+
						//'value="'+icOptions[0].getAttribute('value')+'" '+
						'value="'+icOptions[0].value+'" '+
						'abbr="'+icOptions[0].getAttribute('abbr')+'" '+
						'icimages="'+icOptions[0].getAttribute('icimages')+'" '+
						'icimagem="'+icOptions[0].getAttribute('icimagem')+'" '+
						'icimagel="'+icOptions[0].getAttribute('icimagel')+'" >'+
						icOptions[0].innerHTML+
						'</div>'
				}
				else
				{
					anchorDiv.innerHTML = '<div id="IC_SelectBox'+icDDBCounter+'" '+
						'name="'+node.name+'" '+
						'class="IC_SelectBox" '+
						'onclick="toggleDDList(\''+listDiv.id+'\');" '+
						'abbr="'+icOptions[0].getAttribute('abbr')+'" '+
						'value="'+icOptions[0].value+'" >'+
						icOptions[0].innerHTML+
						'</div>';
					//'value="'+icOptions[0].getAttribute('value')+'"';
				}
				
				/*if (node.name != null)
				{
					anchorDiv.innerHTML += ' name="'+node.name+'"';
				}
				
				// zusätzliches Attribut für Länderauswahl
				if (icOptions[0].getAttribute('abbr') != null)
				{
					anchorDiv.innerHTML += ' abbr="'+icOptions[0].getAttribute('abbr')+'"';
				}*/
				
				anchorDiv.innerHTML += '<div class="IC_SelectArrowDiv" '+
					'onclick="toggleDDList(\''+listDiv.id+'\');" >'+
					'&nbsp;'+
					'</div>';
			}
			
			//Listen-Div befüllen
			listDiv.innerHTML = '';
			for(var i = 0; i < icOptions.length; i++)
			{
				if (icOptions[i].getAttribute('icimages') && icOptions[i].getAttribute('icimagem') != null && icOptions[i].getAttribute('icimagel') != null)
				{
					// Unterscheidung nur für Produktdetailansicht in ABS Täubner nötig
					listDiv.innerHTML += '<div id="ID_'+icDDBCounter+'_'+i+'" '+
					'name="'+node.name+'" '+
					'class="IC_Option" value="'+icOptions[i].getAttribute('value')+'" '+
					'icimages="'+icOptions[i].getAttribute('icimages')+'" '+
					'icimagem="'+icOptions[i].getAttribute('icimagem')+'" '+
					'icimagel="'+icOptions[i].getAttribute('icimagel')+'" '+
					'abbr="'+icOptions[i].getAttribute('abbr')+'" '+
					'onclick="saveSelectedDDElem(\'IC_SelectBox'+icDDBCounter+'\',\'ID_'+icDDBCounter+'_'+i+'\');'+targetFkt+';toggleDDList(\''+listDiv.id+'\');" >'+
					icOptions[i].innerHTML+
					'</div>';
				}
				else
				{
					listDiv.innerHTML += '<div id="ID_'+icDDBCounter+'_'+i+'" '+
					'name="'+node.name+'" '+
					'class="IC_Option" value="'+icOptions[i].getAttribute('value')+'" '+
					'abbr="'+icOptions[i].getAttribute('abbr')+'" '+
					'onclick="saveSelectedDDElem(\'IC_SelectBox'+icDDBCounter+'\',\'ID_'+icDDBCounter+'_'+i+'\');'+targetFkt+';toggleDDList(\''+listDiv.id+'\');" >'+
					icOptions[i].innerHTML+
					'</div>';
				}
					
				/*if (node.name != null)
				{
					listDiv.innerHTML += ' name="'+node.name+'"';
				}
				
				// zusätzliches Attribut für Länderauswahl
				if (icOptions[i].getAttribute('abbr') != null)
				{
					listDiv.innerHTML += ' abbr="'+icOptions[i].getAttribute('abbr')+'"';
				}*/
					
				listDiv.innerHTML += '<div class="ClearBoth MinimizeHeight"></div>';
			}
			
			// alte SelectBox "entfernen"->ID ändern
			node.id = node.id+'_old';
			
			// neue DropdownBox anzeigen
			var parentDiv = node.parentNode;
			parentDiv.appendChild(anchorDiv);
			parentDiv.appendChild(listDiv);
			
			// DropdownBox initialisieren
			initICDDBox(anchorDiv.id,listDiv.id);
			
			// DropdownCounter hochzählen
			icDDBCounter++;
		}
	);
}

dojo.addOnLoad( window.initICCreateDDB );

/*
	Shimmer (displayed transparent for capturing hover clicks out of a box)
*/
window.destroyShimmer = function() {
	dojo.query('.Shimmer').forEach( function(shimmerItem) {
		dojo._destroyElement(shimmerItem);
	});
}

window.createShimmer = function(Toggler) {
	var bodywidth = dojo.style(dojo.body(),'width');
	var bodyheight = dojo.style(dojo.body(),'height');
	Shimmer=dojo.doc.createElement("div");
	Shimmer.id = 'Shimmer';
	dojo.style(Shimmer, 'display', 'block');
	dojo.style(Shimmer, 'width', bodywidth-10 + "px");
	dojo.style(Shimmer, 'height', bodyheight-10 + "px");
	dojo.style(Shimmer, 'zIndex', '9965');
	dojo.style(Shimmer, 'position', 'fixed');
	dojo.style(Shimmer, 'top', '0');
	dojo.style(Shimmer, 'left', '0');
	//dojo.body().appendChild(Shimmer);
	dojo.byId(Toggler).parentNode.appendChild(Shimmer);
	dojo.addClass(Shimmer,'Shimmer');
	dojo.attr(Shimmer,'cdd',Toggler);
	//Shimmer.setAttribute('onclick','toggleDDList(\''+Toggler+'\');'); doesnt work in IE
	document.getElementById('Shimmer').innerHTML = '&nbsp;';
}

window.initClickOnShimmer = function() {
	dojo.query('.Shimmer').onclick( function(e) {
		dojo.query('.Shimmer').forEach( function(shimmerItem) {
			listID = shimmerItem.getAttribute('cdd');
			toggleDDList(listID);
		});
	});
}

/*
  Functions to show the Header-DropDownList
*/

function initICDDBox(anchorID,listID) {
	var anchorObj = dojo.byId(anchorID);
	var listContainerObj = dojo.byId(listID);
	
	if(anchorObj && listContainerObj) {	
		// set the default displayed state
		listContainerObj.setAttribute('displayed', 'off');
		//dojo.connect(listContainerObj,"onclick",saveSelectedDDElem(anchorObj.id,listContainerObj.id));
	}
}

function toggleDDList(listID) {
	var listContainerObj = dojo.byId(listID);
	var display = listContainerObj.getAttribute('displayed');
	
	if (display == 'on') {
		dojo.style(listContainerObj, "display", "none");
		display = 'off';
		window.destroyShimmer();
	}
	else {
		dojo.style(listContainerObj, "display", "block");
		display = 'on';
		//window.createShimmer(toggleDDList);
		//window.createShimmer(listContainerObj);
		window.createShimmer(listID);
		window.initClickOnShimmer(listID);
	}
	// Remember the toggle state
	listContainerObj.setAttribute('displayed', display);
}

// Funktion, die das selektierte Element der DropdownBox
// in das Anker-Div schreibt
function saveSelectedDDElem(nodeID,optionID) {
	var innerAnchorObj = dojo.byId(nodeID);
	var optionObj = dojo.byId(optionID);
	
	if(innerAnchorObj && optionObj) {
		innerAnchorObj.setAttribute('value',optionObj.getAttribute('value'));
		//alert(innerAnchorObj.innerHTML +" - "+ innerAnchorObj.innerHTML);
		innerAnchorObj.innerHTML = optionObj.innerHTML;
		if (optionObj.getAttribute('icimagem') != null && optionObj.getAttribute('icimagel') != null)
		{
			innerAnchorObj.setAttribute('icimagem',optionObj.getAttribute('icimagem'));
			innerAnchorObj.setAttribute('icimagel',optionObj.getAttribute('icimagel'));
		}
					
		if (optionObj.name != null)
		{
			innerAnchorObj.setAttribute('name',optionObj.getAttribute('name'));
		}
		
		// zusätzliches Attribut für Länderauswahl
		if (optionObj.getAttribute('abbr') != null)
		{
			innerAnchorObj.setAttribute('abbr',optionObj.getAttribute('abbr'));
		}
		
		// Selektion für alte Selectbox setzen
		var selectBoxObj = dojo.byId(nodeID+'_old');
		var icOptions = new Array();
		dojo.query('option', selectBoxObj).forEach (
			function(icOption)
			{
				icOptions.push(icOption);
			}
		);
		
		for(var i = 0; i < icOptions.length; i++)
		{
			if(icOptions[i].getAttribute("value") == optionObj.getAttribute('value'))
			{
				icOptions[i].setAttribute('selected','selected');
			}
			else
			{
				icOptions[i].removeAttribute('selected');
			}
		}
	}
}


// Funktion zum Aufklappen der erweiterten Kategoriebeschreibung
function showAdditionalCatDescription() {
	dojo.query('.ICCategoryDescriptionReadMoreLink').onclick( function(e) {
		e.preventDefault();
		var CatDescObj        = dojo.byId('ICCategoryDescriptionTextID');
		var CatDescWrapperObj = dojo.byId('ICCategoryDescriptionWrapperID');
		var AddCatDescObj     = dojo.byId('AdditionalCategoryDescriptionID');
		var ICCatMoreLinkObj  = dojo.byId('ICCatMoreLinkID');
		var ICCatHideLinkObj  = dojo.byId('ICCatHideLinkID');
		dojo.style(CatDescWrapperObj,'min-height','106px');
		if ((CatDescObj != null) && (CatDescWrapperObj != null) && (ICLongDescription != null) && (ICLongDescription != '')) {
			CatDescObj.innerHTML = ICLongDescription;
			dojo.style(CatDescWrapperObj,'height','auto');
		}
		
		if((AddCatDescObj != null) && (ICCatMoreLinkObj != null) && (ICCatHideLinkObj != null)) {
			var display = AddCatDescObj.getAttribute('displayed');
			var wipeArgs = {
				node: "AdditionalCategoryDescriptionID",
				duration:1000
			};
			if(display == '0') {
				var anim = dojo.fx.wipeIn(wipeArgs).play();
				dojo.connect(anim, "onEnd", function(){
					AddCatDescObj.setAttribute('displayed','1');
					dojo.addClass(ICCatMoreLinkObj,'HideElement');
					dojo.removeClass(ICCatHideLinkObj,'HideElement');
				});
				anim.play();
			}
			else {
				var anim = dojo.fx.wipeOut(wipeArgs).play();
				dojo.connect(anim, "onEnd", function(){
					AddCatDescObj.setAttribute('displayed','0');
					dojo.removeClass(ICCatMoreLinkObj,'HideElement');
					dojo.addClass(ICCatHideLinkObj,'HideElement');

					if ((CatDescObj != null) && (CatDescWrapperObj != null) && (ICSlicedDescription != null) && (ICSlicedDescription != '')) {
						CatDescObj.innerHTML = ICSlicedDescription;
						dojo.style(CatDescWrapperObj,'height','106px');
					}
				});
				anim.play();
			}
		}
	});
}

dojo.addOnLoad(showAdditionalCatDescription);

// Funktion zum Schliessen eines Hovers

function closeHover(object) {
	if((object != null) && (typeof object == 'object')) {
		dojo.style(object,'display','none');
		dojo.style(object.parentNode.parentNode,'display','none');
	}
}

function ICSwitchOrder(rel) {
	if((rel != null) && (rel != '') && (rel != 'null')) {
		location.href=rel;
	}
}

function ICSetPager(rel) {
	if((rel != null) && (rel != '') && (rel != 'null')) {
		location.href=rel;
	}
}



// Funktion zum Anzeigen der Variantenauswahl als Hover

var WebServerScriptUrlSSL = '';

function ICShowVariationsHoverByPID() {
	dojo.query('.ICShowVariationHoverBtn').onclick( function(e) {
		e.preventDefault();
		
		if(dojo.byId('ICShowVariationHoverBox') != null) {
			return false;
		}
		
		var pid             = e.target.getAttribute('pid');
		var subCategoryPath = e.target.getAttribute('path');
		var catPath         = e.target.getAttribute('catpath');
		var color           = e.target.getAttribute('ccode');

		var showVarHoverBox = dojo.doc.createElement("div");
		var dataPre = '<div class="ICShowVariationHoverBoxInner AjaxLoaderCentered" id="ICSVHInnerID"><div class="ICSVHCloseBtn">X</div><div id="ICSVHWrapperID">';
		var dataPost = '</div></div>';

		var bodywidth = dojo.style(dojo.body(),'width');
		var bodyheight = dojo.style(dojo.body(),'height');

		var vp = dijit.getViewport();

		showVarHoverBox.id = 'ICShowVariationHoverBoxID';
		dojo.addClass(showVarHoverBox,'ICShowVariationHoverBox');

		dojo.style(showVarHoverBox, 'width', bodywidth-10 + "px");
		dojo.style(showVarHoverBox, 'height', bodyheight-10 + "px");

		showVarHoverBox.innerHTML = dataPre + dataPost;

		dojo.body().appendChild(showVarHoverBox);

		var VHoverInnerObj = dojo.byId('ICSVHInnerID');
		if(VHoverInnerObj != null) {
			dojo.style(VHoverInnerObj,'height', vp.h-400 + 'px');
		}

		dojo.fadeIn( {
			node: showVarHoverBox,
			duration: 500,
			onEnd: function() {
				dojo.xhrGet({
					url: "?ViewAction=IC_ViewVariationHover&ObjectPath="+subCategoryPath+"&ChosenColor="+color+"&CatPath="+catPath+"&ChangeAction=BlockMonitor",
					load: function (data) {
						showVarHoverBox.innerHTML = dataPre + data + dataPost;

						var VHoverInnerObj = dojo.byId('ICSVHInnerID');
						
						//adjust shimmer,if variationbox larger than the shimmer
						if(VHoverInnerObj != null) {
							var VHinnerHeight    = dojo.style(VHoverInnerObj,'height');
							var VHouterHeight    = dojo.style(showVarHoverBox,'height');
							var VHinnerCSSOffset = dojo.style(VHoverInnerObj,'top');
							if((VHinnerHeight+VHinnerCSSOffset) > VHouterHeight) {
								dojo.style(showVarHoverBox,'height',(VHinnerHeight+VHinnerCSSOffset+100)+'px');
							}
						}

						//remove loader-gif
						dojo.removeClass(VHoverInnerObj,'AjaxLoaderCentered');
						//init close-btn
						ICCloseVariationsHoverByPID();
						//init color-picker
						ICToggleVariationHoverColor();
						//init basket button
						ICEnableBasketBtn();
					}
				});
			}
		}).play();
	});
}

function ICCloseVariationsHoverByPID() {
	var showVarHoverBox = dojo.byId('ICShowVariationHoverBoxID')
	
	if(showVarHoverBox != null) {
		dojo.query('.ICSVHCloseBtn').onclick( function(e) {
			e.preventDefault();
			dojo.fadeOut( {
				node: showVarHoverBox,
				duration: 500,
				onEnd: function() {
					dojo._destroyElement(showVarHoverBox);
				}
			}).play();
		});
	}
}

function ICSwitchVariationsHover(ColorCode,subCategoryPath) {
	var VHoverInnerObj   = dojo.byId('ICSVHInnerID');
	var VHoverWrapperObj = dojo.byId('ICSVHWrapperID');
	
	if((VHoverInnerObj != null) && (VHoverWrapperObj != null)) {
		dojo.fadeOut( {
			node: VHoverWrapperObj,
			duration: 500,
			onEnd: function() {	
				dojo.addClass(VHoverInnerObj,'AjaxLoaderCentered');
				
				dojo.xhrGet({
					url: "?ViewAction=IC_ViewVariationHover&ObjectPath="+subCategoryPath+"&ChosenColor="+ColorCode+"&ChangeAction=BlockMonitor",
					load: function (data) {
						VHoverWrapperObj.innerHTML = data;
						dojo.fadeIn( {
							node: VHoverWrapperObj,
							duration: 500,
							onEnd: function() {	
								dojo.removeClass(VHoverInnerObj,'AjaxLoaderCentered');
								
								//init close-btn
								ICCloseVariationsHoverByPID();
								//init color-picker
								ICToggleVariationHoverColor();
								//init basket button
								ICEnableBasketBtn();
							}
						}).play();
					}
				});
			}
		}).play();
	}
}

function ICToggleVariationHoverColor() {
	dojo.query('.IC_SelectBox,.IC_SelectArrowDiv').onclick( function(e) {
		var sBoxObj  = dojo.byId('IC_OptionsDivVH');
		if(sBoxObj != null) {
			var display = sBoxObj.getAttribute('displayed');
			if (display != null && display == 'on') {
				dojo.style(sBoxObj,'display','none');
				sBoxObj.setAttribute('displayed','off');
			}
			else {
				dojo.style(sBoxObj,'display','block');
				sBoxObj.setAttribute('displayed','on');
			}
		}
	});
}

dojo.addOnLoad(ICShowVariationsHoverByPID);



// Funktion zum Anzeigen des Warte-Hovers

function showDelayHover(delay) {
	var hoverObj = dojo.byId('ICDelayHover');
	var vp = dijit.getViewport();
	var xPosition = vp.w/2 - (parseInt(dojo.style(hoverObj,'width'))/2) + vp.l;
	var yPosition = vp.h/2 - (parseInt(dojo.style(hoverObj,'height'))/2) + vp.t;
	
	if(hoverObj != null) {
		dojo.style(hoverObj,'display','block');
		dojo.marginBox(hoverObj, {l:xPosition , t:yPosition });
		
		if((delay == null) || (delay == '')) {
			delay = 0;
		}
		
		dojo.fadeIn({
			node: hoverObj,
			duration: 200,
			onEnd: function() {	
				if(delay > 0) {
					dojo.fadeOut( {
						node: hoverObj,
						duration: 200,
						delay: delay,
						onEnd: function() {
							dojo.style(hoverObj,'display','none');
						}
					}).play();
				}
			}
		}).play();
	}
}

function ICAdjustProcessBar() {
	var ulObj = dojo.byId('OrderProcessID');
	if(ulObj != null) {
		var ulWidth    = dojo.style(ulObj,'width');
		var childCount = ulObj.getElementsByTagName('li').length;
		var liWidth = Math.floor(ulWidth / childCount)-11;
		if(childCount > 0) {
			dojo.query("ul > li").style({width:liWidth+'px'});
		}
	}
}


// Funktion zum Scollen der Produkt-ThumbNails

function ICScrollThumbNails(direction) {
	var ContentNode = dojo.byId('ThumbColWrapperID');
	var ContentNodeHeight = dojo.style(ContentNode,'height');
	var NewPosition = 0;
	var Offset = 96;
	
	if(ContentNode != null) {
		var ContentNodeWrapperHeight = dojo.style(ContentNode.parentNode,'height');
		var ContentNodeWrapperBottom = dojo.style(ContentNode.parentNode,'top') + ContentNodeWrapperHeight;
	
		if(direction == 0) {
			NewPosition = dojo.style(ContentNode,'top')+Offset;
			if(NewPosition >= Offset) {
				NewPosition = 0;
			}
		}
		else {
			NewPosition = dojo.style(ContentNode,'top')-Offset;
		}

		if(((NewPosition) <= 0) && (((NewPosition * -1) + ContentNodeWrapperBottom + 28) < ContentNodeHeight + Offset)) {
			dojo.fx.slideTo( {
				node: ContentNode,
				top: NewPosition,
				left: dojo.style(ContentNode,'left'),
				unit: "px",
				duration: 500
			}).play();
		}
	}
}

function ICInitScrollThumbNails() {
	dojo.query('.BtnUp').onclick( function(e) {
		ICScrollThumbNails(0);
	});
	dojo.query('.BtnDown').onclick( function(e) {
		ICScrollThumbNails(1);
	});
}

function ICChangeProdMidImage(smallImgPath,medImgPath,largeImgPath) {
	if((medImgPath != null) && (medImgPath != '') && (largeImgPath != null) && (largeImgPath != '')) {
		var medImgObj   = dojo.byId('IC_imgImageMedium');
		var largeImgObj = dojo.byId('IC_imgImageLarge');
		
		if((medImgObj != null) && (largeImgObj != null)) {
				
			dojo.fadeOut({
				node: medImgObj,
				duration: 500,
				onEnd: function() {
					medImgObj.setAttribute('src',medImgPath);
					largeImgObj.setAttribute('src',largeImgPath);
					
					dojo.fadeIn( {
						node: medImgObj,
						duration: 500,
						delay: 200
					}).play();
				}
			}).play();
		}
	}
	
	if((smallImgPath != null) && (smallImgPath != '')) {
		var smallImgObj = dojo.byId('IC_imgImageSmall');
		
		if(smallImgObj != null) {
			dojo.fadeOut({
				node: smallImgObj,
				duration: 500,
				onEnd: function() {
					console.log(smallImgPath);
					smallImgObj.setAttribute('src',smallImgPath);
					
					dojo.fadeIn( {
						node: smallImgObj,
						duration: 500,
						delay: 200
					}).play();
				}
			}).play();
			
			//smallImagePath-paramater des SlideShowBildes aendern, damit onclick richtiges Medium-Bild laedt
			var functionString = smallImgObj.getAttribute('onclick');

			if (typeof functionString == 'string') {
				var onclickArray = functionString.split(',');
			
				onclickArray[1] = "'"+medImgPath+"'";
				onclickArray[2] = "'"+largeImgPath+"');";
				smallImgObj.setAttribute('onclick',onclickArray.join(','));
			} else {
				smallImgObj.setAttribute('onclick',function() { eval("ICChangeProdMidImage('',medImgPath,largeImgPath)"); });
			}
		}
	}
}

dojo.addOnLoad(ICInitScrollThumbNails);


// Funktion zum aktivieren des WK-Buttons
function ICEnableBasketBtn() {
	dojo.query('#basketForm input.Text').onkeyup( function(e) {
		if(e.target.value > 0) {
			dojo.removeAttr(dojo.byId('AddToBasketButton1ID'),'disabled');
			dojo.removeAttr(dojo.byId('AddToBasketButton2ID'),'disabled');
			
			dojo.removeClass(dojo.byId('AddToBasketButton1ID'),'DisabledBtn');
			dojo.removeClass(dojo.byId('AddToBasketButton2ID'),'DisabledBtn');

			dojo.removeClass(dojo.byId('AddToBasketButton1ID').parentNode,'DisabledBtn');
			dojo.removeClass(dojo.byId('AddToBasketButton2ID').parentNode,'DisabledBtn');
		}
	});
}


// Funktion zum Darstellen des Abpreises in der Produktdetailansicht
function ICRefreshDetailPrice(currency) {
	var DetailPriceObj    = dojo.byId('ICLowestPriceFieldID');
	var DetailNetPriceObj = dojo.byId('ICLowestNetPriceFieldID');
	
	var PriceLabelObj     = dojo.byId('IC_DetailPriceID');
	var NetPriceLabelObj  = dojo.byId('IC_DetailNetPriceID');
	
	if((DetailPriceObj != null) && (DetailNetPriceObj != null) && (PriceLabelObj != null) && (NetPriceLabelObj != null)) {
		var DetailPrice    = DetailPriceObj.innerHTML;
		var DetailNetPrice = DetailNetPriceObj.innerHTML;
		
		DetailPrice = number_format(parseFloat(DetailPrice),2, epages.vars.Locale.decimalSep, epages.vars.Locale.thousandSep);
		DetailNetPrice = number_format(parseFloat(DetailNetPrice),2, epages.vars.Locale.decimalSep, epages.vars.Locale.thousandSep);
		
		PriceLabelObj.innerHTML    = DetailPrice +' '+currency;
		NetPriceLabelObj.innerHTML = DetailNetPrice +' '+currency;
	}
}


function number_format(number, decimals, dec_point, thousands_sep) {
    number = (number+'').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

