﻿// Nov 11 scripts.js bauknecht.de

/*PLUG IN PNG FIX*/
/**
* DD_belatedPNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
* Version: 0.0.8a
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_belatedPNG/#license
*
* Example usage:
* DD_belatedPNG.fix('.png_bg'); // argument is a CSS selector
* DD_belatedPNG.fixPng( someNode ); // argument is an HTMLDomElement
**/
if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
var DD_belatedPNG={ns:"DD_belatedPNG",imgSize:{},delay:10,nodesFixed:0,createVmlNameSpace:function(){if(document.namespaces&&!document.namespaces[this.ns]){document.namespaces.add(this.ns,"urn:schemas-microsoft-com:vml")}},createVmlStyleSheet:function(){var b,a;b=document.createElement("style");b.setAttribute("media","screen");document.documentElement.firstChild.insertBefore(b,document.documentElement.firstChild.firstChild);if(b.styleSheet){b=b.styleSheet;b.addRule(this.ns+"\\:*","{behavior:url(#default#VML)}");b.addRule(this.ns+"\\:shape","position:absolute;");b.addRule("img."+this.ns+"_sizeFinder","behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;");this.screenStyleSheet=b;a=document.createElement("style");a.setAttribute("media","print");document.documentElement.firstChild.insertBefore(a,document.documentElement.firstChild.firstChild);a=a.styleSheet;a.addRule(this.ns+"\\:*","{display: none !important;}");a.addRule("img."+this.ns+"_sizeFinder","{display: none !important;}")}},readPropertyChange:function(){var b,c,a;b=event.srcElement;if(!b.vmlInitiated){return}if(event.propertyName.search("background")!=-1||event.propertyName.search("border")!=-1){DD_belatedPNG.applyVML(b)}if(event.propertyName=="style.display"){c=(b.currentStyle.display=="none")?"none":"block";for(a in b.vml){if(b.vml.hasOwnProperty(a)){b.vml[a].shape.style.display=c}}}if(event.propertyName.search("filter")!=-1){DD_belatedPNG.vmlOpacity(b)}},vmlOpacity:function(b){if(b.currentStyle.filter.search("lpha")!=-1){var a=b.currentStyle.filter;a=parseInt(a.substring(a.lastIndexOf("=")+1,a.lastIndexOf(")")),10)/100;b.vml.color.shape.style.filter=b.currentStyle.filter;b.vml.image.fill.opacity=a}},handlePseudoHover:function(a){setTimeout(function(){DD_belatedPNG.applyVML(a)},1)},fix:function(a){if(this.screenStyleSheet){var c,b;c=a.split(",");for(b=0;b<c.length;b++){this.screenStyleSheet.addRule(c[b],"behavior:expression(DD_belatedPNG.fixPng(this))")}}},applyVML:function(a){a.runtimeStyle.cssText="";this.vmlFill(a);this.vmlOffsets(a);this.vmlOpacity(a);if(a.isImg){this.copyImageBorders(a)}},attachHandlers:function(i){var d,c,g,e,b,f;d=this;c={resize:"vmlOffsets",move:"vmlOffsets"};if(i.nodeName=="A"){e={mouseleave:"handlePseudoHover",mouseenter:"handlePseudoHover",focus:"handlePseudoHover",blur:"handlePseudoHover"};for(b in e){if(e.hasOwnProperty(b)){c[b]=e[b]}}}for(f in c){if(c.hasOwnProperty(f)){g=function(){d[c[f]](i)};i.attachEvent("on"+f,g)}}i.attachEvent("onpropertychange",this.readPropertyChange)},giveLayout:function(a){a.style.zoom=1;if(a.currentStyle.position=="static"){a.style.position="relative"}},copyImageBorders:function(b){var c,a;c={borderStyle:true,borderWidth:true,borderColor:true};for(a in c){if(c.hasOwnProperty(a)){b.vml.color.shape.style[a]=b.currentStyle[a]}}},vmlFill:function(e){if(!e.currentStyle){return}else{var d,f,g,b,a,c;d=e.currentStyle}for(b in e.vml){if(e.vml.hasOwnProperty(b)){e.vml[b].shape.style.zIndex=d.zIndex}}e.runtimeStyle.backgroundColor="";e.runtimeStyle.backgroundImage="";f=true;if(d.backgroundImage!="none"||e.isImg){if(!e.isImg){e.vmlBg=d.backgroundImage;e.vmlBg=e.vmlBg.substr(5,e.vmlBg.lastIndexOf('")')-5)}else{e.vmlBg=e.src}g=this;if(!g.imgSize[e.vmlBg]){a=document.createElement("img");g.imgSize[e.vmlBg]=a;a.className=g.ns+"_sizeFinder";a.runtimeStyle.cssText="behavior:none; position:absolute; left:-10000px; top:-10000px; border:none; margin:0; padding:0;";c=function(){this.width=this.offsetWidth;this.height=this.offsetHeight;g.vmlOffsets(e)};a.attachEvent("onload",c);a.src=e.vmlBg;a.removeAttribute("width");a.removeAttribute("height");document.body.insertBefore(a,document.body.firstChild)}e.vml.image.fill.src=e.vmlBg;f=false}e.vml.image.fill.on=!f;e.vml.image.fill.color="none";e.vml.color.shape.style.backgroundColor=d.backgroundColor;e.runtimeStyle.backgroundImage="none";e.runtimeStyle.backgroundColor="transparent"},vmlOffsets:function(d){var h,n,a,e,g,m,f,l,j,i,k;h=d.currentStyle;n={W:d.clientWidth+1,H:d.clientHeight+1,w:this.imgSize[d.vmlBg].width,h:this.imgSize[d.vmlBg].height,L:d.offsetLeft,T:d.offsetTop,bLW:d.clientLeft,bTW:d.clientTop};a=(n.L+n.bLW==1)?1:0;e=function(b,p,q,c,s,u){b.coordsize=c+","+s;b.coordorigin=u+","+u;b.path="m0,0l"+c+",0l"+c+","+s+"l0,"+s+" xe";b.style.width=c+"px";b.style.height=s+"px";b.style.left=p+"px";b.style.top=q+"px"};e(d.vml.color.shape,(n.L+(d.isImg?0:n.bLW)),(n.T+(d.isImg?0:n.bTW)),(n.W-1),(n.H-1),0);e(d.vml.image.shape,(n.L+n.bLW),(n.T+n.bTW),(n.W),(n.H),1);g={X:0,Y:0};if(d.isImg){g.X=parseInt(h.paddingLeft,10)+1;g.Y=parseInt(h.paddingTop,10)+1}else{for(j in g){if(g.hasOwnProperty(j)){this.figurePercentage(g,n,j,h["backgroundPosition"+j])}}}d.vml.image.fill.position=(g.X/n.W)+","+(g.Y/n.H);m=h.backgroundRepeat;f={T:1,R:n.W+a,B:n.H,L:1+a};l={X:{b1:"L",b2:"R",d:"W"},Y:{b1:"T",b2:"B",d:"H"}};if(m!="repeat"||d.isImg){i={T:(g.Y),R:(g.X+n.w),B:(g.Y+n.h),L:(g.X)};if(m.search("repeat-")!=-1){k=m.split("repeat-")[1].toUpperCase();i[l[k].b1]=1;i[l[k].b2]=n[l[k].d]}if(i.B>n.H){i.B=n.H}d.vml.image.shape.style.clip="rect("+i.T+"px "+(i.R+a)+"px "+i.B+"px "+(i.L+a)+"px)"}else{d.vml.image.shape.style.clip="rect("+f.T+"px "+f.R+"px "+f.B+"px "+f.L+"px)"}},figurePercentage:function(d,c,f,a){var b,e;e=true;b=(f=="X");switch(a){case"left":case"top":d[f]=0;break;case"center":d[f]=0.5;break;case"right":case"bottom":d[f]=1;break;default:if(a.search("%")!=-1){d[f]=parseInt(a,10)/100}else{e=false}}d[f]=Math.ceil(e?((c[b?"W":"H"]*d[f])-(c[b?"w":"h"]*d[f])):parseInt(a,10));if(d[f]%2===0){d[f]++}return d[f]},fixPng:function(c){c.style.behavior="none";var g,b,f,a,d;if(c.nodeName=="BODY"||c.nodeName=="TD"||c.nodeName=="TR"){return}c.isImg=false;if(c.nodeName=="IMG"){if(c.src.toLowerCase().search(/\.png$/)!=-1){c.isImg=true;c.style.visibility="hidden"}else{return}}else{if(c.currentStyle.backgroundImage.toLowerCase().search(".png")==-1){return}}g=DD_belatedPNG;c.vml={color:{},image:{}};b={shape:{},fill:{}};for(a in c.vml){if(c.vml.hasOwnProperty(a)){for(d in b){if(b.hasOwnProperty(d)){f=g.ns+":"+d;c.vml[a][d]=document.createElement(f)}}c.vml[a].shape.stroked=false;c.vml[a].shape.appendChild(c.vml[a].fill);c.parentNode.insertBefore(c.vml[a].shape,c)}}c.vml.image.shape.fillcolor="none";c.vml.image.fill.type="tile";c.vml.color.fill.on=false;g.attachHandlers(c);g.giveLayout(c);g.giveLayout(c.offsetParent);c.vmlInitiated=true;g.applyVML(c)}};try{document.execCommand("BackgroundImageCache",false,true)}catch(r){}DD_belatedPNG.createVmlNameSpace();DD_belatedPNG.createVmlStyleSheet();
}

var IE = /*@cc_on!@*/false;
var pictureProduct = "";

$( document ).ready( function() {
	
	if($.browser.msie && $.browser.version=="6.0") {
	DD_belatedPNG.fix('#main_content_wrapper .border-box .carousel-wrapper .carousel .item .info .button,#main_content_wrapper .border-box .carousel-wrapper .carousel .item .info .button,.cont_group.themePLT #links_container .product-link,.cont_group.themePLT #links_container .add-to-wishlist,.cont_group.themePLT #links_container .product-link');
	$("#ie6-popup").load("/other-assets/de_DE/ie6-popup/ie6.html");
		$("#ie6-popup").dialog({
		  modal:true,
		  autoOpen: true
		});
	}
	//JS fix for the menu. Move the subheader div inside the header div. Only for IE8.
	if($.browser.msie && $.browser.version=="8.0") {
		$('#wrap .common_header #header').append( $('#wrap .sub-header') );
	}
});

function priceSlider(minVal, maxVal) {
	if(minVal!=maxVal){
		$slider = $("#slider");
		$amountMin = $("#amountMin");
		$amountMax = $("#amountMax");
		$milestone1 = $("#milestone1");
		$slider.slider({   	
			range: true, // necessary for creating a range slider
			min: parseInt(minVal), // minimum range of slider
			max: parseInt(maxVal), // maximimum range of slider
			values: [parseInt(minVal),parseInt(maxVal)], //initial range of slider
			slide: function(event, ui) { // This event is triggered on every mouse move during slide.
				$amountMin.val(ui.values[0]);
				$amountMax.val(ui.values[1]);
				$('.ui-slider-range').css('background-image', imageUrl);
				
			},
			stop: function(event, ui){
				imageUrl = $('.ui-slider-range').css("background-image").replace('_over','');
				$('.ui-slider-range').css('background-image', imageUrl);
				// Add the over again so when the user slides it will be shown
				imageUrl = $('.ui-slider-range').css("background-image").replace(".png", "_over.png");
				//Call ajax function here so the products are updated.
				// Example
				// $products.load('ajaxSlider.php?minValue='+ui.values[0]+'&maxValue='+ui.values[1],'',function() });
				EndecaHelperJS.refreshProductsByPriceRange(ui.values[0], ui.values[1]);
				
				
			}
		});
		imageUrl = $('.ui-slider-range').css("background-image").replace(".png", "_over.png");
		//preLoadImagePath = imageUrl.replace('url("','');
		//preLoadImagePath = preLoadImagePath.replace('")','');
		//jQuery.preLoadImages("slider_gradient_over.png", "preLoadImagePath");
		$amountMin.val($slider.slider("values", 0));
		$milestone1.html($slider.slider("values", 0));
		$amountMax.val($slider.slider("values", 1));
		var children = $('#price-milestone-wrapper').children().size(); 
		var mileStoneValue = new Number(0);
		var newPos =0;
		var newValue = 0;
		var range = $slider.slider("values", 1) - $slider.slider("values", 0);
		for (i=1;i<=children;i++){
			if(i != 1) {
				mileStoneValue += (1/(children-1));
				newValue = Number($slider.slider("values", 0) + (range * mileStoneValue)).toFixed();
				$("#milestone"+ i).html(newValue);	
			}
			// 6.5 is the half the width of the slider button in px
			newPos = ($("#milestone"+ i).width()/2) - 5;
			$("#milestone"+ i).offset({top:$("#milestone"+ i).offset().top,   left:$("#milestone"+ i).offset().left - newPos });
		}
		
		$("#amountMin").blur(function () {		
		  $slider.slider("values", 0,Math.min($slider.slider("values", 1),parseInt($(this).val()) ) );
		  $(this).val(Math.min($slider.slider("values", 1),parseInt($(this).val())));
		  EndecaHelperJS.refreshProductsByPriceRange($slider.slider("values", 0), $slider.slider("values", 1));
		  
		});
		$("#amountMax").blur(function () {
		  $slider.slider("values",1,Math.max($slider.slider("values", 0),parseInt($(this).val()) ) );							   
		  $(this).val(Math.max($slider.slider("values", 0),parseInt($(this).val())));
		  EndecaHelperJS.refreshProductsByPriceRange($slider.slider("values", 0), $slider.slider("values", 1));
		});
		
		$(".ui-slider-handle").each(function(index){							
			if (index == 0){
				$(this).addClass("leftButton");	
			}
			else {
				$(this).addClass("rightButton");
			}
		});
	}else{
		$("#page #main_content_wrapper .cl-side .price-range-container").css("display", "none");
	 
	}
 }
 
/* Main Menu functions */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var productFlyout;

$.fn.equalHeightsMenu = function() {
	
	$(this).each(function(){
		//get size of the li
		var menuLength = $(this).children().length;
		//get the current li
		var menuCounter = 0;
		var currentTallest = 0;
		var paragraph = $(this).find("p");
		var anchor = $(paragraph).find("a");
		var pHeight = 1;
		var aLetters = 20;
		if($(anchor).text().length > aLetters){
			pHeight = 2;
		}
		$(paragraph).height(15*pHeight);
		
		/*$(this).find( ".menu-thumb" ).children().each(function(i){
			if (!$(this).hasClass("dropdown-image")) {
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }	
			}
		});*/
		$(this).find(".menu-thumb > ul").each(function(){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
	
		if ($.browser.msie && $.browser.version == 6.0) { $(this).find( ".menu-thumb > ul").css({'height': currentTallest}); }
		$(this).find( ".menu-thumb > ul").css({'min-height': currentTallest}); 
		
		//remove the last vertical line
		/*$(this).children().each(function(){
			
			if(menuCounter==(menuLength-1)){
				
				$(this).children().each(function(){
					
					$(this).css('border', 'none');
				});
			}
			menuCounter++;
		});*/
		
	});
};

$.fn.removeBorders = function() {
	var cont = 0;
	var size = $(this).length;
	$(this).each(function(){		
		cont++;	
		if (cont > 6 || size < 7)  {
			$(this).css("border-bottom","none");
		}
	});
};

$.fn.equalHeights = function(find,exclude,fixedHeight,addHeight) {
	var current = 0;
	$(this).css({'visibility': 'hidden'}); 
	if (fixedHeight != 0) {
		$(this).each(function(){
			$(this).children(find).each(function(i){
				if(!$(this).hasClass(exclude)){
					$(this).css({'height': fixedHeight}); 
				}
			});
		});
	}
	else {
		
		$(this).each(function(){
			$(this).children(find).each(function(i){
				if(!$(this).hasClass(exclude)){
					if ($(this).height() > current) { current = $(this).height(); }
				}
			});
			$(this).children(find).each(function(i){
				if(!$(this).hasClass(exclude)){
					$(this).css({'height': current+addHeight}); 
				}
			});
		});
	}
	$(this).css({'visibility': 'visible'}); 
	return current;
};

//$(window).load(	function() {

//}); 

$.fn.equalWidths = function(find,exclude) {
	var current = 0;
	$(this).each(function(){
		$(this).children(find).each(function(i){
			if(!$(this).hasClass(exclude)){
				if ($(this).width() > current) { current = $(this).width(); }
			}
		});
		$(this).children(find).each(function(i){
			if(!$(this).hasClass(exclude)){
				$(this).css({'min-width': current}); 
			}
		});
	});
	return current;
}; 

/*
function menuOpen(){  
	$(this).addClass("selected");
	$( this ).find('.menu-thumb').removeBorders();
	//ddmenuitem = $( this ).children(".dropdown-menu-header" ).css( "visibility", "visible" );
	ddmenuitem = $( this ).children(".dropdown-menu-header" ).css( "display", "block" );
	$('.menu-list').equalHeightsMenu();
}

function menuClose(){  
	$(this).removeClass("selected");
	if ( ddmenuitem )	{
	//	ddmenuitem.css( "visibility", "hidden" );
		ddmenuitem.css( "display", "none" );
	}
}
*/

var delay = true;
var currentMenu;
$(document).ready(function(){
	$("#main-menu").mouseleave(function(){
		delay = true;
	});
});
	

function menuOpen(){

currentMenu =$(this);
	if(delay){
		$(this).addClass("delay");
		var timeout = setTimeout("delayMenuOpen()",500);
		ddmenuitem = $( this ).children(".dropdown-menu-header" );
	}else{	
		$(this).addClass("selected");
		$( this ).find('.menu-thumb').removeBorders();
		//ddmenuitem = $( this ).children(".dropdown-menu-header" ).css( "visibility", "visible" );
		ddmenuitem = $( this ).children(".dropdown-menu-header" ).css( "display", "block" );
		$('.menu-list').equalHeightsMenu();
	}
}

 function delayMenuOpen(){
 //alert(delay);
    if(delay){
		if($(currentMenu).hasClass("delay")){
			$(currentMenu).addClass("selected");
			$( currentMenu ).find('.menu-thumb').removeBorders();
			delay = false;
			ddmenuitem = $( currentMenu ).children(".dropdown-menu-header" ).css( "display", "block" );
			$('.menu-list').equalHeightsMenu();
		}
    }
    
 }
function menuClose(){
	$(this).removeClass("delay");
	$(this).removeClass("selected");
	if ( ddmenuitem )	{
	//	ddmenuitem.css( "visibility", "hidden" );
		ddmenuitem.css( "display", "none" );
	}
	
}


$( document ).ready( function()
{
	if ( $("#WHRFeaturedItemsArea_div_2 #product_carousel").length > 0 ) 	{	
		$('#WHRFeaturedItemsArea_div_2 #product_carousel').equalHeights(".carousel-item","",0,80);
	}
	// set the value of the search input field
	if ( $ ("#searchTermValue" ).html() && $( "#searchTermValue" ).html().length > 0 ) 	
	{
		$( "#searchTerm" ).val( $( "#searchTermValue" ).html() ); 
	}
	$("#header .textsearch-container .search-textbox").focus(function(){this.select();});
	$("#page.productlist-page #main_content_wrapper .cl-side .price-range-container .min-max .range").focus(function(){this.select();});
	$("#header .textsearch-container .search-button").click(function(){$("#header .textsearch-container .search-textbox").focus()});
	$(".product_detail_page .product-carousel .carousel-item a.product-image-gallery").click(selectPictureGallery);
	$(".product_detail_page a.video-image-link").click(function(){$(".text-information-box").css("display","none");  $("#tabclose_video .video_box").css("display","none");  });
	$("#page.product_detail_page .video_box .closeLink").click(function(){$("#page.product_detail_page .video_box img").trigger("click");return false;});
	$("#page.product_detail_page #tab_video .closeLink").click(function(){$(".text-information-box").css("display","block");  $("#tabclose_video .video_box").css("display","block");  });
	//$(".color-available li").click(colorPicker); remove this one for issue WHPUK-977
	
	$("#SameShippingAndBillingAddress").click(copyAddress);
	$( ".table-compare-products .section-toggle" ).toggle( 
		function() 
		{
			var section = $( this ).attr( "section" );
			$( ".table-compare-products ." + section ).fadeOut( "fast" );
			$(this).addClass("collapsed");
			var $dif = $( this ).find( "span.differences" ).fadeIn( "fast" );
			return false;
		},
		function()
		{
			var section = $( this ).attr( "section" );
			$( ".table-compare-products ." + section ).fadeIn( "fast" );
			$(this).removeClass("collapsed");
			var $dif = $( this ).find( "span.differences" ).fadeOut( "fast" );
			return false;
		} );
	
	/*Uk MywishList page it's used to make the left menu same size as the content*/		


	positionMiniCart();
	$(".ContactUs .ok_button").click(function(e){e.preventDefault();showHide(".contactus_form,.form_title","")});
	$(".ContactUs .send_request a").click(function(e){e.preventDefault();showHide(".thank_submission","#by_e-mail_box,#by_mail_box,#by_phone_box,.tittle_text,.contactus_form")});
	$("#SameShippingAndBillingAddress").click(copyAddress);
	
	
	/* ---------------------- */	
	/* bindings for main menu */
	$( "#main-menu > li" ).bind( "mouseenter", menuOpen );
	$( "#main-menu > li" ).bind( "mouseleave", menuClose );
	
	
	$( "#header .language-select" ).toggle( function()
		{
			$( "#header .language-list" ).show();
			return false;
		},
		function()
		{
			$( "#header .language-list" ).hide();
			return false;
		});
		
	$( "#header .language-select ul li a" ).toggle( function()
		{
			$( "#header .language-list" ).show();
			return false;
		},
		function()
		{
			$( "#header .language-list" ).hide();
			return false;
		});
		
		
	$( "#header .sub-header .print" ).click( function()
	{
		window.print();
		return false;
	});


	/* list and grid views */
	
//	$( ".product-list-header-controls .product-list-header .view-controls ul li .grid-view" ).click( function()
//	{
//		$( ".productlist-page .search-container .results-lists" ).removeClass( "list-view" );
//		$( ".productlist-page .search-container .results-lists" ).addClass( "grid-view" );
//		$( ".product-list-header-controls .product-list-header .view-controls ul li .list-view" ).removeClass( "selected" );
//		$( ".product-list-header-controls .product-list-header .view-controls ul li .grid-view" ).addClass( "selected" );
//		
//		return false;
//	});

//	$( ".product-list-header-controls .product-list-header .view-controls ul li .list-view" ).click( function()
//	{
//		$( ".productlist-page .search-container .results-lists" ).removeClass( "grid-view" );
//		$( ".productlist-page .search-container .results-lists" ).addClass( "list-view" );
//		$( ".product-list-header-controls .product-list-header .view-controls ul li .list-view" ).addClass( "selected" );
//		$( ".product-list-header-controls .product-list-header .view-controls ul li .grid-view" ).removeClass( "selected" );
//		
//		return false;
//	});	
	
    BindCompareCheckBoxes();
/*addressbook_.php*/
	$(document).ready(function() {
		$(".btn_edit").click(function() {
			$('.edit-form').show();
			$('#view-form').hide();
			$('.btn_remove').hide();
			$('.btn_edit').hide();
			$('.btn_update').show();

		});
		$(".btn_update").click(function() {
			$('.edit-form').hide();
			$('#view-form').show();
			$('.btn_remove').show();
			$('.btn_edit').show();
			$('.btn_update').hide();
		});
	});

/*END addressbook_.php*/

	/* ----- End Product List Page ----- */	
	/* --------------------------------- */
	
/*-----searchResultPage.html (expand or contract elements in left_nav)
by: Luis Diego H.-----*/
	$(document).ready(function()
	{
		$("#page.search-results-page #left_nav .second_div h2").click(expandElements);		
//		$(".search-results-page .results-grid-view").click(function(e){toggleClass(e,"grid-view","list-view")});
//		$(".search-results-page .results-list-view").click(function(e){toggleClass(e,"list-view","grid-view")});
//		$(".search-results-page .view-list li a.grid-view").click(function(e){toggleClass(e,"grid-view","list-view")});
//		$(".search-results-page .view-list li a.list-view").click(function(e){toggleClass(e,"list-view","grid-view")});	
	});
	
	function expandElements(e){
		e.preventDefault();
		if($("#page.search-results-page #left_nav .second_div").hasClass("expand")){
			$("#page.search-results-page #left_nav .second_div").removeClass("expand");
		}else{
			$("#page.search-results-page #left_nav .second_div").addClass("expand");
		}
	}	
		
	function toggleClass(e,add,remove){		
		e.preventDefault();	
		$(".body588").removeClass(remove);
		$(".body588").addClass(add);		
	}		
/*-----END searchResultPage.html-----*/

/*-----Personal Information Page
by: Luis Diego H.
-----*/

	$(".PersonalInformationPage a.edit-button").click(function(e){showInfo(e,"showdiv","")});
	$(".PersonalInformationPage a.update_link").click(function(e){showInfo(e,"showdiv","error")});
	
function showInfo(e, classy, state){
	e.preventDefault();
	$(".personal-information").removeClass(classy);
	$(".form-div").addClass(classy);
	$(".title-information").addClass(classy);
	$(".form-div").addClass(state);
}	

/*-----END Personal Information Page-----*/

	
	/*This is the functionality of the selector for display pagination
	* by: Melania Gonzalez
	*/
	$( "#dropdown_1_a.pagination-select" ).toggle( function()
		{
			$( "#dropdown_1.pagination-list" ).show();
			return false;
		},
		function()
		{
			$( "#dropdown_1.pagination-list" ).hide();
			return false;
		});
		
	$( "#dropdown_1_a.pagination-select ul li a" ).toggle( function()
		{
			$( "#dropdown_1.pagination-list" ).show();
			return false;
		},
		function()
		{
			$( "#dropdown_1.pagination-list" ).hide();
			return false;
		});
	
	
	$( "#dropdown_2_a.pagination-select" ).toggle( function()
		{
			$( "#dropdown_2.pagination-list" ).show();
			return false;
		},
		function()
		{
			$( "#dropdown_2.pagination-list" ).hide();
			return false;
		});
		
	$( "#dropdown_2_a.pagination-select ul li a" ).toggle( function()
		{
			$( "#dropdown_2.pagination-list" ).show();
			return false;
		},
		function()
		{
			$( "#dropdown_2.pagination-list" ).hide();
			return false;
		});
	/*End of code by Melania Gonzalez*/


	
	
	$( "#box .packages .summary .add-to-cart" ).click( function()
	{
		$( "#popup-added-to-cart" ).fadeIn( "fast" );
		$( "#popup-added-to-cart" ).center();
		return false;
	});
	
	$( "#popup-added-to-cart a" ).click( function()
	{
		$( "#popup-added-to-cart" ).fadeOut( "fast" );
		return false;
	});
	
	
	$( "#box .choose-a-coupon" ).click( function()
	{
		$( "#popup-choose-coupon" ).fadeIn( "fast" );
		$( "#popup-choose-coupon" ).center();
		return false;
	});
	
	$( "#popup-choose-coupon a" ).click( function()
	{
		$( "#popup-choose-coupon" ).fadeOut( "fast" );
		return false;
	});
	
	
	$( "#box .shipping-costs-container .shipping-costs-link" ).click( function()
	{
		$( "#popup-shipping-costs" ).fadeIn( "fast" );
		$( "#popup-shipping-costs" ).center();
		return false;
	});

	$( "#popup-shipping-costs .close" ).click( function()
	{
		$( "#popup-shipping-costs" ).fadeOut( "fast" );
		return false;
	});
	
	$( "#box .promo-codes .ok" ).click( function()
	{
		$( "#box .promo-codes .error-message" ).html( "This code is not valid" );
		return false;
	});
	
	
	$( "#returning-customer-container .sign-in" ).click( function()
	{
		$( "#returning-customer-container .email-error" ).slideDown( "fast" );
		$( "#returning-customer-container .password-error" ).slideDown( "fast" );
		return false;
	});
	
	
	
	
	$( "#order_details .increment, #order_details .decrement" ).click( function()
	{
		$( "#popup-quantity-error" ).fadeIn( "fast" );
		$( "#popup-quantity-error" ).center();
	});
	
	$( "#popup-quantity-error .close" ).click( function()
	{
		$( "#popup-quantity-error" ).fadeOut( "fast" );
		return false;
	});
		
});

/* ----- Product Details Page ----- */

$( document ).ready( function()
{
    $( ".share" ).click( function()
	{
		$( "#popup-send-to-friend" ).show();
		return false;
	});
  $("#page.product_detail_page ul.gallery-images li img").mouseover(galleryImageOnMouseOver);
  $("#page.product_detail_page ul.gallery-images li img").mouseout(galleryImageOnMouseOut);
});

/*
 * This method put the border style when the mouse is over the image
 * By: Victor Redondo Quiros, 6 Agu 2010
 */
function galleryImageOnMouseOver()
{
  $(this).closest(".carousel-item").css("border-color","#4A85BA");
}

/*
 * This method remove the border style when the mouse is out the image
 * By: Victor Redondo Quiros, 6 Agu 2010
 */
function galleryImageOnMouseOut()
{
  $(this).closest(".carousel-item").css("border-color","#d9d9d9");
}


function closeAll()
{
	$( ".selected" ).removeClass( "selected" );
	$( ".open" ).fadeOut( "fast" );
}

/* positions the mini cart hover over popup */
function positionMiniCart()
{
	var pos = $( "#header .header_line2 a.popUpLinkHover" ).offset();
	if ( pos )
	{
	//	$( "#quick_cart_container" ).css( "left", ( pos.left - 20 ) + "px" );
	}
}

$( window ).resize( function() 
{
	positionMiniCart();
});


function copyAddress(e){
	//e.preventDefault();
	if($(this).attr("checked")){
		var source=$("#my_account_billing input");
		var dest=$("#my_account_shipping input");		
		for(var i=0;i<source.length-1;i++){			
			$(dest[i+1]).val($(source[i]).val());			
		}
		var source=$("#my_account_billing select");
		var dest=$("#my_account_shipping select");		
		for(var i=0;i<source.length;i++){			
			$(dest[i]).val($(source[i]).val());			
		}		
	}	
}
function colorPicker(e){
	selectPic(e,this,true);
	var text=$(this).children("img").attr("alt");
	$(this).closest("ul").siblings("p.selected_color").html(text);
}

function selectPictureGallery(e){
	e.preventDefault();
	$("#tab_video").css("display","block");
	$("#tab_video").find("#tab-open-image").css("display","block");
	$("#tab_video").find(".closeLink").css("display","block");
	$("#tab_video #large").css("z-index","-1");
	$("#tab_video #small").css("z-index","1");
	$("#tab_video #small").css("display","block");
	$("#tab_video #large").css("display","none");
	$("#tab_video #small img").attr("src"," ");
	$("#tab_video #large img").attr("src"," ");
	var c = $(this).attr("className");
	c = c.split("|");
	var smallImg = c[1].replace("678x450.png","320x320.png");
	$("#tab_video #small img").attr("src",smallImg);
	$("#tab_video #large img").attr("src", c[1]);
	$(".text-information-box").css("display","none");
	$("#tabclose_video .video_box").css("display","none");
}

function selectPic(e,obj,flag){	
	e.preventDefault();
    var c = $(obj).attr("className");
    c = c.split(" ");
    var i = 0;
    while (c[i].indexOf("src|") == -1) {
        i++;
    }
    c = c[i].split("|");
    if (!flag) {
		$("#large img").attr("src", c[1]);
		$("#small img").attr("src", c[1].replace("678x450.png","320x320.png"));
	}
}

function hideVideo(){
$("#tab_video").css("display","none");
}

function selectPicOnClick(){
 $("#page.product_detail_page .video_box .closeLink").css("display","none");
 $("#page.product_detail_page .video_box img").attr("src",pictureProduct);
 $(this).parent().next().css("display","block");
 $(this).parent().css("margin-bottom","0px");
 $(this).parent().css("width","330px");
}
function showHide(show,hide){	
	$(show).css("display","block");
	$(hide).css("display","none");
}


/* ------------------------- */
/* ----- Glossary Page ----- */

/* --------------------------- */
/* ----- Glossary Popups ----- */

var glossaryPos;

// fired when someone clicks on a ? icon
function glossaryPopup( storeId, catalogId, langId, term, obj )
{
	var link = "/webapp/wcs/stores/servlet/WHRGlossaryPopupDisplayView?storeId={0}&catalogId={1}&langId={2}&term={3}";
//	var link = "ajax_glossary.php?storeId={0}&catalogId={1}&langId={2}&term={3}";
	
	//link = link.replace( "{0}", storeId ).replace( "{1}", catalogId ).replace( "{2}", langId ).replace( "{3}", term ); WHPUK-822
	link = link.replace( "{0}", storeId ).replace( "{1}", catalogId ).replace( "{2}", langId ).replace( "{3}", encodeURIComponent(term) ); 
	
	glossaryPos =  $( obj ).offset();
	
	if ( $( "#question-tooltip" ).length > 0 )
	{
		$( "#question-tooltip" ).remove();
	}
	
	$.ajax({ 
		url: link, 
		success: glossaryPopupSuccess
      });
      
    return false;
}

// positions the glossary popup, loads the data that was returned
function glossaryPopupSuccess( data, textStatus, xhr )
{
	$( "#page" ).append( data + '<div class="hidden">' + " - " + glossaryPos.top + '</div>' );
	if($.browser.webkit){
	    $( "#question-tooltip" ).css( {
		"top" : glossaryPos.top - $( "#page" ).position().top + "px", 
		"left" : ((glossaryPos.left - $( "#page" ).position().left)-171) + "px" });
	}else{
	$( "#question-tooltip" ).css( {
		"top" : glossaryPos.top - $( "#page" ).position().top + "px", 
		"left" : glossaryPos.left - $( "#page" ).position().left + "px" });
	}
	$( "#question-tooltip .closeLink" ).click( function()
	{
		$( "#question-tooltip" ).fadeOut( "fast" );
		return false;
	});
	
	$( "#question-tooltip" ).fadeIn( "fast" );
}

/* ----- END Glossary Popups ----- */
/* ------------------------------- */

$( document ).ready( function()
{
    $( "#page.glossary .category ul.category_item li a" ).click( function()
    {
        if ( $( this ).parent().hasClass( "expanded" ) )
        {
            $( this ).parent().removeClass( "expanded" );
            $( this ).siblings( ".glossary_content" ).slideUp( "fast" );
        }
        else
        {
            $( this ).parent().addClass( "expanded" );
            $( this ).siblings( ".glossary_content" ).slideDown( "fast" );
        }
        return false;
    });
    
    
	$( "#page.glossary #glossary a.open-all" ).click( function()
	{
		$( "#page.glossary .category ul.category_item li" ).each( function()
		{
			if ( ! $( this ).hasClass( "expanded" ) )
			{
				$( this ).addClass( "expanded" );
			}
			$( "#page.glossary .category ul.category_item li .glossary_content" ).slideDown( "fast" );
		});
		return false;
	}); 
	
	
	$( "#page.glossary #glossary a.close-all" ).click( function()
	{
		$( "#page.glossary .category ul.category_item li" ).each( function()
		{
			if ( $( this ).hasClass( "expanded" ) )
			{
				$( this ).removeClass( "expanded" );
			}
			$( "#page.glossary .category ul.category_item li .glossary_content" ).slideUp( "fast" );
		});
		return false;
	});
	   
});

/* ----- FAQ Page ----- */

$( document ).ready( function()
{
	$("#page.faq .content_wrapper .content-faq .title-bar .open-close .close-link a").click(function(e){expandCollapse(e,this,1)});
	$("#page.faq .content_wrapper .content-faq .title-bar .open-close .open-link a").click(function(e){expandCollapse(e,this,2)});
	$(".open-link .open-a").click( function()
	{
		$(".expan_link").each(function(){
			if($(this).hasClass("expanded")==false)
				$(this).click();
		});
	});
	
	$(".close-link .close-a").click( function()
	{
		$(".expan_link.expanded").click();
	});
	
});
/* ----- END FAQ Page ----- */
/* ----- END FAQ Page ----- */
// This will bind the click events of the Compare checkboxes on the product list page
function BindCompareCheckBoxes()
{
  // Add compare checkboxes the event Click   
  $(".compare-product .compare-product-chk" ).click(CompareCheckBoxes);  
  if(getCookie(cookieItemProducts) != null)
  {
    getCheckboxCookie();
  }//end if cookie
  $(".compare-product a.compare_link").click( function(e){
      e.preventDefault();   
      var itemsChecked;
      if(getCookie(cookieItemProducts) == null)
        itemsChecked = 0;
      else
      {
        var arrayItems = getCookie(cookieItemProducts).split("|");
        itemsChecked = arrayItems.length - 1  
      }
      if($(this).siblings(".compare-product-chk").attr("checked")==true){       
        $(this).siblings(".compare-product-chk").attr("checked",false); 
        $(this).siblings(".compare-product-chk").click();
        $(this).siblings(".compare-product-chk").attr("checked",false);
       }
       else{
         if(itemsChecked < 4)
         {
           $(this).siblings(".compare-product-chk").attr("checked",true); 
           $(this).siblings(".compare-product-chk").click();
           $(this).siblings(".compare-product-chk").attr("checked",true); 
         }else{         
           showPopupCss("#compare-products-error-popup-v2");          
         }
      } 
    });
}

/*This method is going to update the values and styles chechbox and also management the cookie of the items to compare
By: Victor Redondo Quiros, July 23, 2010
*/
function CompareCheckBoxes(){
  var itemsChecked;
  if(getCookie(cookieItemProducts) == null)
    itemsChecked = 0;
  else
  {
    var arrayItems = getCookie(cookieItemProducts).split("|");
    itemsChecked = arrayItems.length - 1  
  } 
  if(itemsChecked <= 4)
  {
    if($(this).attr("checked") == true)
    {
      if(itemsChecked < 4){
        var tempItems;
        if(getCookie(cookieItemProducts) == null){
          setCookie(cookieItemProducts,"");
          tempItems = "";
        }else
          tempItems = getCookie(cookieItemProducts);
        tempItems+=$(this).attr("sku")+"|"
        setCookie(cookieItemProducts,tempItems);
      }
      else
      {
        $(this).attr("checked",false);
        showPopupCss("#compare-products-error-popup-v2");
      }
    }
    else
    {
      var sku = $(this).attr("sku");
      var arrayItems = getCookie(cookieItemProducts).split("|");
      var tempItems = "";
      var index = 0;
      for(index=0; index < arrayItems.length; index++)
      {
        if((sku != arrayItems[index])&&(arrayItems[index] != ""))
        {
          tempItems+= arrayItems[index] + "|";  
        }
        else
        {         
          $(".product-list-header-controls .product-list-header .compare-controls ul li .checked:eq("+index+")").attr("sku","");
          $(".product-list-header-controls .product-list-header.list-bottom .compare-controls ul li .checked:eq("+index+")").attr("sku","");  
        }//end if sku
      }//end for arrayItems
      setCookie(cookieItemProducts,tempItems);
  }//end if checked
  getCheckboxCookie();
  }
  else
  {
    $(this).attr("checked",false);
    showPopupCss("#compare-products-error-popup-v2");
  }//end if itemsChecked
}

/*This method is going to swicht the style names of the checkboxs and sku values too
By: Victor Redondo Quiros, July 23, 2010
*/
function getCheckboxCookie()
{
  if(getCookie(cookieItemProducts) != null){
  	var arrayItems = getCookie(cookieItemProducts).split("|"); 
  	var itemsChecked = arrayItems.length - 1; 
  	$(".compare-controls ul li .checked").removeClass("checked").addClass("unchecked");
    var selector = ".product-list-header-controls .product-list-header .compare-controls ul li .unchecked:lt("+itemsChecked+")"; 
    if ($(".product_detail_page").length == 0) {
		$(selector).removeClass( "unchecked" ).addClass( "checked" );
    	selector = ".product-list-header-controls .product-list-header.list-bottom .compare-controls ul li .unchecked:lt("+itemsChecked+")";
    	$(selector).removeClass( "unchecked" ).addClass( "checked" );
	}else{
		selector = ".compare-controls ul li .unchecked:lt(" + itemsChecked + ")";
		$(selector).removeClass("unchecked").addClass("checked");
	}	
    var indexItem = 0;
    for(indexItem = 0; indexItem <= itemsChecked; indexItem++)
    {
      var valueIndex = arrayItems[indexItem];
      if(valueIndex != "")
      {
	  	if ($(".product_detail_page").length == 0) {
			selector = ".product-list-header-controls .product-list-header .compare-controls ul li .checked:eq(" + indexItem + ")";
			$(selector).attr("sku", valueIndex);
			selector = ".product-list-header-controls .product-list-header.list-bottom .compare-controls ul li .checked:eq(" + indexItem + ")";
			$(selector).attr("sku", valueIndex);
			selector = ".compare-product .compare-product-chk[sku|=" + valueIndex + "]";
		}else{
			selector = ".compare-controls ul li .checked:eq("+indexItem+")";
        	$(selector).attr("sku",valueIndex);
        	selector = ".compare-product .compare-product-chk[sku|="+valueIndex+"]";
		}//end if product_detail_page  
		$(selector).attr("checked", true);
      }//end if valueIndex
    }//end for arrayItems
    var counter = itemsChecked;
    if(IE)
      counter=counter+"&nbsp;";           
    $( ".compare-controls .compare-link .count" ).html( counter );
    if ( itemsChecked <= 1 )
    {
      $( ".compare-controls .compare-link .count" ).html( "" );
    }
  }else{
    $(".compare-controls ul li .checked").removeClass("checked").addClass("unchecked");
    $(".compare-controls ul li .compare-prod").attr("sku","");
    $(".compare-controls .compare-link .count").html( "" );
  }
}

//Content Pages - Landing Pages

$( document ).ready( function()
{
  var object=".expanded_freshness";
  $(object).click(function(e){content_landing_expandCollapse(e,this,object,0)});
  
  object=".expanded_defrosting";
  $(object).click(function(e){content_landing_expandCollapse(e,this,object,0)});
  
});

function content_landing_expandCollapse (e,This,object,openall) {
  
  if($(This).hasClass('expanded')) {
      $(This).removeClass('expanded');
  }
  else {
      $(This).addClass('expanded');
  }
  
  $(object+".content").toggle();
}

function cleanCookie(){
  if(getCookie(cookieItemProducts) != null){
	if(getCookie(cookieLocation) != location.pathname){//is not a refresh
	  if ($(".product_detail_page").length == 0) {
	  	var tempCookie;
	  	tempCookie = "";
	  	setCookie(cookieItemProducts, tempCookie);
	  	var currentPath = "";
	  	currentPath = location.pathname;
	  	setCookie(cookieLocation, currentPath);
	  	var currentSearchTerm = "";
	  	currentSearchTerm = getUrlVars()["searchTerm"];
	  	if (currentSearchTerm == undefined) 
	  		currentSearchTerm = "";
	  	setCookie(cookieSearchTerm, currentSearchTerm);
	  	cleanCompareBoxs();
	  }
    }else{
		var currentSearchTerm = "";
	  	currentSearchTerm = getUrlVars()["searchTerm"];
		if(currentSearchTerm == undefined)
	  		currentSearchTerm = "";
		if(getCookie(cookieSearchTerm) != currentSearchTerm){
			var tempCookie;
			tempCookie = "";
			setCookie(cookieItemProducts, tempCookie);			
			setCookie(cookieSearchTerm,currentSearchTerm);
			cleanCompareBoxs();
    	}	
	}
  }else{          
  	var currentSearchTerm = "";
	currentSearchTerm = getUrlVars()["searchTerm"];  
  	if(currentSearchTerm == undefined)
		currentSearchTerm = "";
	setCookie(cookieLocation,location.pathname);	
	setCookie(cookieSearchTerm,currentSearchTerm);
  }
}

/*
 * Config variables for make enable the cookie functionality 
 * By: Victor Redondo Quiros
 * */
var cookieOptions = { path: '/', expires: 10 }; 
var cookieItemProducts = "compareItemsBau";
var cookieLocation = "locationPathBau";
var cookieSearchTerm = "searchTermPathBau";

/*This method delete the cookie of compare Items when the user leave the page
By: Victor Redondo Quiros, 23 July, 2010*/
$(window).load(function(){
	cleanCookie();
});

/*getCookie
By: Victor Redondo Quiros, 23 July, 2010*/
function getCookie(cookieName)
{
	return $.cookie(cookieName);	
}

/*setCookie
By: Victor Redondo Quiros, 23 July, 2010*/
function setCookie(cookieName,cookieValue)
{
	$.cookie(cookieName,cookieValue,cookieOptions);
}

/*This method get the parameters from the URL
By: Victor Redondo Quiros, 9 Ago, 2010*/
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function cleanCompareBoxs()
{
  var cleanCookie = "";
  setCookie(cookieItemProducts,cleanCookie);
  $(".compare-product .compare-product-chk").attr("checked",false);
  $(".compare-controls ul li .checked").removeClass( "checked" ).addClass( "unchecked" );
  $(".compare-controls ul li .compare-prod").attr("sku","");
  $(".compare-controls .compare-link .count" ).html( "" );
}
$(document).ready(function(){
	//Fix dinamicly some Heights in Product Detail Page
	if($(".product_detail_page").length > 0){
		if ($("#tabclose_video").height() > $(".info_list").height()) {
			var tempHeight = $("#tabclose_video").height(); 
			$(".info_list").css("height", tempHeight + "px");
			/*tempHeight +=  40;
			$("#tab_overview").css("height",tempHeight +"px");*/				
		}
		else {
			var tempHeight = $(".info_list").height() + 41; 
			$("#tab_overview").css("height", tempHeight + "px");
		}
		var maxHeight = 0;
		$(".main_menu_ul .product_options").each(function(){
			if(maxHeight < $(this).height())
				maxHeight = $(this).height();
		});
		$(".main_menu_ul .product_options").css("height",maxHeight+"px");
	}
	$( "span.header").bind( "click",  myAccountMenu );
});
function printPage(){
	window.print();	
}
function myAccountMenu () {
	
	var htmlText = $(this).html(); 

	if (htmlText == "Letzte Bestellungen") {
		if($(this).hasClass('expanded')) {
			$(this).parent().removeClass('expanded');
			$(this).removeClass('expanded');
		}
		else {
			$(this).addClass('expanded');
			$(this).parent().addClass('expanded');
		}
		
		$(".order_status_table").toggle();
	}
	else if (htmlText == "Produkte, die Ihrem Merkzettel vor kurzem hinzugefügt wurden") {
		if($(this).hasClass('expanded')) {
			$(this).parent().removeClass('expanded');
			$(this).removeClass('expanded');
		}
		else {
			$(this).addClass('expanded');
			$(this).parent().addClass('expanded');
		}
		$("#four-grid").toggle();
	}
	else {
		exit;
	}
}

$(document).ready(function(){
	$("#page.ContentPage div.topTab").click(function(){
		if($(this).hasClass("selected")==false){
			$("div.topTab").removeClass("selected");
			$(this).addClass("selected");
			$("div.contentNavElem").removeClass("selected");
			$("div.contentNavElem").css("display","none");
			var indexTab = $("div.topTab").index($(this));
			$("div.contentNavElem:eq("+indexTab+")").fadeIn("slow");
			$("div.contentNavElem:eq("+indexTab+")").addClass("selected");				
		}
	});
});

$(document).ready(function(){
	if($("#page .brand_pillar .box_picture").length >  0){
		$("#page .brand_pillar .box_picture").mouseenter(function(){
			$(this).addClass("hover");
			$(this).find(".text_description").css("display","block");
			var textDescriptionHeight = $(this).find("text_description").height(); 
			textDescriptionHeight+= 20;
			$(this).find(".link_title").css("marginTop",textDescriptionHeight+"px");
			$(this).find(".link_title").addClass("selected");						
		});
		$("#page .brand_pillar .box_picture").mouseleave(function(){
			$(this).find(".text_description").css("display","none");
			$(this).find(".link_title").css("marginTop","414px");
			$(this).removeClass("hover");
			$(this).find(".link_title").removeClass("selected");
		});
	}
});

/* Espot HOME slide BEGIN 09.09.2011 */
var numItems, itemArray, myInterval ;
//Set Espot selected item
function setCurrent(event) {
	event.preventDefault();
	for (var i = 1; i <= numItems; i++) {
		itemArray[i].removeClass('on');
	}
	jQuery(this).addClass('on');
	jQuery('.genericESpot ul.slideControler').removeClass('slideControler').addClass('homeStopper');
	jQuery('.genericESpot').removeClass('genericESpot').addClass('genericESpotStop');
}

function bgSelect(e){
	e.preventDefault();
	clearInterval(myInterval);
	
	$(".slideControler li").removeClass("selected");
	$(this).parent().addClass("selected");
	$("div.contentText.selected").removeClass("selected");
	
	$($(this).attr("href")).addClass("selected");
	
}

/*function bgSelect(e){
	e.preventDefault();
	$("a.bselector.selected").removeClass("selected");
	$("div.contentText.selected").removeClass("selected");
	$(this).addClass("selected");
	$($(this).attr("href")).addClass("selected");
}
*/


//Rotates Espots on espot page	
function rotateSpots() {
    var oCurSpot = jQuery('.genericESpot div.selected');
    var oNxtSpot = oCurSpot.next();
    var oCurNum = jQuery('.genericESpot ul.slideControler li.selected');
    var oNxtNum = oCurNum.next();
	

    if (oNxtSpot.length == 0)
      oNxtSpot = jQuery('.genericESpot div#contentText1');
    if (oNxtNum.length == 0)
      oNxtNum = jQuery('.genericESpot ul.slideControler li:first');
    oCurSpot.removeClass('selected').addClass('previous');
    oCurNum.removeClass('selected').addClass('previous');
	if(jQuery.support.opacity){
		oNxtSpot.css({
			opacity: 0.0
		}).addClass('selected').animate({
			opacity: 1.0
		},
		1000,
		function() {
			oCurSpot.removeClass('previous');
		});
		oNxtNum.css({
			opacity: 1.0
		}).addClass('selected').animate({
			opacity: 1.0
		},
		1000,
		function() {
			oCurNum.removeClass('previous');
		});
	}else{
		oNxtSpot.addClass('selected');
        oCurSpot.removeClass('previous');
		oNxtNum.addClass('selected');
        oCurNum.removeClass('previous');
	}
    
}

$(document).ready(function(){
	jQuery("a.expandButton").toggle(function(e) {
        e.preventDefault();
        jQuery(this).closest("li").addClass("expanded")
    },
    function(e) {
        e.preventDefault();
        jQuery(this).closest("li").removeClass("expanded")
    });
//START slideControler INIT
	if(jQuery('.slider').length > 0){
		jQuery('.genericESpot ul.slideControler li:first').addClass('selected');
		numItems = jQuery('.bselector').size();
		itemArray = new Array();
		for (var i = 1; i <= numItems; i++) {
			itemArray[i] = jQuery('.genericESpot ul.slideControler li:nth-child(' + i + ') a');
			//itemArray[i].bind("click", setCurrent);
		}
		// Run Automatic rotation every 6s.
		myInterval = setInterval('rotateSpots()', 6000);
		jQuery("ul.slideControler a.bselector").bind("click",bgSelect);
	}
//END slideControler INIT



	//-----190911-DIGITAS : test of adding element in product page------//
	if($("#page.product_detail_page").length > 0){
		if($("#page.product_detail_page p.sale-price").length > 0){
            //alert("accessoire");   
		}
		else
		{
			var urlLinkDealer;
			var isPassion = false;
			var isPlatinum = false;

			$(".logo-image-link").each(function () {
				if($(this).attr('src')=='/digitalassets/WINONLINE_EMEA/BK/BK_COMMON/Passion.png')
				{
					isPassion = true;
				}
				if($(this).attr('src')=='/digitalassets/WINONLINE_EMEA/BK/BK_COMMON/PLATINUM.png')
				{
					isPlatinum = true;
				}
             });

			if($("#WC_BreadCrumbTrailDisplay_link_6").text() == 'PLATINUM' || isPlatinum)		urlLinkDealer = 'http://bauknecht.links.channelintelligence.com/oemsites/1039222/DE/index.asp?nRGID=3113';
			else if($("#WC_BreadCrumbTrailDisplay_link_6").text() == 'PASSION' || isPassion)	urlLinkDealer = 'http://bauknecht.links.channelintelligence.com/oemsites/1039222/DE/index.asp?nRGID=3114';
			else																				urlLinkDealer = 'http://bauknecht.links.channelintelligence.com/oemsites/1039222/DE/index.asp ';
			
			$("#page.product_detail_page .right_links .info_list ul.right_nav_links").append('<li><a class="dealer_link" href="'+urlLinkDealer+'" target="_blank">HÄNDLERSUCHE</a></li>');
		}
	}
	//-----190911-DIGITAS : test of adding element in product page------//

	/******* UPDATE FRANCESCO 11/10/11 - Amine ******/
	$(".file-weight").each(function(i){	
		var attrib = $(this).children().attr('href');
		if(attrib)
		{	
				var currentTarget = $(this).children().attr("target");
				if(currentTarget!='_blank')
				{
					$(this).children().attr("target","_blank")
				}	
		}
		$(this).prev().attr("target","_blank");
		$(this).parent().prev().prev().children().attr("target","_blank");
	});	
	$(".download_warranty").each(function(i){
		$(this).attr("target","_blank");
	});	
	/***********************************************/


});
