var $j = jQuery.noConflict();

String.prototype.trim = function() {return $j.trim(this)} 

$j.ajaxSetup({
	xhrFields: {
		withCredentials: true
	}
});

$j(document).ready( function() {
	
	iPhone=checkiPhone();
	iPad=checkiPad();
    if($j(".showInView").length==0) {
    	$j('.sbild a img.showInView').die('inview');
	}
	// added temporarily to delete XPEventStorage Cookies
	xpes = getCookie("XPEventStorage"); 
	if(xpes && xpes.length > 1500) {
	    setCookie ("XPEventStorage", "") 
	}

	imgChange=true;
	if($j(".insertLF").length > 0) {
		insertLayoutFragments();
	}	
	
	mainNavigationLayer();
	initUebersichten();
	initWarenkorb();
	initQuickviewWarenkorb();
	initMeinKonto();
	initMerkliste();
	initCanvass();
	if($j(".productContainer").length>0) {
		zoomPreload=false;	
		zoomImg = $j("#grossbild").attr("src"); 
		if(zoomImg) {
			lupImgAlba=zoomImg.replace("albamoda_formatI","formatz");
			lupImgHeine=zoomImg.replace("albamoda_formatI","format_hv_ea_1");
			zoomPreloadAlba = new Image();
			zoomPreloadAlba.src = lupImgAlba;
			zoomPreloadHeine = new Image();
			zoomPreloadHeine.src = lupImgHeine;
		}	
		initDetailview();
	}
	if($j("#zoomContainer").length>0) {
		initZoom();
	}	
	
	initMasstabelle();
	initSuggestSearch();
	initSearch();
	initSchuhAmpel();
	initTeaser();
	initParcelShopLayer();
	init();
	initDirectOrder();
	initCountrySelection();
});

function exitLayer() {
    $j("#exitLayer").show();
}

function initParcelShopLayer() {
	$j(".showParcelShopLayer").unbind("click");
	$j("#parcelShopLayer .xclose").unbind("click");
	
	
	$j("#searchParcelShop .bttn").unbind("click").click(function() {
		$j(".result").html("<div class='loader'> </div>");
	});

	$j(".showParcelShopLayer").click(
		function() {
			$j(".result").html("<div class='loader'> </div>");
			$j.ajax({
				type : "GET",
				url : baseUrl + "/ajax_getparcelshops.html",
				success : function() {
					handleResponseOfParcelShopForm();
					initParcelShopLayer();
				}
			});
			$j("#parcelShopLayer").fadeIn("middle");
			return false;
		}
	);

	$j("#parcelShopLayer .xclose").click( function() {
		$j("#parcelShopLayer").fadeOut("fast");
	});

	$j('#updateEmailAddressForm').ajaxForm(
		{
			timeout : 50000,
			success : function() {
				handleResponseOfParcelShopForm();
				initParcelShopLayer();
			}
		}
	);

	$j("#searchParcelShop").ajaxForm(
		{
			timeout :50000,
			success : function() {
				handleResponseOfParcelShopForm();
				initParcelShopLayer();
			}
		}
	);
	
	if ($j('.h220 #packageStationNumber') != null && $j('.h220 #packageStationNumber').length > 0) {
		if ($j('.h220 #packageStationNumber').val() != "") {
			setInputReadOlny();
		} 
	}
}

function setInputReadOlny() {
	$j('.h220 .salutations').attr('readonly', true);
	$j('.h220 .noPack').attr('readonly', true);
	$j('.h220 .strasse').attr('readonly', true);
	$j('.h220 .hausnummer').attr('readonly', true);
	$j('.h220 .plz').attr('readonly', true);
	$j('.h220 .ort').attr('readonly', true);
	$j('.h220 .vorwahl').attr('readonly', true);
	$j('.h220 .telefon').attr('readonly', true);
}

function validateLogin() {
	if($j(".radio:checked").val() == "loginCustNo") {
	    if($j(".loginCustInput input").val().trim().length == 9 && $j(".loginCustInput input").val().substr(0,1) == "3") {
	    	alert($j("#errorMessage").attr("data-isProspect"));
	        $j(".radio:checked").val("new");
	    }
	}	
	document.login.submit();
}

function myAccountValidateLogin() {
    if($j(".customerNumber").val().trim().length == 9 && $j(".customerNumber").val().substr(0,1) == "3") {
    	alert($j("#errorMessage").attr("data-isProspect-account"));
	} else {	
		document.login.submit();
	}	
}

function handleResponseOfParcelShopForm(response) {
	$j("#parcelShopLayer div a.result").mouseover(function() {
		$j("#parcelShopLayer div a.result").removeClass("selected");
		$j(this).addClass("selected");
		var rel = $j(this).attr("rel");
		$j("#parcelShopLayer div.description").hide();
		$j("#parcelShopLayer div.description[rel=" + rel + "]").show().addClass("selected");
		/*$j("#parcelShopLayer div.result p.bttn").show();*/
		return false;
	});
	
	$j("#parcelShopLayer div a.result").live('click',function() {
		var firstName = $j("div.adresse #firstName").val();
		var lastName = $j("div.adresse  #lastName").val();
		if ($j("div.adresse #firstName").val() != "Paketshop") {
			$j("div.adresse #additionalInformation").val($j(".billName").html());
		}
		applyAddress($j("#parcelShopLayer div a.selected"));
		$j("#parcelShopLayer").hide();
		/*document.login.submit();*/
		setInputReadOlny();
	});
}

function applyAddress(dataRow) {
	var packageStationNumber = dataRow.find("span.packageStationNumber").text();
	var salutation = dataRow.find("span.salutation").text().toLowerCase();
	var firstName = dataRow.find("span.firstName").text();
	var lastName = dataRow.find("span.lastName").text();	
	var streetName = dataRow.find("span.streetName").text();
	var houseNumber = dataRow.find("span.houseNumber").text();
	if (houseNumber == '') {
		var regExpHouseNumber = /([0-9].*)/i;
		var regExpResult = regExpHouseNumber.exec(streetName);
		if (regExpResult != null) {
			houseNumber = regExpResult[1];
			streetName = streetName.replace(houseNumber, '');
		}
	}
	var postalCode = dataRow.find("span.postalCode").text();		
	var city = dataRow.find("span.city").text();

	$j(".newAddress").attr("selected", "selected");

	$j("#packageStationNumber").val(packageStationNumber);
	$j("div.adresse #firstName").val(firstName);
	$j("div.adresse #lastName").val(lastName);
	$j("div.adresse #streetName").val(streetName);
	$j("div.adresse #houseNumber").val(houseNumber);
	$j("div.adresse #postalCode").val(postalCode);
	$j("div.adresse #city").val(city);

	$j("#insadressbuch").hide();
	$j("#insadressbuch #storeFlag").attr('checked', false);

	return false;
}

function welcomeList_initCallback(carousel)
{
	$j("#welcomeLayer").css("visibility","visible");
};	


function init() {
	$j(".logout").unbind("click");
	$j(".contact-form").unbind("click");
	$j(".sendPassword").unbind("click");
	$j(".clearDate, .gutschein").unbind("focus");
	$j(".clearDate").unbind("blur");
	$j(".gutschein").unbind("blur");
	$j(".showTermsAndConditons").unbind("click");
	$j(".showImpressum").unbind("click");

	/* Array indexOf fix for Internet Explorer */
	if(!Array.indexOf){
	  Array.prototype.indexOf = function(obj){
	   for(var i=0; i<this.length; i++){
	    if(this[i]==obj){
	     return i;
	    }
	   }
	   return -1;
	  }
	}	
	
	$j(".callback").mouseover(function(){
		$j(".callback").css("margin-bottom","0px");
	});
	
	$j(".callback").mouseout(function(){
		$j(".callback").css("margin-bottom","-61px");
	});
	
	$j(".callback").unbind("click").click(function(){
		openIframeShadowBox(860,580,"/callback.html");
		return false;
	})
	
	if ($j("#welcomeLayer").size() > 0) {
		$j('.welcomeList').jcarousel({
		       scroll: 4,
		       initCallback: welcomeList_initCallback
		});
		$j("#welcomeListContainer .jcarousel-prev").html('<img src="' + rcContextPath + '/images/app/common/bttn/qv_left.png">');
		$j("#welcomeListContainer .jcarousel-next").html('<img src="' + rcContextPath + '/images/app/common/bttn/qv_right.png">');

	} 
	
	$j(".logout").click( function() {
		$j.ajax( {
			type :"GET",
			url :baseUrl + "/ajax_viewLogout.html",
			dataType :"html",
			success : function(html) {
				if (html.length > 0) {
					openShadowBox(640, 485, html, false);
				}
			}
		});
	});

	$j(".contact-form").click(
		function() {
			preselectedOptionParam = '';
			if ($j(this).attr('rel') != "") {
				preselectedOptionParam = "?preselect="+escape($j(this).attr('rel'));
			}
			openContactFormInShadowBox(preselectedOptionParam);
		});

	$j(".sendPassword").click( function() {
		$j.ajax( {
			type :"GET",
			url :baseUrl + "/ajax_sendPassword.html",
			dataType :"html",
			success : function(html) {
				if (html.length > 0) {
					openShadowBox(640, 450, html, true);
				}
			}
		});
	});

	$j(".showTermsAndConditons").click( function() {
		openTermsAndConditonsInShadowBox();
	});

	$j(".showPrivacy").click( function() {
		openPrivacyInShadowBox();
		return false;
	});
	
	$j(".showImpressum").click( function() {
		openImpressumInShadowBox();
	});

	$j(".clearDate, .gutschein").focus(
		function() {
			if ($j(this).val() == 'TT.MM.JJJJ'
				|| $j(this).val().indexOf("itte") != -1) {
				$j(this).val("");
			}
		}
	);

	$j(".clearDate").blur( function() {
		$j(this).val(splitBirthday($j(this).val()));
	});

	$j("#content_home .suchbox").click( function() {
		clearSearchBox($j(this));
	});
	$j("#content_home .suchbox").keydown( function() {
		clearSearchBox($j(this));
	});

	$j(".setFocus").focus();

	$j("#dictionaryLetter li").unbind("click").click(function() {
		location.href = baseUrl + "/viewDictionaryTerms.html?l=" + $j(this).html();
	});

	$j(".showService").unbind("click").click(function() {
		if ($j("#serviceLinks").css("display") == "none") {
			$j("#serviceLinks").css("display","block");
		} else {
			$j("#serviceLinks").css("display","none");
		}
	});
	
	$j("#serviceLinks #colseService").unbind("click").click(function() {
		$j("#serviceLinks").css("display","none");
	});
	
	$j(".homeNavigation li.homeNaviMainElement a.homeNaviMainLink").unbind("click").click(function() {
		if($j(this).parent("li.aktiv").size() == 0) {
			$j(".homeNavigation li.aktiv").removeClass("aktiv");    
			$j(this).parent("li").addClass("aktiv");
			return false;
		} 
	});	
	
	$j("#catalog-order-form #customerData").click(function(){
		$j("#catalog-order-form #errMissing").css("display","none");
	});
	
	if($j("#catalog-order-form .hasError").length > 0) {
		$j("#catalog-order-form #errMissing").css("display","block");
		setTimeout("$j('#catalog-order-form #errMissing').css('display', 'none')", 2000);
	}
	
	$j(".sendEmailLink").unbind("click").click(function() {
		$j("#bestellcontent #sendContainer").load(baseUrl + "/ajax_sendBasketAsEmail.html","", function() {
			$j("#bestellcontent #sendContainer").fadeIn("middle");
		});
		$j("#bestellcontent #sendContainer").focus();
	});
	
	$j("#productListPagingBottom .more").unbind("click").click(function(){
		showMoreArticles($j(this));
	});
	
	$j("#productListPagingBottom .gotoTop").live("click", function(){
		$j("#productListPagingBottom .gotoTop").blur();
		$j('body,html').animate({scrollTop:0},0);
	});
	
	$j("#bestellcontent .ratecalculator").click(function() {
		showRatenCalculator($j(this));
	});
	
	if($j("#queryString").length>0 && $j("#maincontents #content_home").length>0) {
		$j("#queryString").focus();
	}
}

function initCountrySelection() {

	$j("#content_countrySelection a.countryLink").unbind("click").click(function() {
		var dataCountry = $j(this).attr("data-country");
		if (dataCountry == "") {
			if($j("#content_countrySelection input[type=checkbox]").prop("checked") == true) {
				setCookie("saveCountryOption", "checked", 1);
			} else {
				setCookie("saveCountryOption", "unchecked", 1);
			}
		}
	});
}

function initTeaser() {
	$j(".oneClickDirectOrder").unbind("click");

	$j(".oneClickDirectOrder").click(function() {
		var $a = $j(this);
		var variationExternalKey = $a.attr("rel");
		$j.ajax({
			type: "POST",
			url: baseUrl + "/oneClickDirectOrder.html",
			data: {	variationExternalKey: variationExternalKey },
			dataType :"html",
			success : function(html) {
			    Shadowbox.open({
			        content:    html,
			        player:     "html",
			        handleOversize:    "none",
			        width: "286",
			        height: "260",
			        options:    {
			           overlayOpacity:0.3,
		               onFinish: function(item){
		            	   copyInMinibasket();
							$j("#quickviewBasket").load("/ajaxRefreshQuickViewBasket.html",
								function (result, textStatus, XMLHttpRequest) {
									initQuickviewWarenkorb();				
								}				
							);
		            	   
		               }
			        } 	
			    });	 	    
			},
			error : function() {
				console.log("Failed to submit");
			}
		});		
		return false;	
	});

	$j(".jumptogutschein").unbind().click(function() {
		$j.scrollTo($j(".gutscheintobasket"), 500);
		return false;
	});
	
	$j(".showGutschein").unbind().click(function() {
		var cid = $j(this).attr("data-id");
		openGutscheinInShadowBox(cid);
	});
	
	$j(".gutscheintobasket").unbind("click");

	$j(".gutscheintobasket").click( function(){
	    var articleNr = $j("#gutscheinselect").find("option:selected").attr('alt');
	    var variationExternalKey = $j("#gutscheinselect").find("option:selected").val();
	    
		$j("#indenwk").load(baseUrl + "/ajax_addgutscheintobasket.html", {
			variationExternalKey : variationExternalKey,
			articleNr : articleNr,
			articleNrs : articleNrs
		},
		function (result, textStatus, XMLHttpRequest) {
		    if (textStatus == "success") {
		    	refreshMinibasket(-1);
		    	window.location = baseUrl + "/viewBasket.html";
		    } else {
		    	$j("#gutscheinwarning").css("visibility", "visible");
		    	setTimeout(function(){$j("#gutscheinwarning").css("visibility", "hidden");},3000)
		    }
		});
	});
	
	initPassform();
}

function initPassform() {
	$j(".passformbacktoproduct").live("click", function() {
		top.Shadowbox.close();
	});
	
	$j(".passformbacktolist").live("click", function() {
		var bLink = $j(this).attr("value");
		window.location = baseUrl + bLink;
	});	
}

function initDirectOrder() {
		
	$j("#queryString").keyup(function(){
		queryArticle = $j("#queryString").val();
		if (checkQueryArticle(queryArticle)) {
			queryArticle = 'queryArticle=' + queryArticle;
		} else {
			queryArticle = '';
		}
		$j(".directOrder").attr("href", baseUrl + '/viewBasket.html?' + queryArticle + '#lmPromo=la,3,hk,Header,fl,Direkt_Bestellen');
	});
	
	$j(".directOrder").click(function(){
		queryArticle = $j("#queryString").val();
		if($j(".artnr").length > 0)
			if (checkQueryArticle(queryArticle)) {
				$j(".artnr").attr("value", queryArticle);
			}
	});
}

function checkQueryArticle(queryArticle) {
	if (queryArticle.length != 6 && queryArticle.length != 7 ) {
		return false;
	} else if (queryArticle.length == 6) {
		return queryArticle.match(/[0-9][0-9][0-9][0-9][0-9][0-9]/);
	} else {
		return (queryArticle.match(/[0-9][0-9][0-9][0-9][0-9][0-9][A-z]/) || queryArticle.match(/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/));
	}
}

function viewBonusConnectionBanner() {
	$j.ajax( {
		type :"GET",
		url :baseUrl + "/ajax_viewBonusConnectionBanner.html",
		dataType :"html",
		success : function(html) {
			if (html.length > 0) {
				$j("#gutschein").html(html);
			}
		}
	});
}

function openViewBasketToPrintInShadowBox() {
	openIframeShadowBox(760, 1500, baseUrl + "/ajax_viewBasketToPrint.html", false);
}

function openOrderConfirmationInShadowBox() {
	openIframeShadowBox(760, 1500, baseUrl + "/ajax_viewOrderConfirm.html", false);
}

function openTermsAndConditonsInShadowBox() {
	openIframeShadowBox(740, 500, baseUrl + "/shadowbox_agb/boxedService.html", false);
}

function openRevocationInShadowBox() {
	openIframeShadowBox(740, 500, baseUrl + "/svc_agb_rueckgaberecht/boxedService.html", false);
}

function openPrivacyInShadowBox() {
	openIframeShadowBox(740, 500, baseUrl + "/svc_agb_datenschutz/boxedService.html", false);
}

function openImpressumInShadowBox() {
	openIframeShadowBox(740, 500, baseUrl + "/svc_impressum/boxedService.html", false);
}

function openGutscheinInShadowBox(cid) {
	
	var gutscheinValue = $j("#gutscheinselect").find("option:selected").attr('title');
	var urlPath = "";
	if (cid == "fremd") {
		urlPath = "/show_gutschein_02/gutschein.html";
	} else {
		urlPath = "/show_gutschein_01/gutschein.html";
	}

	$j.get(urlPath , {gutscheinValue:gutscheinValue}, function(data) {
	    Shadowbox.open({
	        content:    data,
	        player:     "html",
	        handleOversize:    "none",
	        width: "731",
			modal :true,
	        height: "500",
	        options:  {
               	onFinish: function(item){
				}
	        } 	
	    });	 
	});
}

function openProductQuickLookInShadowBox(bundleId,styleId,sb_height) {
	
	$j.get(baseUrl + '/ajax_productQuickLook.html',{styleId :styleId, bundleId:bundleId}, function(data) {
	    Shadowbox.open({
	        content:    data,
	        player:     "html",
	        handleOversize:    "none",
	        width: "670",
			modal :true,
	        height: sb_height,
	        options:  {
               	onFinish: function(item){
					initQuickLook();
				}
	        } 	
	    });	 
	});
}

function openContactFormInShadowBox(preslectedOptionParam) {
	preselectedOption = '';
	if (typeof (preselectedOptionParam) != "undefined"	&& preselectedOptionParam != '') {
		preselectedOption = preselectedOptionParam;
	}
	$j.ajax( {
		type :"GET",
		url :baseUrl + "/ajax_contactForm.html" + preselectedOption,
		dataType :"html",
		success : function(html) {
			if (html.length > 0) {
				openShadowBox(878, 458, html, true);
			}
		}
	});
}

function openCatalogOrderInShadowBox() {
	$j.ajax( {
		type :"GET",
		url :baseUrl + "/ajax_catalogOrder.html",
		dataType :"html",
		success : function(html) {
			if (html.length > 0) {
				openShadowBox(1000, 670, html, true);
			}
		}
	});
}

function openIncentiveActionFragmentInShadowBox(fragmentWidth, fragmentHeight) {
	if($j(".incentiveActionFragment").length>0) {
		incentiveActionFragment = $j(".incentiveActionFragment").html();
		openShadowBox(fragmentWidth, fragmentHeight, incentiveActionFragment, false);		
	}
}

function openOutfitOrderInShadowBox(bundleId) {

	createGoogleEventTracking('Outfit Bestellung', 'Komplettes Outfit', null);
	
	$j.get(baseUrl + '/ajax_viewOutfitOrder.html',{bundleId:bundleId, lmPromo:'lmPromo=la,1,hk,DV,fl,Outfitorder'}, function(data) {
		Shadowbox.open({
			content:    data,
		    player:     "html",
		    handleOversize:    "none",
		    width: "770",
			modal :true,
		    height: "740",
		    options:  {
	           	onFinish: function(item){
	           		setSizeUpdateEvent();	           		
	           		setLandmark($j(".landmarkUrl").attr("data-url"));
	           		$j("#outfitOrder .infoSelects").each(function(){
	           			showAvailString($j(this));
	           		});
	           		initOutfitToBasketButton();
					if(iPad || iPhone) {
		           		var wScroll=$j(window).scrollTop();
						var wScrollCSS=wScroll+'px';
						$j('#shadowbox_container').css('top', wScrollCSS);
					}
	           	}
		    } 	
		});	 
	});
}

function openSmallOutfitOrderInShadowBox(articleNrs) {

	createGoogleEventTracking('Outfit Bestellung', 'Mix & Match OSutfit', null);
	
	$j.get(baseUrl + '/ajax_viewSmallOutfitOrder.html',{articleNrs:articleNrs, lmPromo:'lmPromo=la,1,hk,DV,fl,MixAndMatch'}, function(data) {
		Shadowbox.open({
			content:    data,
		    player:     "html",
		    handleOversize:    "none",
		    width: "580",
			modal :true,
		    height: "525",
		    options:  {
	           	onFinish: function(item){
	           		setSizeUpdateEvent();
	           		setLandmark($j(".landmarkUrl").attr("data-url"));
	           		$j("#outfitOrder .infoSelects").each(function(){
	           			if ($j(this).parent().find(".articleImg").length > 0) {
	           				var value = $j(this).parent().find(".articleImg").attr("value");
	           				if (value != "") {
    	           				if ($j(this).find(".selectPromoItemNew option").size() > 0) {
	    	           				$j(this).find(".selectPromoItemNew").val($j("#p_" + value).val());
	    	           				$j(this).find(".selectPromoItemNew").change();
	    	           			}
	           				}
	           			}
	           			showAvailString($j(this));
	           		});
	           		initOutfitToBasketButton();
	           	}
		    } 	
		});	 
	});
}

function weitereArtikel() {

	for ( var i = 0; i < 5; i++) {
		$j(".direktbestellung_vorlage").clone().insertBefore("#dbende");
		$j(".direktbestellung_vorlage").each( function(i) {
			if (i == 0) {
				$j(this).removeClass("direktbestellung_vorlage");
				$j(this).addClass("direktbestellung");
			}
		});
	}
	$j("input.artnr").each( function(i) {
		$j(this).attr("id", "orderItems[" + i + "].orderNr");
		$j(this).attr("name", "orderItems[" + i + "].orderNr");
	});
	$j("input.menge").each( function(j) {
		$j(this).attr("id", "orderItems[" + j + "].amount");
		$j(this).attr("name", "orderItems[" + j + "].amount");
	});
	$j("input.groesse").each( function(k) {
		$j(this).attr("id", "orderItems[" + k + "].size");
		$j(this).attr("name", "orderItems[" + k + "].size");
	});
	$j("label.labelartnr").each( function(l) {
		$j(this).attr("for", "orderItems[" + l + "].orderNr");
	});
	$j("label.labelmenge").each( function(m) {
		$j(this).attr("for", "orderItems[" + m + "].amount");
	});
	$j("label.labelgroesse").each( function(n) {
		$j(this).attr("for", "orderItems[" + n + "].size");
	});
	initWarenkorb();
};

function loeschenAbbrechen(obj) {
	obj.parent().fadeOut("fast").empty();
	return false;
}

function loescheObjekt(obj) {
	id = obj.parent().parent().attr("id");
	obj.parent().parent().fadeOut("fast").empty();
	$j("." + id).fadeOut("fast").empty();
	return false;
}

function aendernAbbrechen(obj) {
	infoSelects = obj.closest(".artikel_container");
	promoImg = infoSelects.find(".hidden_imgId").val();
	if (promoImg == "") {
		promoImg == "platzhalter_detailview_formatP";
	}
	imgSrc = "";
	imgSrc = infoSelects.find("img").attr("src");
	imgSrc = imgSrc.split("formatP")[0] + "formatP/" + promoImg + ".jpg";
	infoSelects.find("img").attr("src", imgSrc);
	obj.parent().parent().parent().parent().fadeOut("fast").empty();
	return false;
}

function loescheItem() {
	document.deleteItem.submit();
}

function aendereItem() { 
	if ($j("#selSize").val() != "0" && $j("#selectPromoItem").val() != "0") {
		document.changeItem.submit();
	} else {
		if ($j("#selectPromoItem").val() == "0") {
			if ($j(".selectModel").length > 0) {
				errorMessage("data-noStyling");
			} else {
				errorMessage("data-noColor");
			}
		} else {
			errorMessage("data-noSize");
		}
	}
}

function loescheMerklistenItem(obj) {
	$j.ajax( {
		type :"POST",
		url :baseUrl + "/ajax_deleteWatchListItem.html",
		data :"variationListItemIndex=" + $j("#toDelete").val(),
		dataType :"html",
		success : function(html) {
			if (html.length > 0) {
				setTimeout( function() {
					$j("#ml_metanavi").replaceWith(html)
				}, 1000);
			}
		}
	});
	obj.parent().fadeOut("fast").empty();
	$j("#mi_" + $j("#toDelete").val()).fadeOut('slow', function() {
		$j(this).remove()
	});
	decreaseWatchListDeleteIndex($j("#toDelete").val())
}

function initInBasketSelect() {
	if ($j(".selectModel").length <= 0) {
		$j(".selectPromoItemNew").unbind("change").change(function() {
			if ($j(this).val() != "0") {
				infoSelects = $j(this).closest(".artikel_container");
				promoImg = $j(this).find("option:selected").attr("id");
				if (promoImg != "999999") {
					imgSrc = "";
					imgSrc = infoSelects.find("img").attr("src");
					imgSrc = imgSrc.split("formatP")[0] + "formatP/" + promoImg + ".jpg";
					infoSelects.find("img").attr("src", imgSrc);
				}
				param = infoSelects.attr("id").split("_");
				infoSelects.children("div.change").load(baseUrl + "/ajax_changeitem.html", {
					lineItemId :param[1],
					selectedPromoItemId : $j(this).val()
				}, function() {
					// initSurchargeInformation();
				});
				infoSelects.children("div.change").fadeIn("fast");
			}
		});
	} else {
		$j(".selectModel").unbind("change").change(function() {
			if ($j(this).val() != "0") {
				infoSelects = $j(this).closest(".artikel_container");
				promoImg = $j(this).find("option:selected").attr("data");
				if (promoImg != "999999") {
					imgSrc = "";
					imgSrc = infoSelects.find("img").attr("src");
					imgSrc = imgSrc.split("formatP")[0] + "formatP/" + promoImg + ".jpg";
					infoSelects.find("img").attr("src", imgSrc);
				}
				
				param = infoSelects.attr("id").split("_");
				infoSelects.children("div.change").load(baseUrl + "/ajax_changeitem.html", {
					lineItemId :param[1],
					selectedDistinctColorItemId : $j(this).find("option:selected").val()
				}, function() {
					// initSurchargeInformation();
				});
				infoSelects.children("div.change").fadeIn("fast");
			}
		});
		
		$j(".selectPromoItem").unbind("change").change(function() {
			if ($j(this).val() != "0") {
				infoSelects=$j(this).closest(".artikel_container");
				param = infoSelects.attr("id").split("_");
				infoSelects.children("div.change").load(baseUrl + "/ajax_changeitem.html", {
					lineItemId :param[1],
					selectedModelItemId : $j(this).find("option:selected").val(),
					selectedDistinctColorItemId : infoSelects.find(".selectModel option:selected").val()
				}, function() {
					// initSurchargeInformation();
				});
				infoSelects.children("div.change").fadeIn("fast");
			}
		});
	}
}

function mainNavigationLayer() {

	$j("#topnavi li.tnav > a").unbind("mouseover");
	$j("#topnavi li.tnav > a").unbind("mouseout");
	$j("#topnavi li.tnav div > a").unbind("mouseover");
	$j("#topnavi li.tnav div > a").unbind("mouseout");
	$j(".suchbox").unbind("focus");
	var timerSubnav;

	var timerMainnav;

	$j("#topnavi li.tnav > a").mouseover( function() {
		actualNavi = $j(this)
	    clearTimeout(timerSubnav);
	    clearTimeout(timerMainnav);
	    if (actualNavi.parent().children('div').css('display')=='block') {
	    	isVisible = true;
	    } else {
	    	isVisible = false;
	    }
	    $j('#topnavi li.tnav > a').removeClass('aktiv')
	    $j('.subnav').hide();

	    if (isVisible) {
	    	actualNavi.parent().children('div').show();
	    } else {
		    timerMainnav = setTimeout("actualNavi.parent().children('div').fadeIn('fast')",300);
	    }

	  /*  navi_layer_seen = getCookie("navi_layer_seen");
	    if(!navi_layer_seen) {
	    	$j.ajax( {
				type :"POST",
				url : baseUrl + "/ado_save_outcome.html",
				data :"name=Alba_Moda_NAVI1_LayerNavi_Seen&value=True",
				dataType :"html",
				success : function(html) {
					setCookie("navi_layer_seen","true");
				}
		    });
	    }*/
	});
	$j("#topnavi li.tnav > a").mouseout( function() {
		clearTimeout(timerMainnav);
		timerSubnav = setTimeout("$j('.subnav').hide();$j('#topnavi li.tnav > a').removeClass('aktiv')", 300);
	});

	$j("#topnavi li.tnav div div, #topnavi li.tnav div h1, #topnavi li.tnav div > a, #topnavi li.tnav div.keyVisual, #topnavi li.tnav ul.topLevelNavi").mouseover(
			function() {
			    clearTimeout(timerSubnav);
				$j(this).parent("div").show();
				$j(this).parent().siblings("a").addClass("aktiv");
			});

	$j("#topnavi li.tnav div div, #topnavi li.tnav div h1, #topnavi li.tnav div > a, #topnavi li.tnav div.keyVisual, #topnavi li.tnav ul.topLevelNavi").mouseout(
			function() {
				timerSubnav = setTimeout("$j('.subnav').hide();$j('#topnavi li.tnav > a').removeClass('aktiv')", 300);
			});

	$j(".toCategory p").unbind("click").click(function(){
		location.href=$j(this).parent().parent().siblings("a").attr("href");
		return false;
		});
	
	$j(".suchbox").not("#content_home .suchbox").focus( function() {
		clearSearchBox($j(this));
	});

};

function clearSearchBox(fldObj) {
	query = $j(fldObj).val();
	if (query.indexOf("uchbegr") != -1) {
		$j(fldObj).val("");
	}
}

function initQuicklookButton() {	
	$j(".showProductQuickLook").unbind("click").click( function() {
		if ($j(this).attr("data-outfit") && ($j(this).attr("data-outfit").length > 0 && $j(this).attr("data-outfit") != 1)) {
			sb_height = "570"; 
		} else {
			sb_height = "410"; 
		}
		openProductQuickLookInShadowBox($j(this).attr("data-bundleId"), $j(this).attr("data-styleId"),sb_height);
		return false;
	});
	
}

function initDynamicLoading(){
	if (iPad || iPhone) {
		$j('.sbild a img').each(function(){
	    	if($j(this).attr('data-src')) {
	    		$j(this).hide();
	    		$j(this).attr("src",$j(this).attr('data-src'));
	    		$j(this).fadeIn("slow");
	    		$j(this).css("background","none")
	    	}	
		})
	} else {
/*		$j('.sbild a img').unbind('inview').bind('inview', function (event, visible) {
		    if (visible == true) {
		    	if($j(this).attr('data-src')) {
		    		$j(this).hide();
		    		$j(this).attr("src",$j(this).attr('data-src'));
		    		$j(this).fadeIn("slow");
		    		$j(this).css("background","none")
		    	}	
		        $j(this).unbind('inview');
		    }    
		});*/
	}	
}

function initRatingLink() {
	$j(".rating").unbind("click").click(function(){        
	    url = $j(this).siblings(".sbild").children("a").attr("href");
	    if(url && url != "undefined") {
	        location.href=url+"#ratings";;
	    }
	});
}


function initUebersichten() {
	initDynamicLoading();	
	initRatingLink();
	initQuicklookButton();

	$j("#content div.bundle > a").unbind("mouseover");
	$j("#content div.bundle > a").unbind("mouseout");
	$j("#content div.marke").unbind("mouseover");
	$j("#content div.marke").unbind("mouseout");
	$j("#content #categoryFilter span").unbind("mouseover");
	$j("#content #categoryFilter span").unbind("mouseout");
	$j("#content div.imglayer").unbind("mouseover");
	$j("#content div.imglayer").unbind("mouseout");
	$j("div.sbild").unbind("mouseover");
	$j("div.sbild").unbind("mouseout");

	if ($j(".sobercontainer").length > 0) {
		triggerImagesOfProductlist();
	}

	$j(".outfitListLink").unbind("click").click(function() {
		openOutfitOrderInShadowBox($j(this).attr("data-bid"));
		return false;
	});

	$j(".moreCategories").unbind("click").click(function() {
		$j(".moreCategories").hide();
		$j(".withoutActive").slideDown("fast");
		$j(".lessCategories").show();
		return false;
	});

	$j(".lessCategories").unbind("click").click(function() {
		$j(".lessCategories").hide();
		$j(".withoutActive").slideUp("fast");
		$j(".moreCategories").show();
		return false;
	});
	
	$j("#content #categoryFilter span").mouseover( function() {
		$j(this).children("div").show()
	});

	$j("#content #categoryFilter span").mouseout( function() {
		$j(this).children("div").hide()
	});

	$j("#content div.bundle > a").mouseover( function() {
		$j("div.bundle").each( function(i) {
			$j(this).addClass("zidown");
			$j(this).removeClass("ziup");
		});

		$j(this).parent("div").each( function(i) {
			$j(this).addClass("imglayer_show");
			$j(this).addClass("ziup");
			$j(this).removeClass("zidown");
			if ($j(this).position().left > 500)
				$j(this).addClass("imglayer_left");
		});
	});

	$j("#content div.bundle > a").mouseout( function() {
		$j(this).parent("div").each( function(i) {
			$j(this).removeClass("imglayer_show");
		});
	});

	$j("#content div.marke").mouseover( function() {
		$j(this).parent("div").each( function(i) {
			$j(this).addClass("imglayer_show");
			$j(this).addClass("ziup");
			$j(this).removeClass("zidown");
			if ($j(this).position().left > 500)
				$j(this).addClass("imglayer_left");
		});
		$j(this).parent("div").siblings().each( function(i) {
			$j(this).addClass("zidown");
			$j(this).removeClass("ziup");
		});
	});

	$j("#content div.marke").mouseout( function() {
		$j(this).parent("div").each( function(i) {
			$j(this).removeClass("imglayer_show");
		});
	});

	$j("#content div.imglayer").mouseover( function() {
		$j(this).parent("div").each( function(i) {
			$j(this).addClass("imglayer_show");
		});
	});

	$j("#content div.imglayer").mouseout( function() {
		$j(this).parent("div").each( function(i) {
			$j(this).removeClass("imglayer_show");
		});
	});

	$j("div.sbild").mouseover( function() {
		$j(this).addClass("show");
	});

	$j("div.sbild").mouseout( function() {
		$j(this).removeClass("show");
	});

};

/*
 * ##############################################################################
 * ######################### pager of images of productlist
 * #####################
 * ##############################################################################
 */
function triggerImagesOfProductlist() {
	$j("div.sbild").bind('mouseover.image', ( function() {
		$j(this).find("a.pager").show();
		$j(this).find("a.showProductQuickLook").show();
	}));

	$j("div.sbild").bind('mouseout.image', ( function() {
		$j(this).parent().find("a.pager").hide();
		$j(this).find("a.showProductQuickLook").hide();
	}));

	$j("div.sbild:not(.error)").each( function() {
		var $imageList = $j('.imageList', this).attr("data-imagelist");
		if ($imageList.length > 0) {
			var fileType = ".jpg";
			var currentImage = $j('div.sbild a img', this).attr("src");
			var images = $imageList.split("|");
			if (images.length > 1) {
				var $pager = $j('<span></span>').attr('class', 'imageButtons');
				var $prevLink = $j('<a></a>').attr( {
					'href' :'#',
					'class' :'pager prev'
				});
				var $nextLink = $j('<a></a>').attr( {
					'href' :'#',
					'class' :'pager next'
				});
				if (currentImage == images[images.length - 1]) {
					$nextLink.addClass('last');
				}
				$j(this).append($pager.append($prevLink).append($nextLink));
			}
		}
	});

	$j("div.sbild a.pager").bind('click.pager', ( function() {
		var action = $j(this).hasClass("next") ? "next" : "prev";
		handlePagerOfProductlistImage($j(this), action);
		return false;
	}));
}

function handlePagerOfProductlistImage($obj, action) {
	var $li = $obj.closest("div");
	var $image = $li.find("a img");
	var $imageList = $li.find('.imageList').attr("data-imagelist").split("|");
	var currentImage = $image.attr("src");
	if ($imageList.length > 0) {
		var positionOfCurrentImage = $imageList.indexOf(currentImage);
		var newImage = getImageOfProductlistImage($imageList,
				positionOfCurrentImage, action);
		$image.attr("src", newImage);
	}
}

function getImageOfProductlistImage($imageList, positionOfCurrentImage, action) {
	var index = positionOfCurrentImage;
	if (action == "next") {
		index++;
		if (index >= $imageList.length) {
			index = 0;
		}
	} else {
		index--;
		if (index < 0) {
			index = $imageList.length - 1;
		}
	}
	return $imageList[index];
}

function initWarenkorb() {

	/* Warenkorb */
	$j("#leftnavi .deliveryInfo").unbind("click");
	$j(".gesamtpreis > a").unbind("click");
	$j(".deleteLinkErrBox").unbind("click");
	$j(".changeLinkErrBox").unbind("click");
	$j(".basketChangeLink").unbind("click");
	$j(".checkoutChangeLink").unbind("click");
	$j(".checkDOForm").unbind("click");
	$j("#bestellcontent #lieferadresse").unbind("change");
	$j("#bestellcontent .ssl, #meinkonto .ssl").unbind("click");
	$j("#kreditkarte #pininfo").unbind("mouseover");
	$j("#kreditkarte #pininfo").unbind("mouseout");
	$j(".termine .sel_lieferdatum").unbind("change");
	$j("#bestellcontent .showInfo").unbind("mouseover");
	$j("#bestellcontent .showInfo").unbind("mouseout");
	$j("#bestellcontent .gutschein").unbind("focus");
	$j("#bestellcontent .chooseShippingAddress").unbind("click");
	$j("#belboon").unbind("click");
	$j("#chooseRates").unbind("click");
	$j(".showLoginCustNo").unbind("click");
	$j(".IAmcustomer").unbind("click");
	$j(".willBeCustomer").unbind("click");
	$j("#bestellcontent .showRevocation").unbind("click");
	
	$j("#bestellcontent .showRevocation").click( function() {
		openRevocationInShadowBox();
	});

	$j(".noPack").unbind("change").change( function() {
	    if($j(this).val().toLowerCase().indexOf("ackstation")>-1) {
	        alert("Packstationen sind als Lieferaddresse nicht zulässig!");
	        $j(this).val("");
	        return false;
	    }   
	});	
	
	$j(".noPack").unbind("mouseout").mouseout( function() {
	    if($j(this).val().toLowerCase().indexOf("ackstation")>-1) {
	        alert("Packstationen sind als Lieferaddresse nicht zulässig!");
	        $j(this).val("");
	        return false;
	    }   
	});	

	// workaround: IE6 does not show layer although width is set in css, so we
	// set it again with jquery
	$j("#addMissingArticleSizeWrapper").css("width", "565px");

	$j("#leftnavi .deliveryInfo, #meinkonto .deliveryInfo").click( function() {
		deliveryPopup(baseUrl + "/viewDeliveryInfo.html");
	});

	$j(".gesamtpreis > a").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		param = $j(this).parent().parent().attr("id").split("_");
		$j("#toDelete").val(param[1]);
		var obj = $j(this).parent().parent().children("div.delete");
		obj.html($j(".delete_container").html());
		obj.fadeIn("fast");
	});

	$j(".deleteLinkErrBox").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		param = $j(this).parent().parent().parent().attr("id").split("_");
		$j("#toDelete").val(param[1]);
		var obj = $j(this).parent().parent().parent().children("div.delete");
		obj.html($j(".delete_container").html());
		obj.fadeIn("fast");
	});

	$j(".changeLinkErrBox").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		$j(".artikel_container").removeClass("ziup");
		$j(".artikel_container").addClass("zidown");
		var container = $j(this).parent().parent().parent();
		container.removeClass("zidown");
		container.addClass("ziup");
		param = container.attr("id").split("_");
		var obj = $j(this).parent().parent().parent().children("div.change");
		var target = $j("#flowTargetUrl").html();

		obj.load(baseUrl + "/ajax_changeitem.html", {
			lineItemId :param[1],
			targetUrl :target
		});
		obj.fadeIn("fast");
	});

	$j(".basketChangeLink").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		$j(".artikel_container").removeClass("ziup");
		$j(".artikel_container").addClass("zidown");
		var container = $j(this).parent().parent();
		container.removeClass("zidown");
		container.addClass("ziup");
		param = container.attr("id").split("_");
		var obj = $j(this).parent().parent().children("div.change");
		obj.load(baseUrl + "/ajax_changeitem.html", {
			lineItemId :param[1]
		}, function() {
			// initAvailabilityInformation()
		});
		obj.fadeIn("fast");
	});

	$j(".checkoutChangeLink").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		$j(".artikel_container").removeClass("ziup");
		$j(".artikel_container").addClass("zidown");
		var container = $j(this).parent().parent();
		container.removeClass("zidown");
		container.addClass("ziup");
		param = container.attr("id").split("_");
		var obj = $j(this).parent().parent().children("div.change");
		var target = $j("#flowTargetUrl").html();

		obj.load(baseUrl + "/ajax_changeitem.html", {
			lineItemId :param[1],
			targetUrl :target
		});
		obj.fadeIn("fast");
	});

	$j(".checkDOForm").click( function() {
		var error_text = $j('#errorMessage').attr('data-invalidOrderNumber');
		error = false;
		filled = false;
		clickAllowed = true;
		$j('input.artnr').each( function(i, o) {
			artnr = $j(this).val().replace(" ","");
			$j(this).val(artnr.toUpperCase());
			if (artnr != "") {
				if (artnr.length < 7) {
					$j(this).css("border","1px solid red");
					error = true;
				} else {
					if (isNaN(artnr.substring(0, 6)) == true) {
						error = true;
						$j(this).css("border","1px solid red");
					} else {
						$j(this).css("border","1px solid #a9a9a9");
					}							
				}
			filled = true;
			}
		});
		if (error) {
			alert(error_text);
		} else {
			if (clickAllowed && filled) {
				clickAllowed = false;
				document.frmDirekt.submit();
				setTimeout("clickAllowed=true;", 30000);
			}
		}
	});

	$j("#bestellcontent #lieferadresse").change( function() {
		if ($j(this).val() != -1) {
			$j("#insadressbuch").hide();
			$j(".adresse").load(baseUrl + "/ajax_getCustomerAddress.html", {
				id :$j($j(this)).val()
			});
		} else {
			$j("#insadressbuch").show();
			$j(".adresse").load(baseUrl + "/ajax_getCustomerAddress.html");
		}
	});

	$j("#bestellcontent .ssl, #meinkonto .ssl").click(
		function() {
			if ($j(this).is(":checked")) {
				url = $j("form[name='login']").attr("action").replace(
						serverUrl, serverUrlSSL);
				$j("form[name='login']").attr("action", url);
			} else {
				url = $j("form[name='login']").attr("action").replace(
						serverUrlSSL, serverUrl);
				$j("form[name='login']").attr("action", url);
			}
		}
	);

/*
 * $j("input[name='paymentInfo']").click( function() { if ($j(this).val() ==
 * "CREDITCARD") { $j("#kreditkarte").slideDown("slow");
 * $j(".kredittrenner").slideDown("slow"); } else {
 * $j("#kreditkarte").slideUp("slow"); $j(".kredittrenner").slideUp("slow"); }
 * });
 */

	$j("#kreditkarte #pininfo").mouseover( function() {
		$j(".pininfo").fadeIn("fast");
	});

	$j("#kreditkarte #pininfo").mouseout( function() {
		$j(".pininfo").fadeOut("fast");
	});

	$j(".termine .sel_lieferdatum").change( function() {
		$j("#radio_ontime").prop("checked", true);
		$j(".termine .sel_lieferzeit").load(baseUrl + "/ajax_changedeliverytime.html", {
			date :$j($j(this)).val()
		});
	});

	$j("#bestellcontent .showInfo").mouseover( function(e) {
		targetDiv = $j(this).attr("rel");
		$j(targetDiv).fadeIn("fast");
		$j("iframe.rateninfoIframe").fadeIn("fast");
	});

	$j("#bestellcontent .showInfo").mouseout( function() {
		targetDiv = $j(this).attr("rel");
		$j("iframe.rateninfoIframe").fadeOut("fast");
		$j(targetDiv).fadeOut("fast");
	});

	$j("#bestellcontent .chooseShippingAddress").click( function() {
		$j("#ShipAddressId").val($j(this).attr("rel"));
		$j("#insadressbuch").hide();
		$j(".adresse").load(baseUrl + "/ajax_getCustomerAddress.html", {
			id :$j(this).attr("rel")
		}, function() {
			document.login.submit();
		});

	});

	$j("#bestellcontent .unsubscribeNewsletter").click(
		function() {
			$j("#subscribeNewsletter").hide();
			$j("#unSubscribeNewsletter").show();
			$j("input[name='newsletter']").val("0");
		}
	);

	$j("#chooseRates").click( function() {
		$j("#paymentRates").slideDown();
		if (!$j(":radio[value='INSTALLMENT_5']").prop("checked") && !$j(":radio[value='INSTALLMENT_7']").prop("checked")) {
			$j(":radio[value='INSTALLMENT_3']").prop("checked",true);
		}
	});
	$j(":radio[name='paymentInfo']").unbind("click").click(	function() {
		if ($j(":radio[value='INSTALLMENT_3']").prop("checked") || $j(":radio[value='INSTALLMENT_5']").prop("checked") || $j(":radio[value='INSTALLMENT_7']").prop("checked")) {
		
		} else {
			$j("#chooseRates").prop("checked", false);
			$j("#paymentRates").slideUp();
		}
	});

	$j(".isCustomer").click( function() {
		$j("#existingCustomerLogin").slideDown();
		$j(".auth_bottom").slideDown();
		$j("#loginSwitch").slideUp();
		$j(".co_continue").show();
		if ($j(":radio[value='new']").prop("checked")) {
			$j(":radio[value='loginEmail']").prop("checked", true);
		}
		$j(".button_left").addClass("auth_backlink");
	});

	$j(".auth_backlink").live("click", function() {
		$j("#existingCustomerLogin").slideUp();
		$j(".auth_bottom").slideUp();
		$j("#errMissing").slideUp();
		$j("#loginSwitch").slideDown();
		$j(".co_continue").hide();
		$j(":radio[value='new']").prop("checked", true);
		$j(".button_left").removeClass("auth_backlink");
		$j("span").removeClass("error");
		return false;
	});
	
	$j(".willBeCustomer").click( function() {
		$j(":radio[value='new']").prop("checked", true);
		document.login.submit();
	});
	$j(".checkout_button a, #loginSwitch a").live("mousedown", function(){
		$j(this).addClass("aktiv");
	})

	$j(".checkout_button a, #loginSwitch a").live("mouseup", function(){
		$j(this).removeClass("aktiv");
	})
	
};

function initQuickviewWarenkorb() {
	var timerQVBclose;
	var timerQVBopen;


	if ($j("#content_checkout").length == 0) {
	    clearTimeout(timerQVBclose);
	    clearTimeout(timerQVBopen);

	   $j('#quickviewBasket').css("display","block");
	   $j('#quickviewBasket').css("top","-10000px");

	   $j(".warenkorb, #quickviewBasket").unbind("mouseover").mouseover(function() {
		    clearTimeout(timerQVBclose);
		    if($j("#quickviewBasket li.jcarousel-item-placeholder").size() > 0) {
		    	$j('#quickviewBasket').css('display', 'none');
		    } else {
		    	if ($j("#quickviewBasket li").size() > 0) {
		    		timerQVBopen = setTimeout("$j('#quickviewBasket').css('display', 'block')", 300);
		    	}
		    }
/*
 * blu_set = getCookie("blu_set"); if(!blu_set && $j(".articlesList li").size() >
 * 0) { $j.ajax( { type :"POST", url : baseUrl + "/ado_save_outcome.html", data
 * :"name=Basket_Layer_Seen&value=True", dataType :"html", success :
 * function(html) { setCookie("blu_set","true"); } }); }
 */
	   });
   
	   $j(".warenkorb, #quickviewBasket").unbind("mouseout").mouseout(function(){
			timerQVBclose = setTimeout("$j('#quickviewBasket').css('display', 'none')", 300);
 	   });
		   
	   
		if($j(".articlesListHorizontal").size() > 0) {
			$j('.articlesListHorizontal .articlesList').jcarousel({
		        scroll: 3
			});
			$j(".articlesListHorizontal .jcarousel-prev").html('<img src="' + rcContextPath + '/images/app/common/bttn/qv_left.png">');
			$j(".articlesListHorizontal .jcarousel-next").html('<img src="' + rcContextPath + '/images/app/common/bttn/qv_right.png">');
		}
	   $j('#quickviewBasket').css("display","none");
	   $j('#quickviewBasket').css("top","48px");
	   
	   
	   $j("#quickviewBasket .angaben").unbind("click").click(function() {
		   $j(".delete").hide();
		   var obj = $j(this).parent().parent().siblings(".delete");
		   obj.css("height","160px");
  	       obj.css("padding","18px 3px 0 7px");
		   obj.css("right","0px");
		   obj.css("top","0px");
		   obj.html($j("#quickviewBasket .delete_container_quickview").html());
		   obj.fadeIn("fast");
	   })
	   
	   $j("#quickviewBasket .loeschen").die().live("click", function(){ 
		   lineItemId = $j(this).parent().attr("data-line-item-id");
			$j("#quickviewBasket").load(baseUrl + "/ajaxDeleteQuickViewBasketLineItem.html",{
					lineItemId :lineItemId
				},
				function (result, textStatus, XMLHttpRequest) {
					initQuickviewWarenkorb();	
				    if($j("#quickviewBasket li.jcarousel-item-placeholder").size() > 0) {
				    	$j('#quickviewBasket').css("display","none");
				    } else {
				    	$j('#quickviewBasket').css("display","block");
				    } 	
				}				
			);

	   });
	}
	
	$j('#quickviewBasket .jcarousel-list li:first').css("border-left", "1px solid #B8B3A4");
}

function articlesListVertical_itemLoadCallback(carousel)
{
	if($j(".articlesListVertical .jcarousel-prev-disabled").size() > 0) {
		$j(".articlesListVertical").css("padding-top","0px");
	} else {
		$j(".articlesListVertical").css("padding-top","22px");		
	}
};	


function initMeinKonto() {

	$j("#kennwort a").unbind("click");
	$j("#meinkonto .change").unbind("click");
	$j("#meinkonto .adresseSpeichern").unbind("click");
	$j("#meinkonto .adresseAendern").unbind("click");
	$j("#meinkonto .la_loeschen").unbind("click");
	$j("#meinkonto .loesche_adresse").unbind("click");
	$j("#meinkonto .showCancelOrder").unbind("click");
	$j("#meinkonto .cancelOrder").unbind("click");
	$j("#meinkonto .createPin").unbind("click");

	$j("#kennwort a").click( function() {
		$j(this).parent().hide();
		$j("#kennwort_neu").show();
	});

	$j("#meinkonto .change").click( function() {
		$j("#addressForm").load(baseUrl + "/ajax_changeAddressBookAddress.html", {
			index :$j(this).parent().attr("label")
		});
	});

	$j("#meinkonto .adresseSpeichern").click( function() {
		$j("#addressForm").submit();
	});

	$j("#meinkonto .adresseAendern").click( function() {
		$j("#customerForm").submit();
	});

	$j("#meinkonto .la_loeschen").click( function() {
		$j(".delete").empty().fadeOut("fast");
		var obj = $j(this).parent().children("div.delete");
		obj.html($j(".delete_container").html());
		obj.fadeIn("fast");
		initMeinKonto();
	});

	$j("#meinkonto .loesche_adresse").click( function() {
		var obj = $j(this);
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_deleteAddressBookAddress.html",
			data :"index=" + $j(this).parent().parent().attr("label"),
			dataType :"html",
			success : function(html) {
				$j(".trenner_" + obj.parent().parent().attr("label")).remove();
				obj.parent().parent().fadeOut('slow');
				setTimeout(obj.parent().parent().remove(), 2000);
				i = 0;
				$j(".lieferadresse").each( function() {
					$j(this).attr("label", i);
					i += 1;
				});
				i = 0;
				$j(".tkurz").each( function() {
					$j(this).removeClass("trenner_" + i);
					$j(this).removeClass("trenner_" + (i + 1));
					$j(this).addClass("trenner_" + i);
					i += 1;
				});
			}
		});
	});

	$j("#meinkonto .showCancelOrder").click( function() {
		$j(".delete").empty().fadeOut("fast");
		var obj = $j(this).parent().parent().children("div.delete");
		obj.html($j(".delete_container").html());

		obj.fadeIn("fast");
		initMeinKonto();
	});

	$j("#meinkonto .cancelOrder").click( function() {
		parts = $j(this).parent().parent().attr("id").split("_");
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_cancelOrder.html",
			data :"orderId=" + parts[0] + "&orderDetailId=" + parts[1]
					+ "&articelNumber=" + parts[2],
			dataType :"html",
			success : function(html) {
				$j(".delete").html(html);
			}
		});
	});

	$j("#meinkonto .createPin").click( function() {
		$j.ajax( {
			type :"POST",
			url :baseUrl + "/ajax_createPin.html",
			dataType :"html",
			success : function(html) {
				openShadowBox(450, 200, html, false);
			}
		});
	});
}

function showAddressChangeSb() {
	html = $j("#changedAddress").html();
	openShadowBox(440, 200, html, false);
	setTimeout( function() {
		Shadowbox.close()
	}, 8000);
}

function initMerkliste() {
	$j("#ml_show_sendlayer").unbind("click");
	$j("#kml_indenwk").unbind("click");
	$j("#ml_print").unbind("click");
	$j(".m_loeschen").unbind("click");
	$j(".m_basket").unbind("click");

	$j("#ml_show_sendlayer").click( function() {
		$j("#send_container").load(baseUrl + "/ajax_sendWatchList.html");
		$j("#send_container").fadeIn("middle");
	})

	$j("#kml_indenwk").click( function() {
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_addCompleteWatchListToBasket.html",
			dataType :"html",
			success : function(html, textStatus) {
				if (html.length > 0) {
					parts = html.split("<split/>");
					$j("#indenwk").html(parts[0]);
					$j("#indenwk").fadeIn("middle");
					$j('#indenwk').mouseleave( function() {
						$j(this).fadeOut('slow');
					});
					$j("#ml_metanavi").replaceWith(parts[1]);
					$j(".m_basket").parent().parent(".artikel_container").fadeOut("slow");
					setTimeout( function() {
						$j(".m_basket").parent().parent(".artikel_container").remove();
					}, 2000);
					$j("#quickviewBasket").load(baseUrl + "/ajaxRefreshQuickViewBasket.html",
						function (result, textStatus, XMLHttpRequest) {
							initQuickviewWarenkorb();				
						}				
					);
				}
				if (textStatus == "success") {
					refreshMinibasket(-1);
				}
			}
		});
        $j(".watchlistLink").html(" (0)");
	})

	$j("#ml_print").click( function() {
		printWatchListPopup("printWatchList.html");
	})

	$j(".m_loeschen").click( function() {
		$j(".delete").empty().fadeOut("fast");
		$j(".change").empty().fadeOut("fast");
		parts = $j(this).attr("id").split("_");
		$j("#toDelete").val(parts[1]);
		var obj = $j(this).parent().parent().children("div.delete");
		obj.html($j(".delete_container").html());
		obj.fadeIn("fast");
	});

	$j(".m_basket").click( function() {
		params = $j(this).attr("id").split("_");

		$j.get(baseUrl + '/ajax_addtobasket.html',{vid :params[1],bid :$j(this).attr("label").replace("indwk_", ""),amount:"1",variationListItemIndex :params[3]}, function(data) {
		    Shadowbox.open({
		        content:    data,
		        player:     "html",
		        handleOversize:    "none",
		        width: "286",
		        height: "260",
		        options:    {
		           overlayOpacity:0.3,
	               onFinish: function(item){
	            	   copyInMinibasket();
						$j("#quickviewBasket").load(baseUrl + "/ajaxRefreshQuickViewBasket.html",
							function (result, textStatus, XMLHttpRequest) {
								initQuickviewWarenkorb();				
							}				
						);
	            	   
	               }
		        } 	
		    });	 	    
		});			
		
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_deleteWatchListItem.html",
			data :"variationListItemIndex=" + params[3],
			dataType :"html",
			success : function(html) {
				if (html.length > 0) {
					setTimeout( function() {
						$j("#ml_metanavi").replaceWith(html)
					}, 1000);
				}
			}
		});
		$j(this).parent().parent().fadeOut('middle', function() {
			$j(this).remove()
		});
		decreaseWatchListDeleteIndex(params[3]);
	});

}
function initCanvass() {
	$j("#fwQuickFillIn").unbind("click");
	$j("#fwQuickFillIn").click( function() {
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_viewCanvassLogin.html",
			dataType :"html",
			success : function(html) {
				openShadowBox(640, 385, html, false);
			}
		});
	});
}
function loginCanvass() {
	if ($j('#fw_CustomerNumber').val().length > 5
			&& $j('#fw_Birthday').val().length > 5) {
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_canvassLogin.html",
			data :"&customerNumber=" + $j('#fw_CustomerNumber').val()
					+ "&birthday=" + splitBirthday($j('#fw_Birthday').val()),
			dataType :"html",
			success : function(html) {
				$j("#addressData").html(html);
			}
		});
	} else if ($j('#fw_Email').val().length > 5
			&& $j('#fw_Password').val().length > 3) {
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_canvassLogin.html",
			data :"&email=" + $j('#fw_Email').val() + "&password="
					+ $j('#fw_Password').val(),
			dataType :"html",
			success : function(html) {
				$j("#addressData").html(html);
			}
		});
	}
}
function showInvalidCanvass() {
	html = $j("#invalidCanvass").html();
	openShadowBox(440, 200, html, false);
}

function showCanvassLoginError() {
	$j("#shadowbox_content #canvLoginError").html($j("#cError").html());
}

function fillCanvassForm() {
	if ($j("#cSalutation").html() == "Mr.") {
		$j("#herr").attr("checked", "true");
	} else {
		$j("#frau").attr("checked", "true");
	}
	$j("input[name='firstName']").val($j("#cName").html());
	$j("input[name='lastName']").val($j("#cLastName").html());
	$j("input[name='streetName']").val($j("#cStreetName").html());
	$j("input[name='houseNumber']").val($j("#cHouseNumber").html());
	$j("input[name='postalCode']").val($j("#cPostalCode").html());
	$j("input[name='city']").val($j("#cCity").html());
	$j("input[name='email']").val($j("#cEmail").html());
	$j("input[name='additionalInformation']").val($j("#cAddition").html());
	$j("input[name='birthday']").val($j("#cBirthday").html());
	$j("input[name='phonePrefix']").val($j("#cPhonePrefix").html());
	$j("input[name='phoneNumber']").val($j("#cPhoneNumber").html());

}

function decreaseWatchListDeleteIndex(deletedIndex) {
	$j(".links a.m_basket").each( function() {
		idParts = $j(this).attr("id").split("_");
		if (parseInt(idParts[3]) > parseInt(deletedIndex)) {
			idParts[3]--;
		}
		$j(this).attr("id", idParts.join("_"));
	});

	$j(".links a.m_loeschen").each( function() {
		idParts = $j(this).attr("id").split("_");
		if (parseInt(idParts[1]) > parseInt(deletedIndex)) {
			idParts[1]--;
		}
		$j(this).attr("id", idParts.join("_"));
	});

	$j("#ml_items .artikel_container").each( function() {
		idParts = $j(this).attr("id").split("_");
		if (parseInt(idParts[1]) > parseInt(deletedIndex)) {
			idParts[1]--;
		}
		$j(this).attr("id", idParts.join("_"));
	});
	
    count_watchlist = $j("#ml_items .artikel_container").length-1;
    $j(".watchlistLink").html(" (" + count_watchlist + ")");
}

function initSendWatchListFormLink() {
	$j("#ml_send").unbind("click");
	$j("#ml_send").click( function() {
		$j("#progress_container").show();
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_sendWatchList.html",
			data :$j("#sendWatchListForm").serialize(),
			dataType :"html",
			success : function(html) {
				$j("#send_container").html(html);
				if (!$j("div .error").text().length > 0) {
					setTimeout("$j('#send_container').fadeOut('middle');",3000);
				}
			},
			complete : function() {
				$j("#progress_container").hide();
			}
		});
	})
}

function initSendWatchListFormCancel() {
	$j("#ml_send_cancel").unbind("click");
	$j("#ml_send_cancel").click( function() {
		$j("#sendWatchListForm :input").val("");
		$j("#sendWatchListForm textarea").val("");
		$j("#send_container").fadeOut("middle");
	})

}

function initSurchargeInformation() {
	if ($j("#inputPromoItem").attr("alt") != undefined && $j("#inputPromoItem").attr("alt").length > 0) {
		$j("#surchargeInformationContainer #surchargeInformation").text(
		$j("#inputPromoItem").attr("alt"));
		$j("#surchargeInformationContainer").show();
	} else if ($j("#selectPromoItem option:selected").attr("alt") != undefined && $j("#selectPromoItem option:selected").attr("alt").length > 0) {
		$j("#surchargeInformationContainer #surchargeInformation").text(
		$j("#selectPromoItem option:selected").attr("alt"));
		$j("#surchargeInformationContainer").show();
	} else {
		$j("#surchargeInformationContainer").hide();
	}
}

function initSuggestSearch() {
	$j("#queryString").autocomplete(baseUrl + "/ajax_suggestSearch.html", {
		width :260,
		minChars :2,
		selectFirst :false
	});
}

function initSearch() {
	
	initDynamicLoading();
	initRatingLink();	

	$j("#minAvailCode").unbind("change");
	$j("#sortType").unbind("change");
	$j("#resultsPerPage").unbind("change");
	$j(".priceFilterBttn").unbind("click");
	
	if ($j("#productSearch").length > 0 || $j(".searchNavigation").length > 0) {
		searchFilter.triggerFilter();
		searchFilter.setFilter();
	} else {
		
		$j(".priceFilterBttn").click( function() {
			url = $j("#priceFilter").attr("action");
			if ($j("#minPrice").attr("value").length > 0) {
				url = url + "&minPrice=" + $j("#minPrice").attr("value");
			}
			if ($j("#maxPrice").attr("value").length > 0) {
				url = url + "&maxPrice=" + $j("#maxPrice").attr("value");
			}
			location.href = url;
		});
		$j("#minAvailCode").change( function() {
			url = $j("#minAvailCode").attr("label") + "&minAvailCode=" + $j(this).val();
			location.href = url;
		});
		$j("#sortType").change( function() {
			url = $j("#sortType").attr("label") + "&sortType=" + $j(this).val();
			location.href = url;
		});
		$j("#resultsPerPage").change( function() {
			url = $j("#resultsPerPage").attr("label") + "&resultsPerPage=" + $j(this).val();
			location.href = url;
		});
	}	
}

function initSchuhAmpel() {

	$j("#outfitBestellen").live("click", function() {
		actOutfit = mf.getCurrent().title;
		actShoe = mf2.getCurrent().title;
		$j("#completeOutfitForm").html();
		outfits = artikel[actOutfit][6].split(";");
		form = '<input type="hidden" id="orderItems[0].orderNr" name="orderItems[0].orderNr" value="' + actShoe + '"><input class="menge" type="hidden" name="orderItems[0].amount" id="orderItems[0].amount" value="1" >';
		for (i = 0; i < outfits.length; i++) {
			form = form
				+ '<input type="hidden" id="orderItems['
				+ (i + 1)
				+ '].orderNr" name="orderItems['
				+ (i + 1)
				+ '].orderNr" value="'
				+ outfits[i]
				+ '"><input class="menge" type="hidden" name="orderItems['
				+ (i + 1) + '].amount" id="orderItems['
				+ (i + 1) + '].amount" value="1" >';
		}
		$j("#completeOutfitForm").html(form);
	});
}

function initTellAFriendFormLink() {
	$j("#taf_send").unbind("click");
	$j("#taf_send").click( function() {
		$j("#progress_container").show();
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_tellAFriend.html",
			data :$j("#tellAFriendForm").serialize(),
			dataType :"html",
			success : function(html) {
				$j("#sendContainer").html(html);
			},complete : function() {
				$j("#progress_container").hide();
				if ($j("#taf_success").text() != "") {
					setTimeout("$j('.productContainer #sendContainer').fadeOut('middle');",3000);
				}
			}
		});
	})
}

function initTellAFriendFormCancel() {
	$j("#taf_send_cancel").unbind("click");
	$j("#taf_send_cancel").click( function() {
		$j("#tellAFriendForm :input").val("");
		$j("#tellAFriendForm textarea").val("");
		$j("#send_container").fadeOut("middle");
	})
}

function initSendBasketMailFormLink() {
	$j("#basketmail_send").unbind("click");
	$j("#basketmail_send").click( function() {
		$j("#progress_container").show();
		$j.ajax( {
			type :"POST",
			url : baseUrl + "/ajax_sendBasketAsEmail.html",
			data :$j("#sendBasketMailForm").serialize(),
			dataType :"html",
			success : function(html) {
				$j("#sendContainer").html(html);
			},complete : function() {
				$j("#progress_container").hide();
				if ($j("#basketmail_success").text() != "") {
					setTimeout("$j('#bestellcontent #sendContainer').fadeOut('middle');",3000);
				}
			}
		});
	})
}

function initSendBasketMailFormCancel() {
	$j("#basketmail_send_cancel").unbind("click");
	$j("#basketmail_send_cancel").click( function() {
		$j("#sendBasketMailForm :input").val("");
		$j("#send_container").fadeOut("middle");
	})
}

function initMasstabelle() {
	$j("a.messtechnik").click( function(e) {
		targetDiv = $j(this).attr("rel");
		$j(targetDiv).css("top", e.pageY + "px");
		$j(targetDiv).show()
	});
}

function closeMesstechnik(targetDiv) {
	$j("#" + targetDiv).hide();
}

function sendContactForm() {
	$j("#progress_container").show();
	$j.ajax( {
		type :"POST",
		url : baseUrl + "/ajax_contactForm.html",
		data :$j("#contactForm").serialize(),
		dataType :"html",
		success : function(html) {
			$j("#contact-form").replaceWith(html);
			if ($j("#cf-success").length > 0) {
				setTimeout("Shadowbox.close();", 3000);
			}
		},
		complete : function() {
			$j("#progress_container").hide();
		}
	});
}

function sendCatalogOrderForm() {
	$j("#progress_container").show();
	$j.ajax( {
		type :"POST",
		url :baseUrl + "/ajax_catalogOrder.html",
		data :$j("#catalog-order-form").serialize(),
		dataType :"html",
		success : function(html) {
			$j("#catalog-order-form-container").replaceWith(html);
			if ($j("#cof-success").length > 0) {
				setTimeout("Shadowbox.close();", 3000);
			}
		},
		complete : function() {
			$j("#progress_container").hide();
		}
	});
}

function sendPasswordRequest() {
	$j("#progress_container").show();
	$j.ajax( {
		type :"POST",
		url : baseUrl + "/ajax_sendPassword.html",
		data :$j("#sendPasswordForm").serialize(),
		dataType :"html",
		success : function(html) {
			$j("#sendPassword-form").replaceWith(html);
		},
		complete : function() {
			$j("#progress_container").hide();
		}
	});
}

function addStyleToRecentlyViewedList(bid, sid) {
	if ("" != bid && "" != sid) {
		$j.ajax( {
			type :"POST",
			url :baseUrl + "/ajax_addToRecentlyViewedList.html",
			data :"bid=" + bid + "&sid=" + sid
		});
	}
}

function errorMessage(msg) {
	message = $j("#errorMessage").attr(msg);
	$j("#errMissing").html(message).fadeIn("fast");
	$j("#ifr").fadeIn("fast");
	setTimeout("$j('#errMissing').fadeOut('fast');", 1000);
	setTimeout("$j('#ifr').fadeOut('fast');", 1000);		
}


function copyInMinibasket() {
	$j(".basketSum").html($j("#intasche").html());
// $j(".warenkorb").removeClass("emptyBasket");
// $j(".warenkorb").addClass("filledBasket");
}

function copyInWatchList(){
    $j(".watchlistLink").html(" (" + $j("#watchlistSize").html() + ")");
}

function resizeRecommendationImageContainer() {
	maxImageHeight = 0;
	$j("div.recommendationImageContainer img").each( function() {
		if ($j(this).height() > maxImageHeight) {
			maxImageHeight = $j(this).height();
		}
	});
	$j("div.recommendationImageContainer").css("height", maxImageHeight + 5);
}

function showPaymentConditions() {
	html = $j("#agb").html();
	openShadowBox(500, 400, html, false);
}

function acceptPC() {
	if (!$j("input[name='installmentTerms']").is(":checked")) {
		$j("input[name='installmentTerms']").attr("checked", "true")		
	}
	Shadowbox.close();
	checkPC();
}

function backPC() {
	$j(".agb1").show();
	$j(".agb2").hide();
}

function deniePC() {
	$j(".agb1").hide();
	$j(".agb2").show();
}

function closePC() {
	if ($j("input[name='installmentTerms']").is(":checked")) {
		$j("input[name='installmentTerms']").click();
	}
	$j(".invoice").click();
	$j("#chooseRates").prop("checked", false);
	$j("#paymentRates").slideUp();
	$j(".agb1").show();
	$j(".agb2").hide();
	Shadowbox.close();
}

function checkPC() {
	if ($j(".rates").is(":checked")
			&& !$j("input[name='installmentTerms']").is(":checked")) {
		showPaymentConditions();
	} else {
		document.services.submit();
	}
}

function redirectToSearchEngine(redirectUrl, query) {
	redirectUrlWithQuery = redirectUrl + "&query=" + query;

	if (navigator.appVersion.indexOf("MSIE") > -1 || document.location.replace) {
		document.location.replace(redirectUrlWithQuery);
	} else {
		document.location.href = redirectUrlWithQuery;
	}
}

function zoomPopup(dest) {
	sizePopup(dest, 'zoom', '600', '580', '10', '400');
}
function printArticleInformationPopup(dest) {
	sizePopup(dest, 'articleInformation', '650', '700', '10', '10');
}
function printWatchListPopup(dest) {
	sizePopup(dest, 'watchlist', '600', '700', '10', '10');
}
function printAccountPopup(dest) {
	sizePopup(dest, 'account', '610', '700', '10', '10');
}
function callbackPopup(dest) {
	fixedPopup(dest, 'callback', '540', '300', '370', '250');
}
function deliveryPopup(dest) {
	sizePopup(dest, 'delivery', '700', '450', '370', '250');
}
function companyPopup(dest) {
	sizePopup(dest, 'company', '1204', '768', '0', '0');
}

function sizePopup(url, name, w, h, t, l) {
	popup(url, 'width=' + w + ',height=' + h + ',toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=' + l + ',top=' + t + '', name);
}

function fixedPopup(url, name, w, h, t, l) {
	popup(url, 'width=' + w + ',height=' + h + ',toolbar=0,menubar=0,resizable=0,scrollbars=0,status=0,left=' + l + ',top=' + t + '', name);
}

// Popup-Basisfunktion
function popup(url, optionen, popupName) {
	popupName = window.open(url, popupName, optionen);
	if (popupName) {
		if (popupName.focus) {
			popupName.focus();
		}	
	}
	return false;
}

// Shadowbox-Basisfunktion

function openShadowBox(boxWidth, boxHeight, content, modal) {
	Shadowbox.open( {
		player :'html',
		title :'',
		content :content,
		width :boxWidth,
		height :boxHeight
	}, {
		animate :true,
		overlayOpacity :0.3,
		modal :modal,
		enableKeys :false,
		handleOversize :'none'
	});
}

function openIframeShadowBox(boxWidth, boxHeight, content, modal) {
	Shadowbox.open( {
		player :'iframe',
		title :'',
		content :content,
		width :boxWidth,
		height :boxHeight
	}, {
		animate :true,
		overlayOpacity :0.3,
		modal :modal,
		enableKeys :false,
		handleOversize :'none'
	});
}

function printShadowbox() {
	if (shadowbox_content) {
		shadowbox_content.print();
	}
}

function splitBirthday(formValue) {
	var Satz = formValue;
	Satz = Satz.replace(/,/g, ".");
	var Woerter = Satz.split(".");
	if (Woerter.length == 3) {
		if (Woerter[0].length == 1) {
			Woerter[0] = "0" + Woerter[0];
		}	
		if (Woerter[1].length == 1) {
			Woerter[1] = "0" + Woerter[1];
		}	
		if (Woerter[2].length == 2) {
			Woerter[2] = "19" + Woerter[2];
		}	
		formValue = Woerter[0] + "." + Woerter[1] + "." + Woerter[2];
	} else {
		if (Woerter.length == 1 && Satz.length == 8) {
			formValue = Satz.substr(0, 2) + "." + Satz.substr(2, 2) + "." + Satz.substr(4, 4);
		} else if (Woerter.length == 1 && Satz.length == 6) {
			formValue = Satz.substr(0, 2) + "." + Satz.substr(2, 2) + ".19" + Satz.substr(4, 2);
		}
	}
	return formValue;
}

function eraseCookie(name) {
	setCookie(name, "", -1);
}

function setCookie(name, value, expiresInDays) {
	var expires = "";
	var domain = "";

	if (expiresInDays) {
		var date = new Date();
		date.setTime(date.getTime() + (expiresInDays * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	}

	if (cookieDomain) {
		domain = "; domain=" + cookieDomain 
	}

	document.cookie = name + "=" + value + expires + "; path=/" + domain;
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for ( var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}

	return null;
}

function specifyInBasket() {
	$j(".inBasket").each( function() {
		if (!$j(this).is(':checked')) {
			$j(this).parent().siblings('.right').find(".count").val("0");
			lastsize = $j(this).parent().siblings('.right').find(".selectMissingSize option:last").val();
			$j(this).parent().siblings('.right').find(".selectMissingSize").val(lastsize);
		}
	});
	$j('#addMissingSize').submit();
}

function insertLayoutFragments() {
	$j(".insertLF").each( function() {
		name = $j(this).attr("rel");
		page = $j(this);
		$j.ajax( {
			type :"GET",
			url :baseUrl + "/extern/3/" + name + ".html",
			dataType :"html",
			success : function(html) {
				if (html.length > 0) {
					page.html(html);
					page.removeClass("insertLF");
				}
			}
		});
	});
}

/* New QuickLook Start */

function initQuickLook(){

	actImg = $j("#grossbild").attr("src");
	
	$j("#productQuickLook .infoSelects").each(function(){
		showAvailString($j(this));
	});
	
	$j("#quickLookContainer .rating").unbind("click").click(function(){        
	    url = $j(this).parent().attr("data-href");
	    if(url && url != "undefined") {
	        location.href=url+"#ratings";;
	    }
	});
	
	$j(".outfitShoppen").unbind("click").click(function() {
		openOutfitOrderInShadowBox($j("#bid").val());
		return false;
	});

	$j(".changePicBySelectedColor").unbind("click").click(function(){
		changeImagesNew($j("#"+$j(this).attr("data-imguri")));
	});
	
	initButtonDv();
	
	imgChange = true;
	setSizeUpdateEvent();

/*
 * $j("#selectPromoItemNew").live("change", function() {
 * initSurchargeInformation(); });
 */
}

/* New Detailview Start */

function initZoom() {
	$j('#zoomCarousel').jcarousel({
        vertical: true,
        scroll: 5,
        itemLoadCallback: zoomCarousel_itemLoadCallback
	});
	
	$j("#zoomCarouselContainer .jcarousel-prev").html('<img src="' + rcContextPath + '/images/app/common/bttn/bttn_car_up.png">');
	$j("#zoomCarouselContainer .jcarousel-next").html('<img src="' + rcContextPath + '/images/app/common/bttn/bttn_car_down.png">');
	$j('#zoomCarouselContainer').css("visibility","visible");
	$j("#DEBUG").hide();
	$j("#zoomCarousel img").live("click", function(){
		var zoom = $j(this).attr("data-zoom");
		showZoom(zoom);
		// $j("#zoomImg").html('<iframe width="650" height="650" frameborder="0"
		// src="viewZoom.html?zoomImg='+zoom+'">');
		//createGoogleEventTracking('Bilder', 'Angeklickt', caculatePicNameFromSrc(this));
	});
	
}

function showZoom(imgUrl) {
   var zv = new ZoomoViewer();
   zv.serverName = 'http://albamoda.zoomoviewer.com',
   zv.clientID = 6529;
   zv.width = 620;
   zv.height = 586;
   zv.addPlugIn("gui_albamoda");
   zv.addImage(imgUrl);
   zv.start('#zoomo');
}

function zoomCarousel_itemLoadCallback(carousel)
{
	if($j("#zoomCarouselContainer .jcarousel-prev-disabled").size() > 0) {
		$j("#zoomCarouselContainer").css("padding-top","10px");
	} else {
		$j("#zoomCarouselContainer").css("padding-top","32px");		
	}
};	


function imgCarousel_itemLoadCallback(carousel)
{
	if($j("#imgCarouselContainer .jcarousel-prev-disabled").size() > 0) {
		$j("#imgCarouselContainer").css("padding-top","0px");
	} else {
		$j("#imgCarouselContainer").css("padding-top","22px");		
	}
};	

function initDetailview() {

	showAvailString($j(".infoSelects"));
	
	$j("#outfitContainer ul li a").click(
		function() {
			$j(".productContainerOutfits #infoContainer .loader").show();
			$j.ajax({
				type : "POST",
	            dataType: "xml",
				url : $j(this).attr("href"),
				success : function() {
					initButtonDv();
					setSizeUpdateEvent();
					infoSelects=$j(".productContainerOutfits #infoContainer .articleInfos .infoSelects");
					showAvailString(infoSelects);
					return false;
				}
			});
			return false;
		}
	);
	
	$j(".outfitShoppen").click(function() {
		openOutfitOrderInShadowBox($j("#bid").val());
		return false;
	});

	
	$j("#videoLink").live("click", function() {
		name = $j(this).attr("data-video");
		openIframeShadowBox(302,430,"viewVideo.html?video="+name);
		return false;
	});

	$j("#zoomLink,#largeImage").live("click", function() {
		var url = $j("#zoomLink").attr("data-url");
		var name = $j("#grossbild").attr("data-zoom");	
		
		if(name.length < 5) {
			$j("#imgCarousel li img").each(function(){
				if($j(this).attr("data-zoom").length > 5) {
					name=$j(this).attr("data-zoom");
					return false;
				}
			});
		}
		if(name.length > 4) {
			openIframeShadowBox(815,705,url+"&zoomImg="+name);
		}	
		return false;
	});

	$j(".promoItemPic img").live("click", function() {
		var url = $j(this).attr("data-url");
		var name = $j(this).attr("data-zoom");	
		
		if(name.length < 5) {
			$j(".outfitColorImage").each(function(){
				if($j(this).attr("data-zoom").length > 5) {
					name=$j(this).attr("data-zoom");
					return false;
				}
			});
		}
		if(name.length > 4) {
			openIframeShadowBox(815,705,url+"&zoomImg="+name);
		}	
		return false;
	});
	
	$j('#imgCarousel').jcarousel({
        vertical: true,
        scroll: 5,
        itemLoadCallback: imgCarousel_itemLoadCallback
	});
	
	$j("#imgCarouselContainer .jcarousel-prev").html('<img src="' + rcContextPath + '/images/app/common/bttn/bttn_car_up.png">');
	$j("#imgCarouselContainer .jcarousel-next").html('<img src="' + rcContextPath + '/images/app/common/bttn/bttn_car_down.png">');
	$j('#imgCarouselContainer').css("visibility","visible");

	actImg = $j("#grossbild").attr("src");

	initButtonDv();
	zoomClicked = false;
	setSizeUpdateEvent();	

	/* Bildschirmlupe */

	$j("#grossbild").mouseover( function() {
		if ((zoomPreloadAlba.width != "0" || zoomPreloadHeine.width != "0") && !zoomClicked && $j("#grossbild").attr("src").indexOf("platzhalter") < 0 ) {
			$j("#zoom").hide();
			zoomImg = $j("#grossbild").attr("src");
			if (zoomPreloadAlba.width > 0) {
				lupImg = zoomImg.replace("albamoda_formatI","formatz");
			} else {
				lupImg = zoomImg.replace("albamoda_formatI","format_hv_ea_1");
			}
			zoomPreload = new Image();
			zoomPreload.src = lupImg;
			$j("#zoomPic").css("background-image","url(" + lupImg + ")");

			$j("#zoom").fadeIn("middle");
			$j(".selectModelNew").css("visibility", "hidden");
			$j(".selectModelPromoItem").css("visibility", "hidden");
			$j(".selectPromoItemNew").css("visibility", "hidden");
			$j("#selSize").css("visibility", "hidden");
			zoomClicked = true;
		} else {
			$j("#zoom").hide();
			$j(".selectModelNew").css("visibility", "visible");
			$j(".selectModelPromoItem").css("visibility", "visible");
			$j(".selectPromoItemNew").css("visibility", "visible");
			$j("#selSize").css("visibility", "visible");
			zoomClicked = false;
		}
	});

	$j("#grossbild").mousemove( function(e) {
		xpos = e.pageX - $j(this).offset().left;
		ypos = e.pageY - $j(this).offset().top;
		if (zoomPreload) {
			pic_width = zoomPreload.width;
			pic_height = zoomPreload.height;
			orig_width = $j(this).width();
			orig_height = $j(this).height();

			xfaktor = pic_width / orig_width;
			yfaktor = pic_height / orig_height;
			xoff = 157 / xfaktor;
			yoff = 157 / yfaktor;
			if (xpos < xoff) {
				xpos = 0;
			} else if (xpos > (orig_width - xoff)) {
				xpos = pic_width - 315;
			} else {
				xpos = ((xpos - xoff) * xfaktor);
			}	
			if (ypos < yoff) {
				ypos = 0;
			} else if (ypos > orig_height - yoff) {
				ypos = pic_height - 315;
			} else {
				ypos = ((ypos - yoff) * yfaktor);
			}		
			$j("#zoomPic").css("background-position","-" + xpos + "px -" + ypos + "px");
		}
	});

	$j("#largeImage").mouseleave( function() {
		$j("#zoom").hide();
		$j(".selectModelNew").css("visibility", "visible");
		$j(".selectModelPromoItem").css("visibility", "visible");
		$j(".selectPromoItemNew").css("visibility", "visible");
		zoomClicked = false;
	});

	$j("#zoom").mouseover( function() {
		$j("#zoom").hide();
		$j(".selectModelNew").css("visibility", "visible");
		$j(".selectModelPromoItem").css("visibility", "visible");
		$j(".selectPromoItemNew").css("visibility", "visible");
	});
		
	
	if ($j(".selectPromoItemNew").length > 0) {
		if ($j(".selectPromoItemNew option:selected").val() != "0") {
			changeImagesNew($j("#" + $j(".selectPromoItemNew option:selected").attr("id").replace("p_", "")));
			$j(".selectPromoItemNew").change();
		}
	}
	
	if ($j("#p_" + promoItemMoUri).length > 0) {
		if ($j(".selectModelNew option").size() > 0) {
			$j(".selectModelNew").val($j("#p_" + promoItemMoUri).val());
			$j(".selectModelNew").change();
		} else if ($j(".selectPromoItemNew option").size() > 0) {
			$j(".selectPromoItemNew").val($j("#p_" + promoItemMoUri).val());
			$j(".selectPromoItemNew").change();
		}
	}
	
	setTimeout("$j('#loadPic').fadeOut('slow');",1000);

	$j("#merken").live("click", function() {
		if (checkOrderSelects()) {
			if($j(".singleSize").size()>0) {
				vid = $j(".singleSize").attr("data-id");
			} else {
				vid = $j(".chosenItem").attr("data-id");				
			}

			$j("#aufdieml").load(baseUrl + "/ajax_addtowatchlist.html", {
				vid :vid,
				bid :$j("#bid").val()
			});
			$j("#aufdieml").fadeIn("middle");
			$j('#aufdieml').mouseleave( function() {
				$j(this).fadeOut('slow');
			});
			top.Shadowbox.close();
			$j("html, body").animate({ scrollTop: 0 }, 0);		
		}
	});

	$j("#showSizeChart").live("click", function() {
		openIframeShadowBox(622, 700, baseUrl + "/shadowbox_masstabelle/boxedService.html", false);
	});

	$j("#showPassformAdviser").live("click", function() {
		showPassformAdviserInShadowBox($j(".backLink a").attr("href"), $j(this).attr("passformPage"));
	});
	
	$j("#product #showDictionaryTerms").live("click", function() {
		openIframeShadowBox(900, 700, baseUrl + "/viewDictionaryTerms.html?l=a", false);
	});

	$j("#printArticleInformation").live("click", function() {
		promoItemKeyParameter = "";
		if (typeof ($j('.selectPromoItemNew option:selected').attr('id')) != "undefined") {
			promoItemKey = $j('.selectPromoItemNew option:selected').attr('id').replace('p_', '');
			promoItemKeyParameter = "?promoItemKey=" + promoItemKey;
		} else if (typeof ($j('#inputPromoItem').attr('title')) != "undefined") {
			promoItemKey = $j('#inputPromoItem').attr('title').substring(0, 6);
			promoItemKeyParameter = "?promoItemKey=" + promoItemKey;
		}
		printArticleInformationPopup($j(this).attr("data-url") + promoItemKeyParameter);
	});

	$j("#recommend").live("click", function() {
		params = $j(this).attr("label").split("_");
		$j("#product #sendContainer").load(baseUrl + "/ajax_tellAFriend.html","", function() {
			$j("#taf_bundleId").val(params[1]);
			$j("#taf_styleId").val(params[3]);
		});
		$j("#product #sendContainer").fadeIn("middle");
	});

	$j(".dictionary").live("click", function() {
		params = $j(this).attr("id").split("_");
		$j("#product #dictionary_container").load(
			baseUrl + "/ajax_viewDictionaryTerm.html", {
				termId :params[1]
			}, function() {
				$j("#dictionary .xclose").click( function() {
				$j("#dictionary_container").fadeOut("fast");
			});
		});
		$j("#product #dictionary_container").fadeIn("middle");
	});

	$j("#dictionary .xclose").live("click", function() {
		$j("#dictionary_container").fadeOut("fast");
	});

	$j("#anzahl").blur( function() {
		if (parseInt($j(this).val()) > parseInt($j(this).attr("rel"))) {
			$j(this).val($j(this).attr("rel"));
			errorMessage("data-numberChanged");
		}
	});

// initSurchargeInformation();

	$j(".selectPromoItemNew").live("change", function() {
		initSurchargeInformation();
	});

	$j("#imgCarouselContainer li > img").live("click", function() {
		changeImagesNew($j(this));
		imgChange=false;		
		id=$j(this).attr("id");
		sbChange = false;
		
		if (id != "") {
			if ($j(".selectModelNew").length != "0") {
				$j(".selectModelNew option").each(function(){
					if($j(this).attr("id") == "p_"+id && $j(this).attr("id") != $j(".selectModelNew option:selected").attr("id")) {
						$j(".selectModelNew").val($j("#p_" + id).val());
						$j(".selectModelNew").change();						
						sbChange = true;			}
				});
			} else {
				$j(".selectPromoItemNew option").each(function(){
					if($j(this).attr("id") == "p_"+id && $j(this).attr("id") != $j(".selectPromoItemNew option:selected").attr("id")) {
						$j(".selectPromoItemNew").val($j("#p_" + id).val());
						$j(".selectPromoItemNew").change();
						sbChange = true;	
					}
				});	
			}
		}
		
		if(!sbChange) {
			id=$j(this).attr("data-articleno");
			if (id != "") {
				if ($j(".selectModelNew").length != "0") {
					$j(".selectModelNew option").each(function(){
						if($j(this).attr("data-articleno") == id && $j(this).attr("data-articleno") != $j(".selectModelNew option:selected").attr("data-articleno")) {
							$j(".selectModelNew").val($j(this).val());
							$j(".selectModelNew").change();						
						}
					});
				} else {
					$j(".selectPromoItemNew option").each(function(){
						if($j(this).attr("data-articleno") == id && $j(this).attr("data-articleno") != $j(".selectPromoItemNew option:selected").attr("data-articleno")) {
							$j(".selectPromoItemNew").val($j(this).val());
							$j(".selectPromoItemNew").change();
						}
					});	
				}
			}
		}	
		imgChange=true;
	});
	
	triggerSliderToolTips($j('.toolTipSlider'));
	
	$j(".showMoreReviews").click(function() {
		$j(this).css("display","none");
		$j(".showLessReviews").css("display","block");
		$j(".reviewInfoMore").css("display","block");
	});
	
	$j(".showLessReviews").click(function() {
		$j(this).css("display","none");
		$j(".showMoreReviews").css("display","block");
		$j(".reviewInfoMore").css("display","none");
	});
	
	$j(".voteHelpful").live("click", function() {
		parentEle = $j(this).parent();
		
		$j.ajax({
            type: "GET",
            url: baseUrl + "/ajax_reviewVote.html",
			data: {
				reviewExternalKey: $j(this).attr("data-reviewExternalKey"),
        		isHelpful: $j(this).attr("data-isHelpful")
			},
            dataType: "html",
            success: function(html){
				if (html != "" && html != null) {
					$j(parentEle.parent()).replaceWith(html);
				}
            },
			error: function() {
				$j(".reviewDetails").html("Die Bewertungen konnten nicht geladen werden!");
			}
        });
	});
	
	$j(".voteUnhelpful").live("click", function() {
		parentEle = $j(this).parent();
		
		$j.ajax({
            type: "GET",
            url: baseUrl + "/ajax_reviewVote.html",
			data: {
				reviewExternalKey: $j(this).attr("data-reviewExternalKey"),
        		isHelpful: $j(this).attr("data-isHelpful")
			},
            dataType: "html",
            success: function(html){
				if (html != "" && html != null) {
					$j(parentEle.parent()).replaceWith(html);
				}
            },
			error: function() {
				$j(".reviewDetails").html("Die Bewertungen konnten nicht geladen werden!");
			}
        });	
		
	});
	
	triggerJumpToRatingLink();
	$j(".outfitComplete .arrowLink, .outfitComplete img").click(function() {
		openOutfitOrderInShadowBox($j("#bid").val());
		return false;
	});
	
	
}

function triggerJumpToRatingLink() {
		$j("#product .jumpToRatings").live("click", function() {
			$j.scrollTo($j("#product .reviewDetails"), 500);
			return false;
		});
}

function showPassformAdviserInShadowBox(backLink, passformPage) {
	var page = '/'+ passformPage +'/ajax_passform_adviser.html'
	$j.get(page,{bLink : backLink, page : passformPage}, function(data) {
	    Shadowbox.open({
	        content:    data,
	        player:     "html",
	        handleOversize:    "none",
	        width: "806",
	        height: "490",
	        options:    {
               onFinish: function(item){
               }
	        } 	
	    });	 	    
	});
}

function setSizeUpdateEvent() {

	$j(".sold").each(function(){					
	    $j(this).children("img").css("width",$j(this).width()+"px");
	})			
	
	$j(".infoSelects .selectModelNew").unbind("change").change(function() {
		infoSelects=$j(this).closest(".infoSelects");
		if (infoSelects.find(".selectModelNew option:selected").attr("id") != "") {
			if(infoSelects.closest("#outfitOrder").size()>0 || infoSelects.closest(".productContainerOutfits").size()>0) {	
				changeOutfitImage(infoSelects,infoSelects.find(".selectModelNew option:selected").attr("id").replace("p_", ""),$j("#" + infoSelects.find(".selectModelNew option:selected").attr("id").replace("p_", "")));
			} else {
				changeImagesNew($j("#" + infoSelects.find(".selectModelNew option:selected").attr("id").replace("p_", "")));
			}	
		}
		infoSelects.find(".modelSelectorNew").load(baseUrl + "/ajax_changeDVModels.html", {
			pid :$j(this).val(),
			size :infoSelects.find(".chosenItem span").text()
		}, function() {
			showAvailString(infoSelects);
		});
	});

	$j(".infoSelects .selectPromoItemNew").unbind("change").change(function() {
		infoSelects=$j(this).closest(".infoSelects");
		if ($j(this).val() != "0") {
			if(infoSelects.closest("#outfitOrder").size()>0 || infoSelects.closest(".productContainerOutfits").size()>0) {	
				changeOutfitImage(infoSelects,infoSelects.find(".selectPromoItemNew option:selected").attr("id").replace("p_", ""),$j("#" + infoSelects.find(".selectPromoItemNew option:selected").attr("id").replace("p_", "")));
			} else {
				changeImagesNew($j("#" + infoSelects.find(".selectPromoItemNew option:selected").attr("id").replace("p_", "")));
			}
			mySize = "";
			if($j(".searchSize").length && $j(".searchSize").html().length > 0) {
				mySize = $j(".searchSize").html().trim();
				$j(".searchSize").html("");
			} else {
				mySize = infoSelects.find(".chosenItem span").text()
			}
			
			infoSelects.find(".sizeSelectorNew").load(baseUrl + "/ajax_changeDVSizes.html", {
				pid :$j(this).val(),
				size :mySize
			}, function() {
				showAvailString(infoSelects);
				infoSelects.find(".sold").each(function(){
				    $j(this).children("img").css("width",$j(this).width()+"px");
				})				
			});
		} else {
			showAvailString(infoSelects);			
		}	
	});
	
	$j(".infoSelects .modelSelectorNew .selectModelPromoItem").unbind("change").change(function() {
		infoSelects=$j(this).closest(".infoSelects");
		infoSelects.find(".chooseModel li").removeClass("chosenModel");
		mySize = "";
		if($j(".searchSize").length && $j(".searchSize").html().length > 0) {
			mySize = $j(".searchSize").html().trim();
			$j(".searchSize").html("");
		} else {
			mySize = infoSelects.find(".chosenItem span").text()
		}
		if ($j(this).val() != "0") {
			$j('li[data-artno*="'+$j(this).val()+'"]').addClass("chosenModel");
			infoSelects.find(".sizeSelectorNew").load(baseUrl + "/ajax_changeDVSizes.html", {
				pid :$j(this).val(),
				size :mySize
			}, function() {
				showAvailString(infoSelects);
				infoSelects.find(".sold").each(function(){
				    $j(this).children("img").css("width",$j(this).width()+"px");
				})				
			});
		} else {
			showAvailString(infoSelects);			
		}	
	});

	$j(".chooseModel li").unbind("click").click(function() {
		infoSelects=$j(this).closest(".infoSelects");
		infoSelects.find(".chooseModel li").removeClass("chosenModel");
		$j(this).addClass("chosenModel")
		infoSelects.find(".selectModelPromoItem").val($j(this).attr("data-artno"));
		infoSelects.find(".selectModelPromoItem").change();
	});
	
	$j(".availableSize").unbind("click").click(function() {
		infoSelects=$j(this).closest(".infoSelects");
		infoSelects.find(".availableSize").removeClass("chosenItem");
		$j(this).addClass("chosenItem");
		showAvailString(infoSelects);
	});
	
}

function changeImagesNew(obj) {
	if (obj.attr("src") && imgChange && obj.attr("id") != "showPassformAdviser") {
		if(obj.attr("src").indexOf("platzhalter")>0) {
			imgSrc = obj.attr("data-url");
		} else {
			imgSrc = obj.attr("src");
		} 
	
		if (imgSrc.indexOf("formatP")>0) {
			actImg = imgSrc.replace("formatP", "formatI");
		} else if (imgSrc.indexOf("formatp")>0) {
			actImg = imgSrc.replace("formatp", "formati");
		}
		actZoomImg = obj.attr("label");

		$j("#grossbild").attr("src", actImg);
		if (obj.attr("data-zoom") != "") {
			$j("#grossbild").attr("data-zoom", obj.attr("data-zoom"));			
		}
	}
}

function changeOutfitImage(infoSelects, imgUri, obj) {
	if(infoSelects.closest(".productContainerOutfits").size()>0) {
		$j(".promoItemPic img").attr("src","http://image01.otto.de/pool/albamoda_formatK/"+imgUri+".jpg");
		if (obj.attr("data-zoom") != "") {
			$j(".promoItemPic .mainPic").attr("data-zoom", obj.attr("data-zoom"));			
		}
	} else {
		infoSelects.closest(".articleItem").find(".articleImg").attr("src","http://image01.otto.de/pool/albamoda_formatP/"+imgUri+".jpg");
	}	
}

function refreshMinibasket(itemId) {
		$j.ajax({
    	type: "POST",
        url: baseUrl + "/ajax_changeBasketItem.html",
		data: {
        	lineItemId: itemId
		},
        dataType: "html",
        success: function(html){
			if (html != "" && html != null) {
			}
        }
	});
}

function initButtonDv() {
	$j(".productContainer .toBasket").unbind("click").click(function() {
		if (checkOrderSelects()) {
			if($j(".singleSize").size()>0) {
				vid = $j(".singleSize").attr("data-id");
				deliveryDesignation = $j(".singleSize").attr("data-deliverydesignation");
			} else {
				vid = $j(".chosenItem").attr("data-id");				
				deliveryDesignation = $j(".chosenItem").attr("data-deliverydesignation");
			}
			if (deliveryDesignation != "1") { 	
				$j("#indenwk").load(baseUrl + "/ajax_addtobasket.html", {
					vid :vid,
					bid :$j("#bid").val(),
					amount :"1",
					articleNumberWithPromotionCode :$j("#articleNumberWithPromotionCode").val()
			        },
					function (result, textStatus, XMLHttpRequest) {
						if (textStatus == "success") {
						refreshMinibasket(-1);
						$j("#quickviewBasket").load(baseUrl + "/ajaxRefreshQuickViewBasket.html",
							function (result, textStatus, XMLHttpRequest) {
								initQuickviewWarenkorb();				
							}				
						);
	
					}				
				});
			} else {
				alert("Der Artikel ist in dieser Größe und Farbe leider ausverkauft");
			}	
				
			$j("#indenwk").fadeIn("middle");
			$j(".productContainer .toBasket").unbind("click");
			setTimeout('initButtonDv()', 5000);
			$j('#indenwk').mouseleave( function() {
				$j(this).fadeOut('slow');
			});
			top.Shadowbox.close();
			$j("html, body").animate({ scrollTop: 0 }, 0);				
		}
	});
	
	$j(".productContainer .toBasketSB").unbind("click").click(function() {
		if (checkOrderSelects()) {
			if($j(".singleSize").size()>0) {
				vid = $j(".singleSize").attr("data-id");
				deliveryDesignation = $j(".singleSize").attr("data-deliverydesignation");
			} else {
				vid = $j(".chosenItem").attr("data-id");				
				deliveryDesignation = $j(".chosenItem").attr("data-deliverydesignation");
			}
				
			if (deliveryDesignation != "1") { 	
				$j.get(baseUrl + '/ajax_addtobasket.html',{vid :vid,bid :$j("#bid").val(),amount:"1",articleNumberWithPromotionCode:$j("#articleNumberWithPromotionCode").val()}, function(data) {
				    Shadowbox.open({
				        content:    data,
				        player:     "html",
				        handleOversize:    "none",
				        width: "286",
				        height: "260",
				        options:    {
				           overlayOpacity:0.3,
			               onFinish: function(item){
			            	   copyInMinibasket();
								$j("#quickviewBasket").load("/ajaxRefreshQuickViewBasket.html",
									function (result, textStatus, XMLHttpRequest) {
										initQuickviewWarenkorb();				
									}				
								);
			            	   
			               }
				        } 	
				    });	 	    
				});			
				$j(".productContainer .toBasketSB").unbind("click");
				setTimeout('initButtonDv()', 5000);
			} else {
				alert($j("#errorMessage").attr("data-articleSoldOut"));
			}	
			
		}
	});

	$j(".productContainer .toBasketPage").unbind("click").click(function() {
		if (checkOrderSelects()) {
			if($j(".singleSize").size()>0) {
				vid = $j(".singleSize").attr("data-id");
			} else {
				vid = $j(".chosenItem").attr("data-id");				
			}
				
			location.href="addtobasket.html?vid="+vid+"&bid="+$j("#bid").val()+"&amount=1&articleNumberWithPromotionCode="+$j("#articleNumberWithPromotionCode").val();
		}
	});
	
	
	$j(".productContainer .addBonus").click(	function() {
		if (checkOrderSelects()) {
			if($j(".singleSize").size()>0) {
				vid = $j(".singleSize").attr("data-id");
			} else {
				vid = $j(".chosenItem").attr("data-id");				
			}
			location.href = "premium.html?vid=" + vid + "&bid=" + $j("#bid").val();
		}
	});

}	

function initOutfitToBasketButton() {
	$j("#outfitOrder .outfitToBasket").unbind("click").click(function() {
		var vid="";
		var errorMessage = "";
		var errorObject;
		$j("#outfitOrder .articleItem").each(function(){
			if(($j(this).find(".chosenItem").size()>0 || $j(this).find(".singleSize").size()>0) && $j(this).find(".articleCheckBox input").is(':checked')) {
				if($j(this).find(".singleSize").size()>0) {
					vid = vid + $j(this).find(".singleSize").attr("data-id") + ";";
				} else {
					vid = vid + $j(this).find(".chosenItem").attr("data-id") + ";";				
				}
			}
			if ($j(this).find(".articleCheckBox input").is(':checked')) {
				if (($j(this).find(".selectModelNew").length > 0 && $j(this).find(".selectModelNew option:selected").val() == "0") || ($j(this).find(".selectPromoItemNew").length > 0 && $j(this).find(".selectPromoItemNew option:selected").val() == "0")) {
					errorMessage = "data-noColor";
				} else if ($j(this).find(".selectModelNew").length > 0 && $j(this).find(".selectModelPromoItem option:selected").val() == "0") {
					errorMessage = "data-noStyling";
				} else if ($j(this).find(".selectPromoItemNew").length > 0 && $j(this).find(".selectPromoItemNew option:selected").val() == "0") {
					errorMessage = "data-noColor";
				} else if($j(this).find(".chosenItem").size()>0) {
				} else if ($j(this).find(".singleSize").size()>0)  {
				} else {
					errorMessage = "data-noSize";
				}
			}
			message = $j("#errorMessage").attr(errorMessage);
			if (errorMessage != "") {
				$j(this).find("a").focus();
				errorObject = $j(this).find(".errMissing");
				errorObject.html(message).fadeIn("fast");
				setTimeout(function(){$j(".errMissing").fadeOut("fast")}, 1200);
				return false;
			}
		})
		if (errorMessage == "") {
			if (vid.length >0) {
				var variantId=vid.substring(0,vid.length-1);
				if ($j("#bid").length > 0) {
					$j("#indenwk").load(baseUrl + "/ajax_addoutfittobasket.html", {
						vid :variantId,
						bid :$j("#bid").val()
						},
						function (result, textStatus, XMLHttpRequest) {
							if (textStatus == "success") {
								refreshMinibasket(-1);
								$j("#quickviewBasket").load("/ajaxRefreshQuickViewBasket.html",
										function (result, textStatus, XMLHttpRequest) {
											initQuickviewWarenkorb();				
										}				
								);
								Shadowbox.close();
							}				
					});
				} else {
					$j("#indenwk").load(baseUrl + "/ajax_addoutfittobasket.html", {
						vid :variantId	},
						function (result, textStatus, XMLHttpRequest) {
							if (textStatus == "success") {
								refreshMinibasket(-1);
								$j("#quickviewBasket").load("/ajaxRefreshQuickViewBasket.html",
										function (result, textStatus, XMLHttpRequest) {
											initQuickviewWarenkorb();				
										}				
								);
							}				
					});	
				}
				
				$j("#indenwk").fadeIn("middle");
				$j("#outfitOrder .outfitToBasket").unbind("click");
				$j('#indenwk').mouseleave( function() {
					$j(this).fadeOut('slow');
				});
				top.Shadowbox.close();
				$j("html, body").animate({ scrollTop: 0 }, 0);
			} else if ($j(".errMissing").length > 0){
				errorMessage = "data-noArticle";
				message = $j("#errorMessage").attr(errorMessage);
				errorObject = $j(".errMissing")[$j(".errMissing").length-1];
				errorObject.innerHTML = message;
				errorObject.style.display = "block";
				$j(".outfitToBasket").focus();
				setTimeout(function(){ $j(".errMissing")[$j(".errMissing").length-1].style.display = "none";}, 1200);
			}
			return false;
		}
		return false;
	});
	
	$j(".articleCheckBox input").unbind("click").click(function(){
		if($j(this).is(":checked")) {
			$j(this).closest(".articleInfos").find(".infoSelects").css("visibility","visible");
        } else {
    		$j(this).closest(".articleInfos").find(".infoSelects").css("visibility","hidden");
        }
	});
}


function showAvailString(infoSelects) {

	infoSelects.find(".availabilityInformationNew").removeClass("gelb").removeClass("gruen");
	if (((infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelNew option:selected").val() == "0")) || ((infoSelects.find(".selectPromoItemNew").length > 0 && infoSelects.find(".selectPromoItemNew option:selected").val() == "0"))) {
		infoSelects.find(".availabilityInformationNew").text($j("#errorMessage").attr("data-noColor"));
		setInactive(infoSelects);
	} else if (infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelPromoItem option:selected").val() == "0") {
		infoSelects.find(".availabilityInformationNew").text($j("#errorMessage").attr("data-noStyling"));
		setInactive(infoSelects);
	} else if(infoSelects.find(".chosenItem").size()>0) {
		if(infoSelects.find(".chosenItem").attr("data-deliverydesignation") == "2") {
			infoSelects.find(".availabilityInformationNew").addClass("gelb");
		} else if(infoSelects.find(".chosenItem").attr("data-deliverydesignation") == "0") {
			infoSelects.find(".availabilityInformationNew").addClass("gruen");
		} else if(infoSelects.find(".chosenItem").attr("data-deliverydesignation") == "1") {
			infoSelects.find(".availabilityInformationNew").addClass("red");
		} 
		infoSelects.find(".availabilityInformationNew").text(infoSelects.find(".chosenItem").attr("alt"));
	} else if (infoSelects.find(".singleSize").size()>0)  {
		if(infoSelects.find(".singleSize").attr("data-deliverydesignation") == "2") {
			infoSelects.find(".availabilityInformationNew").addClass("gelb");
		} else if(infoSelects.find(".singleSize").attr("data-deliverydesignation") == "0") {
			infoSelects.find(".availabilityInformationNew").addClass("gruen");
		} else if(infoSelects.find(".singleSize").attr("data-deliverydesignation") == "1") {
			infoSelects.find(".availabilityInformationNew").addClass("red");
		} 
		infoSelects.find(".availabilityInformationNew").text(infoSelects.find(".singleSize").attr("data-deliveryMessage"));
	} else {
		infoSelects.find(".availabilityInformationNew").text($j("#errorMessage").attr("data-noSize"));							
	}
	
	refreshPrice(infoSelects);
	
}	

function refreshPrice(infoSelects) {
	
	saving = getSaving(infoSelects);
	varprice = getPrice(infoSelects);
	oldprice = getOldPrice(infoSelects, saving);
	
	
	if (((infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelNew option:selected").val() == "0")) || ((infoSelects.find(".selectPromoItemNew").length > 0 && infoSelects.find(".selectPromoItemNew option:selected").val() == "0"))) {
	
	} else {	
		checkSaving(infoSelects, saving);
		infoSelects.closest(".articleInfos").find(".price").html(varprice);
		infoSelects.closest(".articleInfos").find(".priceReduced").html(varprice);
		infoSelects.closest(".articleInfos").find(".savingPrice").html("statt "+oldprice+" ");
		if (saving && saving != "0") {
			infoSelects.closest(".articleInfos").find(".saving").html(saving);	
			if (!$j("#shadowbox_content").length > 0) {
				$j(".flag").attr("class","flag reducedFlag flags-eckesale"+saving)
			}	
		} else if ($j(".reducedFlag").length > 0 && !$j(".singleSize").length > 0 && !$j("#shadowbox_content").length > 0) {
			$j(".flag").attr("class","flag reducedFlag")
		}		
	}	
	
}

function getSaving(infoSelects) {

	saving="0";
	if (((infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelNew option:selected").val() == "0")) || ((infoSelects.find(".selectPromoItemNew").length > 0 && infoSelects.find(".selectPromoItemNew option:selected").val() == "0"))) {

	} else if (infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelPromoItem option:selected").val() == "0") {	
		saving = infoSelects.find(".chooseModel li:first").attr("data-saving");
	} else if (infoSelects.find(".singleSize").length > 0) {	
		saving = infoSelects.find(".singleSize").attr("data-saving");
	} else {	
		if(infoSelects.find(".chosenItem").size()>0) {
			saving = infoSelects.find(".chosenItem").attr("data-saving");
		} else {
			if (infoSelects.closest(".articleInfos").find(".availableSize").length > 0) { 
				saving = infoSelects.closest(".articleInfos").find(".availableSize:first").attr("data-saving");
			} else if (infoSelects.closest(".articleInfos").find(".inactive").length > 0) {	
				saving = infoSelects.closest(".articleInfos").find(".inactive:first").attr("data-saving");
			} else if (infoSelects.closest(".articleInfos").find(".sold").length > 0) {	
				saving = infoSelects.closest(".articleInfos").find(".sold:first").attr("data-saving");
			}	
		}	
	}
	
	return saving;
}

function getPrice(infoSelects) {

	varprice=infoSelects.closest(".articleInfos").find(".price").attr("data-price");
	if (infoSelects.closest(".articleInfos").find(".singleSize").length > 0) {	
		varprice = infoSelects.closest(".articleInfos").find(".singleSize").attr("data-price");
	}			
	
	if (((infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelNew option:selected").val() == "0")) || ((infoSelects.find(".selectPromoItemNew").length > 0 && infoSelects.find(".selectPromoItemNew option:selected").val() == "0"))) {
		
	} else if (infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelPromoItem option:selected").val() == "0") {	
		varprice = infoSelects.find(".chooseModel li:first").attr("data-price");
	} else if (infoSelects.find(".singleSize").length > 0) {	
		price = infoSelects.find(".singleSize").attr("data-price");
	} else {
		if(infoSelects.find(".chosenItem").size()>0) {
			varprice = infoSelects.find(".chosenItem").attr("data-price");
		} else {
			if (infoSelects.closest(".articleInfos").find(".availableSize").length > 0) {
				varprice = infoSelects.closest(".articleInfos").find(".availableSize:first").attr("data-price");
			} else if (infoSelects.closest(".articleInfos").find(".inactive").length > 0) {	
				varprice = infoSelects.closest(".articleInfos").find(".inactive:first").attr("data-price");
			} else if (infoSelects.closest(".articleInfos").find(".sold").length > 0) {	
				varprice = infoSelects.closest(".articleInfos").find(".sold:first").attr("data-price");
			}	
		}	
	}
	return varprice;
}

function getOldPrice(infoSelects, saving) {

	oldprice="";
	
	if (((infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelNew option:selected").val() == "0")) || ((infoSelects.find(".selectPromoItemNew").length > 0 && infoSelects.find(".selectPromoItemNew option:selected").val() == "0"))) {
		
	} else if (infoSelects.find(".selectModelNew").length > 0 && infoSelects.find(".selectModelPromoItem option:selected").val() == "0") {	
		if (saving && saving != "0") {
			oldprice = infoSelects.find(".chooseModel li:first").attr("data-old-price");
		}
	} else if (infoSelects.find(".singleSize").length > 0) {	
		if (saving && saving != "0") {
			oldprice = infoSelects.find(".singleSize").attr("data-old-price");
		}
	} else {	
		if(infoSelects.find(".chosenItem").size()>0) {
			if (saving && saving != "0") {
				oldprice = infoSelects.find(".chosenItem").attr("data-old-price");
			}		
		} else {
			if (infoSelects.closest(".articleInfos").find(".availableSize").length > 0) {
				oldprice = infoSelects.closest(".articleInfos").find(".availableSize:first").attr("data-old-price");
			} else if (infoSelects.closest(".articleInfos").find(".inactive").length > 0) {	
				oldprice = infoSelects.closest(".articleInfos").find(".inactive:first").attr("data-old-price");
			} else if (infoSelects.closest(".articleInfos").find(".sold").length > 0) {	
				oldprice = infoSelects.closest(".articleInfos").find(".sold:first").attr("data-old-price");
			}	
		}	
	}	
	return oldprice;
}


function checkSaving(infoSelects, saving) {
	if (saving != "0") {
		infoSelects.closest(".articleInfos").find(".oldPrice").css("visibility","visible");
		infoSelects.closest(".articleInfos").find(".priceReduced").css("color","#CC1A1A");		
	} else {
		infoSelects.closest(".articleInfos").find(".oldPrice").css("visibility","hidden");
		infoSelects.closest(".articleInfos").find(".priceReduced").css("color","#1A1A1A");		
	}	
}


function setInactive(infoSelects) {
	infoSelects.find(".availableSize").unbind("click");
	infoSelects.find(".soldItems li").removeClass("availableSize").removeClass("sold").removeClass("chosenItem").addClass("inactive");
}

function checkOrderSelects() {
	if (($j(".selectModelNew").length > 0 && $j(".selectModelNew option:selected").val() == "0") || ($j(".selectPromoItemNew").length > 0 && $j(".selectPromoItemNew option:selected").val() == "0")) {
		errorMessage("data-noColor");
		return false;
	} else if ($j(".selectModelNew").length > 0 && $j(".selectModelPromoItem option:selected").val() == "0") {
		errorMessage("data-noStyling");
		return false;
	} else if ($j(".selectPromoItemNew").length > 0 && $j(".selectPromoItemNew option:selected").val() == "0") {
		errorMessage("data-noColor");
		return false;
	} else if($j(".chosenItem").size()>0) {
		return true;
	} else if ($j(".singleSize").size()>0)  {
		return true;
	} else {
		errorMessage("data-noSize");
		return false;
	}
}	

function initSurchargeInformationNew() {
	if ($j("#inputPromoItem").attr("alt") != undefined && $j("#inputPromoItem").attr("alt").length > 0) {
		$j("#surchargeInformationContainer #surchargeInformation").text(
		$j("#inputPromoItem").attr("alt"));
		$j("#surchargeInformationContainer").show();
	} else if ($j("#selectPromoItem option:selected").attr("alt") != undefined && $j("#selectPromoItem option:selected").attr("alt").length > 0) {
		$j("#surchargeInformationContainer #surchargeInformation").text(
		$j("#selectPromoItem option:selected").attr("alt"));
		$j("#surchargeInformationContainer").show();
	} else {
		$j("#surchargeInformationContainer").hide();
	}
}

function triggerSliderToolTips($selector) {
	$selector.tooltip({
		bodyHandler: function() {
			return $j($j(this).attr("data-tooltipId")).html();
		},
		delay: 0,
		showURL: false,
		top: 5,
		left: 5,
		extraClass: "limitedWidth"
	});
}

/* Detailview Ende */


function showAvailabilityMatrix() {
	showAvailabilityMatrixWithStyleId($j("#sid").val(),$j("#bid").val());
}

function showAvailabilityMatrixWithStyleId(styleId,bundleId) {
	$j.get(baseUrl + '/ajax_viewavailabilitymatrix.html',{sid :styleId,bid :bundleId}, function(data) {
	    Shadowbox.open({
	        content:    data,
	        player:     "html",
	        handleOversize:    "none",
	        width: "500",
	        height: "440",
	        options:    {
               onFinish: function(item){
            	   $j("#availMatrix .models p").css("width", (100/$j("#availMatrix .models p").length)+"%");
            	   $j("#availMatrix .models p.last").css("width",$j("#availMatrix .models p.last").width()+1+("px"));
            	   initAvailMatrix();
               }
	        } 	
	    });	 	    
	});
}

function showAvailabilityMatrixWithStyleIdAndColor(elem,styleId,bundleId,color) {
	elem.append('<span class="availMatrixLoading"> </span>');
	$j.get(baseUrl + '/ajax_viewavailabilitymatrix.html',{sid :styleId,bid :bundleId,color: color}, function(html) {
		$j(".availMatrixColor").hide();
		elem.append(html);
		elem.children(".availMatrixLoading").remove();
		elem.children(".availMatrixColor").show();
	});
}

function initAvailMatrix() {	
	$j("#availMatrix .models p").unbind("click").click(function() {
		styleId=$j(this).attr("data-styleId");
		bundleId=$j(this).attr("data-bundleId");
		model=$j(this).text();
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Ausführung', model.trim());
		
		$j("#availMatrix").load(
			baseUrl + "/ajax_viewavailabilitymatrix.html", {
				sid :styleId,
				bid :bundleId,
				model :model
			}, function() {
				$j("#availMatrix .models p").css("width", (100/$j("#availMatrix .models p").length)+"%");
				$j("#availMatrix .models p.last").css("width",$j("#availMatrix .models p.last").width()+1+("px"));
          	    initAvailMatrix();
		});
		
	});

	$j("#availMatrix table td.available, #availMatrix table td.lateravailable").unbind("click").click(function() {
		$j("#availMatrix table td").removeClass("chosen");
		$j(this).addClass("chosen");
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Farbe', $j(this).parent().first().text().trim());
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Größe', $j(this).attr('data-name').trim());
	});

	
	
	$j("#availMatrix .toBasket").unbind("click").click(function() {
		if ($j("td.chosen").length > 0) {
			vid=$j("td.chosen").attr("data-id");	
			bid=$j("td.chosen").attr("data-bundleId");	
			promoCode=$j("td.chosen").attr("data-promoCode");	
			$j("#indenwk").load(baseUrl + "/ajax_addtobasket.html", {
				vid :vid,
				bid :bid,
				amount :"1",
				promoCode :promoCode
			}, 
			function (result, textStatus, XMLHttpRequest) {
				if (textStatus == "success") {
					refreshMinibasket(-1);
				}
			});
			top.Shadowbox.close();
			$j("html, body").animate({ scrollTop: 0 }, 0);							
			$j("#indenwk").fadeIn("middle");
			$j('#indenwk').unbind("mouseleave").mouseleave( function() {
				$j(this).fadeOut('slow');
			});
		} else {
			alert($j("#errorMessage").attr("data-noSize"));
		}	
	});
}

function getWindowHeight() {
	if(window.innerHeight)
		return window.innerHeight;
	return window.document.documentElement.clientHeight || window.document.body.clientHeight;
}


var searchFilter = {
	changeUrl: function(url) {
		var parts = url.split('?');
		location.hash = (parts[1] || "-").replace(/^[&\!]/,'');
	},
	triggerFilter: function() {
		$j(window).hashchange(function (e, initial) {
			if (location.hash.length > 0) {
				searchFilter.sendFilter(location.hash.replace('#', ''));
			}	
		}).hashchange();
		
		
		// activity indicator
		$j("#searchNavi a").live("click", function() {
			$j("#searchNavi a.loading").removeClass("loading");
			$j(this).addClass("loading");
		});
		
		
		$j(".colorthumb").live("mouseover", function() {
		     var color = $j(this).attr("data-name"); 
		     
		     $j(this).tooltip({
				bodyHandler: function() {
					$j("#tooltip").css("text-transform","Capitalize")
				    return color;
				},
				delay: 0,
				showURL: false,
				top: 5,
				left: 5,
				extraClass: "limitedWidth"
			});
		})		
		
		// filter request
		$j("#searchNavi a, .paging a").live("click", function(event) {
			searchFilter.triggerContentUpdate($j(this).attr("href"));
			return false;
		});
	},	
	triggerContentUpdate: function(url) {
		var parts = url.split('?');
		location.hash = (parts[1] || "-").replace(/^[&\!]/,'');
		return false;
	},
	sendFilter: function(hash) {
		searchFilter.displayWaitingOverlay();
		
		if ($j.browser.msie) {
			hash = encodeURI(hash).replace("%25","%");
		}

		var path = window.location.pathname;

		$j.ajax({
			type: "POST",
			url: path+"?"+hash,
			data: '',
			success: function(msg){
				searchFilter.setFilter();
				initDynamicLoading();
/*
 * if(!isIE6) { searchFilter.scrollFilter(); }
 */
		  	}
		});
		return false;
	},
	displayWaitingOverlay: function() {
		var headerHeight = $j("header").height();
// var top = Math.max(290, getScrollTop()+getWindowHeight()/2-headerHeight-116);
		$j("#ajaxLoader").remove();
		var ajaxLoader = "<div id=\"ajaxLoader\"> </div>";
		$j("#content").addClass("loading");
		$j("#content").append(ajaxLoader);
	// $j("#ajaxLoader").css("top", top+"px");
	},	
	setFilter: function() {
		
		$j("#ajaxLoader").remove();
		$j("#content").removeClass("loading");
		initDynamicLoading();
		initRatingLink();

		initQuicklookButton();

		triggerImagesOfProductlist();
		$j(".scrollableFilter").jScrollPane({
			scrollbarWidth: 7
		});	
		$j("#searchNavi .grepFilterContainer").css("border","none");
		
		$j(".grepFilter input").unbind("click").click(function(){
			if ($j(this).val().indexOf("eingeben") > 0) {
				$j(this).val("");
			}			
		});
		
		$j(".grepFilter input").unbind("blur").blur(function(){
			if ($j(this).val().length == 0) {
				$j(this).val($j(this).parent().siblings("em").html()+" eingeben");
			}			
		});

		
		$j(".grepFilter input").each(function(){
		    var id=$j(this).attr("id");
		    $j("#"+id).unbind("keyup").keyup(function() {
		      s = $j(this).val().toLowerCase();
		        $j("."+id+" ul li a").each(function(){
		            if($j(this).text().toLowerCase().indexOf(s) > -1) {
		                $j(this).parent().css("display","block");
		            } else {
		                $j(this).parent().css("display","none");
		            }
		        });
		        $j('.'+id).jScrollPane({
		           scrollbarWidth: 7
		        });
		    });    
		})
		
		var $el = $j("#priceSlider");
		$el.slider({
		    from: parseInt($el.attr('min'), 10),
			to: parseInt($el.attr('max'), 10),
			step: 1,
			smooth: true,
			round: 0,
			dimension: "&nbsp;&euro;",
			callback: function (priceValue) {
				var newFilterUrl = "";
				filterUrl=($j(".searchFilter").attr("data-filter-url"));
				filterUrlSplit=filterUrl.split("&");
				var valueSplit = priceValue.split(";");
				if (filterUrl.indexOf("minPrice") > 0 || filterUrl.indexOf("maxPrice") > 0 ) {
					for (j = 0; j < filterUrlSplit.length; j++) {
						if(filterUrlSplit[j].split("=")[0] == "minPrice") {
							newFilterUrl = newFilterUrl+"&minPrice="+valueSplit[0];
						} else if(filterUrlSplit[j].split("=")[0] == "maxPrice") {
							newFilterUrl = newFilterUrl+"&maxPrice="+valueSplit[1];							
						} else {
							newFilterUrl = newFilterUrl+"&"+filterUrlSplit[j];
						}					
					}
				} else {
					newFilterUrl=filterUrl+"&minPrice="+valueSplit[0]+"&maxPrice="+valueSplit[1];
				}
				createGoogleEventTracking('Filter', locateListPageName(), "Preis gesetzt");
				searchFilter.triggerContentUpdate(newFilterUrl);
				return false;
			}
		});
		$j(".priceFilter").css("border-bottom","none");

		var $el = $j("#materialSlider");
		var material = $j("#materialDetail").attr("data-chosen");
		$el.slider({
		    from: parseInt($el.attr('min'), 10),
			to: parseInt($el.attr('max'), 10),
			step: 10,
			smooth: true,
			round: 0,
			dimension: "&nbsp;%",
			callback: function (value) {
				var newFilterUrl = "";
				filterUrl=($j(".searchFilter").attr("data-filter-url"));
				filterUrlSplit=filterUrl.split("&");				
				valueSplit = value.split(";");
				if (filterUrl.indexOf("materialDetail") > 0) {
					for (j = 0; j < filterUrlSplit.length; j++) {
						if(filterUrlSplit[j].split("=")[0] == "materialDetail") {
							newFilterUrl = newFilterUrl+"&materialDetail=";
							for (i = parseInt(valueSplit[0]); i <= parseInt(valueSplit[1]); i=i+10) {
								newFilterUrl=newFilterUrl+material+i+"|";
							}												
							newFilterUrl=newFilterUrl.substring(0,newFilterUrl.length-1);
						} else {
							newFilterUrl = newFilterUrl+"&"+filterUrlSplit[j];
						}					
					}
				} else {
					newFilterUrl=filterUrl+"&materialDetail=";
					for (i = parseInt(valueSplit[0]); i <= parseInt(valueSplit[1]); i=i+10) {
						newFilterUrl=newFilterUrl+material+i+"|";
					}					
					newFilterUrl=newFilterUrl.substring(0,newFilterUrl.length-1);
				}
				searchFilter.triggerContentUpdate(newFilterUrl);
				return false;
			}
		});
		
		$j("#searchNavi ul li em.aktiv").unbind("click").click(function(){
			if($j(this).siblings().css("display") == "none") {
			    if($j(this).parent().prop("class").indexOf("farben") > -1) {
			    	$j(this).siblings("span").slideDown("fast");
			    } else {
			    	$j(this).siblings().slideDown("fast");			    	
			    }
			    $j(this).css('background-image','url("/images/app/common/bkgd/filter_arrow_down.gif")');
			} else {
			    if($j(this).parent().prop("class").indexOf("farben") > -1) {
			    	$j(this).siblings("span").slideUp("fast");
			    } else {
			    	$j(this).siblings().slideUp("fast");			    	
			    }	
			    $j(this).css('background-image','url("/images/app/common/bkgd/filter_arrow_right.gif")');
			}
		});         
		
		$j("#sortType").change( function() {
			url = $j("#sortType").attr("label") + "&sortType=" + $j(this).val();
			searchFilter.triggerContentUpdate(url);
			return false;
		});
		
		$j(".adoSortType a").unbind("click").click( function() {
			createGoogleEventTracking('Sortierung', locateListPageName(), $j(this).text());
			url = $j(this).url();
			searchFilter.triggerContentUpdate(url);
			return false;
		});
		
		$j("#content #categoryFilter span").unbind("mouseover").mouseover( function() {
			$j(this).children("div").show()
		});

		$j("#content #categoryFilter span").unbind("mouseout").mouseout( function() {
			$j(this).children("div").hide()
		});

		$j("#resultsPerPage").unbind("change").change( function() {
			url = $j("#resultsPerPage").attr("label") + "&resultsPerPage=" + $j(this).val();
			searchFilter.triggerContentUpdate(url);
			return false;
		});

		$j(".resultsPerPage").unbind("change").change( function() {
			url = $j(".resultsPerPage").attr("label") + "&resultsPerPage=" + $j(this).val();
			searchFilter.triggerContentUpdate(url);
			return false;
		});
		
		
		$j(".resultsPerPage").unbind("click").click( function() {
			createGoogleEventTracking('Artikel Pro Seite', $j(this).text(), null);
			url = $j(this).attr("href");
			searchFilter.triggerContentUpdate(url);
			return false;
		});

	}
};

function checkiPhone() {
	var iPhone=((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)));
	return iPhone;
}

function checkiPad() {
	var iPad=navigator.userAgent.match(/iPad/i);
	return iPad;
}

function isTouchDevice(){
	try{
		document.createEvent("TouchEvent");
		return true;
	}catch(e){
		return false;
	}
}
function initDynamicLoading(){
	if (!checkiPad() || !checkiPhone()) {
		$j('.sbild a img.showInView').die("inview").live('inview', function (event, visible) {
		    if (visible == true) {
		    	if($j(this).attr('data-src')) {
		    		$j(this).hide();
		    		$j(this).attr("src",$j(this).attr('data-src'));
		    		$j(this).fadeIn("slow");
		    		$j(this).css("background","none")
		    		$j(this).removeClass("showInView");
		    	}	
		    }  
		});
	}
}	
initDynamicLoading();

$j(".loginCustInput input").live("focus", function() {
	$j(":radio[value='loginCustNo']").prop("checked", true);
});

$j(".loginMailInput input").live("focus", function() {
	$j(":radio[value='loginEmail']").prop("checked", true);
});

function googleAnalyticsEventsTracking() {
	
	// Pictures-Click Event, Pic On Zoom in initZoom()
//	$j("#topnavi img, #storefrontContainer img, #storefront img, .sobercontainer .sbild img, #product img, #productSearch #content img, .naviImageContainer img").live("click", function() {
//		_gaq.push(['_trackEvent', 'Bilder', 'Angeklickt', caculatePicNameFromSrc(this)]);
//	});
	$j(".trackingPic").click(function() {
		var trackinginfo = caculatePicAttrFromSrc(this);
		if (trackinginfo != undefined) {
			createGoogleEventTracking('Bilder', trackinginfo, null);
		}
	});
	
	
	// Farbe, Ausführung und Größe auch in initAvailMatrix();
	// Farbe
	$j(".sobercontainer .sfarben img, #colorsToShow img").live("click", function() {
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Farbe', $j(this).attr('alt'));
	});
	$j("#modelSelector option, #infoSelects .selectModel option").live("click", function() {
		if ($j(this).val() != 0 && $j(this).text().split(' ').length > 0) {		
			createGoogleEventTracking('Auswahl der Artikelattribute', 'Farbe', $j(this).text().split(' ')[0]);
		}
	});
	$j("#infoSelects #selectPromoItem option").live("click", function() {
		if ($j(this).parent().attr('name') == 'color') {		
			createGoogleEventTracking('Auswahl der Artikelattribute', 'Farbe', $j(this).text().split(' ')[0]);
		} else if ($j(this).parent().attr('name') == 'pid') {
			createGoogleEventTracking('Auswahl der Artikelattribute', 'Ausführung', $j(this).text().split(' ')[0]);
		}
	});
	
	// Ausführung
	$j(".modelSelectorNew .selectModelPromoItem option").live("click", function() {
		if ($j(this).val() != 0 && $j(this).text().split(' ').length > 0) {		
			createGoogleEventTracking('Auswahl der Artikelattribute', 'Ausführung', $j(this).text().split(' ')[0]);
		}
	});
	$j(".modelSelectorNew .chooseModel li span").live("click", function() {
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Ausführung', $j(this).text());
	});
	
	// Größe	
	$j(".sizeSelectorNew .soldItems li").live("click", function() {
		createGoogleEventTracking('Auswahl der Artikelattribute', 'Größe', $j(this).text());
	});
	$j(".selectMissingSize option, #infoSelects #selSize option").live("click", function() {
		if ($j(this).val() != 0) {		
			createGoogleEventTracking('Auswahl der Artikelattribute', 'Größe', $j(this).text().trim());
		}
	});
	
	// Outfit in openOutfitOrderInShadowBox() oder openSmallOutfitOrderInShadowBox()
	
	// Zoom
	$j("#product #zoomLink, #product #grossbild").click(function() {
		createGoogleEventTracking('Funktionalitäten (Links oder Buttons)', 'Zoom', null);
	});	
	// Video
	$j("#product #videoLink").click(function() {
		createGoogleEventTracking('Funktionalitäten (Links oder Buttons)', 'Video', null);
	});
	
	// Maßtabelle, Merken, Empfehlen, Modelexikon, Drucken
	$j("#showSizeChart, #merken, #recommend, #showDictionaryTerms, #printArticleInformation").click(function() {
		createGoogleEventTracking('Funktionalitäten (Links oder Buttons)', $j(this).text().split(' ')[0], null);
	});	
	// alle Größen ein Preis
	$j("#agep, #ageptext").click(function() {
		createGoogleEventTracking('Funktionalitäten (Links oder Buttons)', 'alle Größen ein Preis', null);
	});
	// Verfügbare Farben und Größen
	$j("#showAvailMatrix").click(function() {
		createGoogleEventTracking('Funktionalitäten (Links oder Buttons)', 'Verfügbare Farben und Größen', null);
	});
	
	// EHI Logo
	$j(".ads_ehi, #ehi, #ehitext, #ehi_siegel").click(function() {
		createGoogleEventTracking('Logo', 'EHI Logo', null);
	});
	// Ekomi Logo
	$j("#ekomiSiegel, #ekomistars").click(function() {
		createGoogleEventTracking('Logo', 'Ekomi Logo', null);
	});
	
	// Zuletzt gesehene Artikel
	$j("#lastViewed img").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Zuletzt gesehene Artikel', 'Auf Detailseite');
	});
	// Dazu passende Artikel
	$j(".hasOutfit a").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Dazu passende Artikel', 'Auf Detailseite');
	});
	// Ähnliche Artikel
	$j("#similarArticle a").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Ähnliche Artikel', 'Auf Detailseite');
	});
	$j("#categoriesList a").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Ähnliche Artikel', 'Auf Artikelliste');
	});
	// empfohlene Artikel
	$j(".hasRecomm a").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Empfohlene Artikel(Dies könnte Ihnen auch gefallen)', 'Auf Detailseite');
	});
	$j("#recommondations li a").click(function() {
		createGoogleEventTracking('Artikelempfehlungen', 'Empfohlene Artikel(Dies könnte Ihnen auch gefallen)', 'Auf Warenkorbseite');
	});
	
	// Bewertung
	$j(".sproductcontainer .rating").click(function() {
		createGoogleEventTracking('Bewertung', 'Aufgerufen', 'Artikelliste');
	});
	$j("#product .jumpToRatings").click(function() {
		createGoogleEventTracking('Bewertung', 'Aufgerufen', 'Detailseite');
	});
	$j(".reviewHelpully a").live("click", function() {
		createGoogleEventTracking('Bewertung', 'Hilfreich ja/nein gewählt', $j(this).text());
	});
	
	// Facebook in partial_facebook.ftl
	
	// Blätterung
	$j(".paging a").live("click", function() {
		if ($j(this).text() != null && $j(this).text() != ' ' && $j(this).text() != '') {
			createGoogleEventTracking('Blätterung', $j(this).text(), null);
		} else {
			createGoogleEventTracking('Blätterung', 'Vorherige/Nächste Seite', null);
		}
	});
	
	// Artikel Pro Seite, auch in SearchFilter()
	$j("#resultsPerPage option").click(function(event) {
		createGoogleEventTracking('Artikel Pro Seite', $j(this).val(), null);
	});
	
	// Sortierung, auch in SearchFilter()
	$j("#sortType option").click(function(event) {
		if ($j(this).val() != '1') {		
			createGoogleEventTracking('Sortierung', locateListPageName(), $j(this).text());
		} else {
			createGoogleEventTracking('Sortierung', locateListPageName(), 'Auswahl aufheben');
		}
	});
	$j("#content #categoryFilter #sorting a").click(function() {
		createGoogleEventTracking('Filter',  'Lucene Seite', $j(this).text());
	});
	
	
	// Filter , auch in $el.slider callback (price, material)
	$j('.searchFilter a').live("click", function() {
		if ($j(this).parent().attr('data-filter') != null && $j(this).parent().attr('data-filter').split("=").length > 1) {			
			if ($j(this).parent().hasClass('active')) {
				createGoogleEventTracking('Filter', locateListPageName(), $j(this).parent().attr('data-filter').split("=")[0] + ' aufgehoben');
			} else {
				createGoogleEventTracking('Filter', locateListPageName(), $j(this).parent().attr('data-filter').split("=")[0] + ' gesetzt');
			}		
		}
	});
	$j('.noFilter').live("click", function() {
		createGoogleEventTracking('Filter',  locateListPageName(), 'alle Filter zurücksetzen gesetzt');
	});
	$j("#content #categoryFilter #f_s_size a").click(function() {
		if ($j(this).text() == "alle anzeigen") {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Größe aufgehoben');
		} else {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Größe gesetzt');
		}
	});
	$j("#content #categoryFilter #f_n_variation_rating a").click(function() {
		if ($j(this).text() == "lieferbar") {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Lieferbar aufgehoben');
		} else {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Lieferbar gesetzt');
		}
	});
	$j("#content #categoryFilter #f_s_brand a").click(function() {
		if ($j(this).text() == "alle anzeigen") {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Marken aufgehoben');
		} else {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Marken gesetzt');
		}
	});
	$j("#content #categoryFilter #f_s_color a").click(function() {
		if ($j(this).text() == "alle anzeigen") {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Farben aufgehoben');
		} else {
			createGoogleEventTracking('Filter',  'Lucene Seite', 'Farben gesetzt');
		}
	});

	// Suchbox
	$j('#suchBox .suchButton').click(function(){
		createGoogleEventTracking('Suchbox', $j("#queryString").val(), null);
	});	
}

function locateListPageName() {
	if ($j('#productSearch').length > 0) {
		return "Suchergebnisse Seite";
	}
	return 'Artikelliste';
}

function caculatePicAttrFromSrc(obj) {
	var srcName = $j(obj).attr('data-trackinginfo');
	return srcName;
}

function createGoogleEventTracking(category, action, label) {
	if (typeof _gaq != 'undefined') {
		if (label == null && action != null) {			
			_gaq.push(['_trackEvent', category, action]);
		} else if (action == null) {
			_gaq.push(['_trackEvent', category]);
		} else {
			_gaq.push(['_trackEvent', category, action, label]);
		}
	}
}

function showRatenCalculator(obj) {
	var subtotal = obj.attr('data-subtotal');

	$j.ajax({
		type: "POST",
		url: "/ajax_calculatorHelper.html",
		data: {total : subtotal},
		dataType :"html",
		success : function(html) {
			$j("#bestellcontent #ratecalculatorLayer").html(html);
			$j("#bestellcontent #ratecalculatorLayer").css("display","block");
			$j("#bestellcontent #ratecalculatorLayer input").focus();
			
		    $j('#ratecalculatorLayer #amount').keyup(function() {
				var amount_value=$j("#ratecalculatorLayer #amount").val();
				var amount_pattern=/^\d+[\.|\,]?\d{0,2}$/;
				if (amount_pattern.test(amount_value)==false)
				{
					$j("#ratecalculatorLayer #error").css("visibility", "visible");
					$j("#ratecalculatorLayer #rc_submit").unbind("click");
				}
				else
				{
					$j("#rc_submit").attr('data-subtotal', $j('#ratecalculatorLayer #amount').val());
					$j("#ratecalculatorLayer #error").css("visibility", "hidden");
					$j("#ratecalculatorLayer #rc_submit").unbind("click").click(function() {
						showRatenCalculator($j(this));
					});
				}
			});
			
			$j("#ratecalculatorLayer #rc_submit").unbind("click").click(function() {
				showRatenCalculator($j(this));
			});
		}
	});
}

function showMoreArticles(obj) {

	obj.unbind('click');
	obj.addClass('disabled');
	var requestUrl = obj.attr('data-url');
	var currentPage = requestUrl.split('page=')[1];
	var nextPage = parseInt(currentPage) + 1;
	var newUrl = requestUrl.split('page=')[0] + "page=" + nextPage;
	var pageCnt = obj.attr('data-pageCnt');
	var shopKey = obj.attr('data-shopKey');
	requestUrl = requestUrl.split('?')[1];

	$j.ajax({
		type: "POST",
		url: baseUrl + "/ajax_showMoreArticles.html?" + requestUrl,
		data: {shopKey : shopKey, index : $j('.sobercontainer').children().last().index()},
		dataType :"html",
		success : function(html) {
			$j('.sobercontainer').append(html);
			if (pageCnt == currentPage) {
				obj.css('display', 'none');
			} else {
				obj.attr('data-url', newUrl);				
			}
			obj.removeClass('disabled');
			$j("#productListPagingBottom .more").unbind("click").click(function(){
				showMoreArticles($j(this));
			});
		}
	});
}

