$(document).ready(function(){
						   
	ceZoom = $('.ce-zoom-wrap');
	if(ceZoom.length > 0){
		zI = 100;
		ceZoom.each(function(){
			$(this).css('z-index', zI);
			zI--;
		});
	}
					   	
	if($('.fancy').is('a')){
		$("a.fancy").fancybox({
	 		'zoomSpeedIn': 300,
	  		'zoomSpeedOut': 100,
			'transitionIn' : 'fade',
			'transitionOut' : 'none',
	  		'overlayShow': true
		});
	}
	
	$('#product-image').hover(
		function(){
			$(this).css('z-index', '103');
			$('#fixed-zoom-window').show();
		},
		function(){
			$(this).css('z-index', '101');
			$('#fixed-zoom-window').hide();
		}
	);
	
	$('#fixed-zoom-window').mouseover(function(){
		$(this).parent().css('z-index', '101');
	});
	
	if($('.image-gallery-item').length > 0){
		$('.image-gallery-item').wrapAll('<div id="image-gallery-wrap"><div id="image-gallery-container"><div id="image-gallery-move"></div></div></div>');
		galleryWrap = $('#image-gallery-wrap');
		galleryWrap.prepend('<div id="ig-slide-left"></div>');
		galleryWrap.append('<div id="ig-slide-right"></div>');
		galleryWrap.append('<div class="clear"></div>');
		
		$('.image-gallery-item').each(function(){
			var header = $(this).find('.csc-header');
			var text = $(this).find('.csc-textpic-text');
			if(header.length || text.html().length > 0){
				$(this).prepend('<div class="ig-item-info-icon"><div class="ig-item-info-text"></div></div>');
				$(this).find('.ig-item-info-text').prepend(header).append(text);
			}
		});
		
		var ig_items = $('.image-gallery-item').length
		
		if(ig_items < 2)
			$('#ig-slide-right').hide();
		ig_pos = 1;
		ig_left = 0;
		
		$('#ig-slide-left').click(function(){	
			if(ig_left >= 0)
				return;
			
			ig_left += 758;
			$('#image-gallery-move').animate({'left': ig_left});
			
			ig_pos--;
			
			if(ig_pos == 1)
				$(this).hide();
				
			$('#ig-slide-right').show();
		});
		
		$('#ig-slide-right').click(function(){			
			if(ig_pos == ig_items)
				return;
			
			ig_left -= 758;
			$('#image-gallery-move').animate({'left': ig_left});
			
			ig_pos++;
			
			if(ig_pos == ig_items)
				$(this).hide();
				
			$('#ig-slide-left').show();
		});
		
		galleryWrap.hover(function(){
			if(ig_pos > 1 && ig_pos >= ig_items)
				$('#ig-slide-left').show();
			if(ig_pos > 1 && ig_pos < ig_items){
				$('#ig-slide-left').show();
				$('#ig-slide-right').show();
			}
			if(ig_pos <= 1 && ig_pos < ig_items)
				$('#ig-slide-right').show();
		},function(){
			$('#ig-slide-left').hide();
			$('#ig-slide-right').hide();
		});
		
		$('.ig-item-info-icon').hover(function(){
			$(this).find('.ig-item-info-text').stop(true, true).fadeIn();
		},
		function(){
			$(this).find('.ig-item-info-text').stop(true, true).fadeOut();
		});
	}
						   
	$('#nav li').hover(function() {
		
		$(this).addClass('over');
		$(this).find('.level-top a').addClass('over');
		$(this).find('.level0').addClass('shown-sub');
										 },
							function() {
			
		$(this).removeClass('over');
		$(this).children().find('a').removeClass('over');
		$(this).find('.level0').removeClass('shown-sub');
										}
	);
	
	$('.level0 li').hover(function() {
		
		$(this).addClass('over');
		$('.level1 a').addClass('over');
		$('.level2 a').removeClass('over');
		$(this).find('.level1').addClass('shown-sub');
										},
							function() {
						
		$(this).removeClass('over');
		$('level1 a').removeClass('over');
		$(this).find('.level1').removeClass('shown-sub');
										}
	);
        
	$('#nav .level0 a.active img').css('top', -20);
	
	$("#product-detail-nav").css("display","block");
	
	$("#product-detail-nav").find('tr').each(function() {
		$(this).find('td').last().remove();
	});
	
	isSlide = true;
	teaser_pointer = 0;
	teaser_count = $('.teaser_4cols').length;
	
	if(teaser_count <= 4 && teaser_count != 0)
		isSlide = false;
	
	teaser_left_step = 243;
	teaser_show = 4;
	
	if(teaser_count == 0){
		teaser_count = $('.teaser_3cols').length;
		
		if(teaser_count <= 3)
			isSlide = false;
			
		teaser_left_step = 325;
		teaser_show = 3;
	}
	
	teaser_left = 0;
	
	$('.teaser-wrap').hover(
		function() {
			if(isSlide)
				$('.teaser-active').fadeIn();
		},
		function() {
			if(isSlide)
				$('.teaser-active').fadeOut();
		}
	);
	
	if(teaser_count > teaser_show)
		$('.teaser_slider_right').addClass('teaser-active');
	
	$('.teaser_slider_right').click(function() {
		if(teaser_pointer + teaser_show >= teaser_count)
			return true;
			
		$('.teaser-wrap').css('overflow', 'hidden');
		
		teaser_left -= teaser_left_step;
		$('.teaser_slider').animate({'left': teaser_left},function(){
			$('.teaser-wrap').css('overflow', 'visible');
		});
		
		teaser_pointer++;
		
		if(teaser_pointer + teaser_show >= teaser_count)
			$(this).removeClass('teaser-active').fadeOut();
		
		if(teaser_pointer > 0)
			$('.teaser_slider_left').addClass('teaser-active').fadeIn();
	});
	
	$('.teaser_slider_left').click(function() {
		if(teaser_pointer == 0)
			return true;
			
		$('.teaser-wrap').css('overflow', 'hidden');
		
		teaser_left += teaser_left_step;
		$('.teaser_slider').animate({'left': teaser_left},function(){
			$('.teaser-wrap').css('overflow', 'visible');
		});
		teaser_pointer--;
		
		if(teaser_pointer == 0)
			$(this).removeClass('teaser-active').fadeOut();
			
		if(teaser_pointer+teaser_show < teaser_count)
			$('.teaser_slider_right').addClass('teaser-active').fadeIn();
	});
	
	
	if($('.footer-category ul').length < 5){
		$('.footer-category').addClass('footer-'+$('.footer-category ul').length+'-cols');
	}
	
	
	$('.continent').each(function() {
		continent = $(this);
		total = 0;
		sum = 0;
		iter = 0;
		
		continent.find('li.parent').each(function() {
			total += $(this).outerHeight(true);
		});
		
		limit = Math.ceil(total / 1) + 15;
		
		if(continent.is('#cont-Europe'))
			limit = Math.ceil(total / 2) + 20;		
		
		$(this).find('li.parent').each(function() {
			sum += $(this).outerHeight(true);
			if(sum <= limit)
				iter++;
			else{
				continent.find('li.parent:lt('+iter+')').wrapAll('<li><ul></ul></li>').removeClass('parent').addClass('parentDone');
				sum = 0;
				iter = 0;
			}
			$(this).has('ul').addClass('has-languages');
		});
		continent.find('li.parent').wrapAll('<li><ul></ul></li>');
		continent.find('.clear').css('height', 0).css('overflow', 'hidden');
		continent.css('height', continent.height());
		continent.find('li li ul').css('height', 0).css('overflow', 'hidden');
	});	
			
	$('#america, #europe, #asia').click(function() {
           $('.lang-layer').animate({'top': 30}, 500);
           $('#america, #europe, #asia').css('overflow', 'visible');
           $('#america').find('.lang-layer').css('border-width', '1px 0 1px 1px');
           $('#asia').find('.lang-layer').css('border-width', '1px 1px 1px 0');
	});
	
	$('.multi-lang').toggle(
		function(){
			ul_height = 0;
			$(this).next('ul').find('li').each(function(){
				ul_height += $(this).height();
			});
			$(this).next('ul').animate({height: ul_height});
		},
		function(){
			$(this).next('ul').animate({height: 0});
		}
	);
	
	$('.sitemap-content, #product-overview-left-col').parent('div').css('position', 'static');

	$('.press-select li').not('.press-select li.show').hover(
		function() {
			$(this).css('background-position', 'right bottom');
			$(this).find('a').css('background-position', 'left bottom');
		},
		function() {
			$(this).css('background-position', 'right top');
			$(this).find('a').css('background-position', 'left top');
		}
	);
	
	$('.news-single-imgcaption').each(function(){
		if($(this).is(':empty'))
			$(this).hide();
	});
	
	$('.news-single-img a').css('padding', '0 0 0 6px');
	if($.browser.msie && $.browser.version.substr(0,1)=="6"){
		$('.news-single-img a').css('padding', '0 0 0 5px');
	}
	$('.news-single-img a:first').css('padding', '0');

    window.setTimeout("$('#america').click()", 3000);
	
//###############|vb_navi_shop|#################
	var COOKIE_NAME = 'storeview';	
	c_storeview = $.cookie(COOKIE_NAME);
	if(c_storeview){
		$('[href*=\/\/shop]').each(function() {
			var href = $(this).attr('href');
			var indexLeft = href.indexOf('/public_');
			if(indexLeft > -1){
				var substrUrl = href.substr(indexLeft + 1);
				var indexRight = substrUrl.indexOf('/');
				if(indexRight > -1){
					substrUrl = '/' + substrUrl.substr(0, indexRight) + '/'; 								
					var repWith = '/' + c_storeview + '/';
					href = href.replace(substrUrl, repWith);
					$(this).attr('href', href);
				}
			}
		});
	}

//###############|image_rotation|#################
	if($.browser.msie)
		$('#content-center-intro-evb-items div div').css('filter', 'inherit');
	
	$(".content-center-intro-evb-infos").bind("mouseover", function(e){
		$(this).parent().find(".content-center-intro-evb-image-text").fadeIn();
		if(slideshow)
			window.clearInterval(slideshow);
	});
	
	$(".content-center-intro-evb-infos").parent().bind("mouseleave", function(e){
		$(this).find(".content-center-intro-evb-image-text").fadeOut();
		if(slideshow)
			slideshow = window.setInterval("navigateIntroEVB()", 3000);
	});
	
	$('#content-center-intro-evb-items').children().css('position', 'absolute');
	
	if($('.content-center-intro-evb-images').length > 1){		
		$("#content-center-intro-evb .content-center-intro-evb-images").css("display","none");
		$("#content-center-intro-evb .content-center-intro-evb-images-1").css("display","block");
		
		slideshow = window.setInterval("navigateIntroEVB()", 10000);
	}
	
//#################|Whirlpoolsysteme jump to item|######################

	$('a[class*="jump-to-item-"]').each(function(){
		url = $(this).attr('href');
		aClass = $(this).attr('class');
		url += '#'+aClass;
		$(this).attr('href', url);
	});
});

var actNumber = 1;
var newNumber = 0;
var slideshow = '';
function navigateIntroEVB(number) {

	if(number==undefined) {
		number = actNumber;
		newNumber = actNumber + 1;
	}
	else
		newNumber = number + 1;
	
	if($("#content-center-intro-evb .content-center-intro-evb-images-"+newNumber).length==0) {
		actNumber = 0;
		number = actNumber;
		newNumber = actNumber + 1;
	}

	$("#content-center-intro-evb .content-center-intro-evb-images").fadeOut(2500);
	$("#content-center-intro-evb .content-center-intro-evb-images-"+newNumber).fadeIn(2500);
	$(".content-center-intro-evb-navigator-element").css("background","url(fileadmin/sites/website-2010-v1/gfx/blind.gif) repeat");
	$("#content-center-intro-evb-navigator-element-"+number).css("background","#ffffff");

	actNumber = newNumber;
	window.clearInterval(slideshow);
	slideshow = window.setInterval("navigateIntroEVB()", 10000);
}

//###############|mm_viewd_products|#################
function setCurrentProduct(product){
	if(!product) 
		return;
	var pkeyA = product.split('_');
	var pkey = pkeyA[0]+'_'+ pkeyA[1]+'_'+ pkeyA[1];
	var COOKIE_NAME = 'ext_vbproduct2_product_lastViewedProducts';
	var list = $.cookie(COOKIE_NAME);
	if(list){
		var cookiearray = list.split(',');
		var kUniqueA = new Array();
		var newcookiearray = new Array();
		for(var i=0; i<cookiearray.length; i++) {
			var ukeyA = cookiearray[i].split('_');
			var ukeyS = ukeyA[0]+'_'+ ukeyA[1]+'_'+ ukeyA[1];
			if($.inArray(ukeyS, kUniqueA) == -1) {
				if(ukeyS != pkey) {
					kUniqueA.push(ukeyS);
					newcookiearray.push(cookiearray[i]);
				}
			}
		}
		cookiearray = newcookiearray;
		cookiearray.unshift(product);
		cookiearray = cookiearray.slice(0, 3);
	}else{
		cookiearray = new Array();
		cookiearray.push(product);
	}
	$.cookie(COOKIE_NAME, cookiearray.join(','), {path: '/'});	  
}
 
function getLastViewedIds(){
	var COOKIE_NAME = 'ext_vbproduct2_product_lastViewedProducts';
	var list = $.cookie(COOKIE_NAME);			
		
	return list;
}
