$(document).ready(function(){
	
// Tab Milieubilder Scrollleiste >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	mItems = $('#milieu-list li').length;
	mPos = 0;
	left = 0;
	
	if(mItems > 4){
		$('#milieu-left').addClass('inactive');
	}

	$('#milieu-left').click(function() {
		if(mPos > 0){
			left += $('#milieu-list li:eq('+(mPos-1)+')').outerWidth(true);
			$('#milieu-list').animate({left: left});
			mPos--;
			$('#milieu-right').removeClass('inactive');
			if(mPos == 0)
				$('#milieu-left').addClass('inactive');
		}
	});
	
	$('#milieu-right').click(function() {
		if(mPos < mItems - 4){
			left -= $('#milieu-list li:eq('+mPos+')').outerWidth(true);
			$('#milieu-list').animate({left: left});
			mPos++;
			$('#milieu-left').removeClass('inactive');
			if(mPos == mItems - 4)
				$('#milieu-right').addClass('inactive');
		}
	});
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// Tab Download Akkordeon >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	$('.product-detail-downloads-firstcol-with-subfiles').toggle(
		function() {		
			id = $(this).attr('id');
			$(this).addClass('act');
			$('#product-detail-downloads').find('table[id^='+id+'_]').slideDown();
		},
		function() {
			id = $(this).attr('id');
			$(this).removeClass('act');
			$('#product-detail-downloads').find('table[id^='+id+'_]').slideUp();
		}
	);
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// Tab Hover >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	$('.tab-label').hover(function(){
		$(this).css('background-position', 'bottom right');
		$(this).find('span').css('background-position', 'bottom left');
	},
	function(){
		$(this).css('background-position', 'top right');
		$(this).find('span').css('background-position', 'top left');
	});
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// Tab wechseln >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	$('.tab-label').click(function(){
		$('.tab-label-act').removeClass('tab-label-act').addClass('tab-label');
		$('.tab-bg-act').removeClass('tab-bg-act').addClass('tab-bg');
		$(this).removeClass('tab-label').addClass('tab-label-act');
		$(this).find('span').removeClass('tab-bg').addClass('tab-bg-act');
		
		id = $(this).attr('id');
		id = id.substr(id.length-1, 1);
		$('.tab').hide();
		$('#tab-box-'+id).show();
	});
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		
	$('#tab-labels li:first').removeClass('tab-label').addClass('tab-label-act');
	$('#tab-labels li:first').find('span').removeClass('tab-bg').addClass('tab-bg-act');
	
// Produktmatrix anzeigen / schliessen >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	$('#matrix').click(function(){
		// to be tested 'cause cache!
		if($("#productsearchoverlaybg").length) {
			$("#productsearchoverlaybg").css("display","block");
		}
		else {
			var posLeft = (document.body.clientWidth/2)-450;
            $("#productsearchoverlay-shadow").css("left",posLeft+"px");
			$("body").append('<div id="productsearchoverlaybg"></div>');
		}

		$('#productsearchoverlay-shadow').show();
	});


	$('#productsearchoverlay-closebutton').click(function(){
		$("#productsearchoverlaybg").hide();
		$('#productsearchoverlay-shadow').hide();
	});
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	
	$('.accessories').parent().parent().css('height', '40px');
	$('.accessories').parent('td').css('vertical-align', 'bottom');
	$('.accessories').parent('td').css('border-right', '0');
	
	$('#fancybox-title').hide();
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	
	$('table#bath tbody tr:even').css('background-color', '#f5f6f8');
	$('table#kitchen tbody tr:even').css('background-color', '#f5f6f8');
	$('table#faucets tbody tr:even').css('background-color', '#f5f6f8');
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	
	$('.vb-product-watchlist-table').each(function(){
		$(this).find('.vb-product-watchlist-table-tr-data:first').find('.up').hide();
		$(this).find('.vb-product-watchlist-table-tr-data:last').find('.down').hide();
	});


// Tobi: Extend Cloud Zoom <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    if($(".cloud-zoom").is('a')){
	   $(".cloud-zoom").fancybox({
		'transitionIn' : 'fade',
		'transitionOut' : 'fade'
		});
	}
	
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	$('.product-detail-table tr').each(function(){
		$(this).find('td:first').attr('width', 140);
		$(this).find('td:eq(1)').attr('width', 250);
		$(this).find('td:eq(2)').attr('width', 75);
		$(this).find('td:eq(3)').attr('width', 75);
	});
});
