
	var currentDisplayedLayer;

	var sliderPriceMin = 0;
	var sliderPriceMax = 100;
	
	var sliderPrice_defaultMin = 0;
	var sliderPrice_defaultMax = 100;
	
	var sliderRateMin = 0;
	var sliderRateMax = 10;
	
	var sliderRate_defaultMin = 0;
	var sliderRate_defaultMax = 10;
	
	var selectedRates = new Array();
	
	var box_four_slider_pos_1 = 0;
	var box_four_slider_pos_2 = 0;
	var box_four_slider_pos_3 = 0;
	var box_four_slider_pos_4 = 0;
	
	// initialise plugins
	jQuery(document).ready(function() { 
		$('ul.main_menue').superfish();
		$('#customselector').customSelect();
		

		$('.headerSearchInput input').click(function(){
			if($(this).val()=='Stichwort'){
				$(this).val('');
			}
		});

		$('.headerSearchInput input').blur(function(){
			if($(this).val()==''){
				$(this).val('Stichwort');
			}
		});   
		
		
		
		
		
		$(".tooltip").tooltip({
			sticky: true,
			track: true,
			delay: 0,
			showURL: false,
			fixPNG: true,
			showBody: " - ",
			extraClass: "pretty fancy",
			top: 10,
			left: 10
		});
		
		
		
		$("div.scrollable").scrollable({ 
		    prevPage: 'div.left',
			nextPage: 'div.right',
		    clickable: false,
		    keyboard: false,
		    onSeek: function(){ 
			    $("div.left").toggle();
				$("div.right").toggle();
				currentSlideshowPOsition = 0;
		     }
		});
		
		
		
		
		
		// Slider Konfiguration
		
		$("#slider_price").slider({
			range: true,
			min: sliderPriceMin,
			max: sliderPriceMax,
			values: [sliderPrice_defaultMin, sliderPrice_defaultMax],
			slide: function(event, ui) {
				$('#price_text_range_min').html(convertPrice(ui.values[0])+",00 &euro;");
				$('#price_text_range_max').html(convertPrice(ui.values[1])+",00 &euro;");
			},
			stop: function(event, ui) {

				$('#price_range_min').val(ui.values[0]);
				$('#price_range_max').val(ui.values[1]);
				document.searchoption.submit();
			}
		});
		
		
		$("#slider_rate").slider({
			range: true,
			min: sliderRateMin,
			max: sliderRateMax,
			values: [sliderRate_defaultMin, sliderRate_defaultMax],
			slide: function(event, ui) {
				$('#rate_text_range_min').html(ui.values[0]);
				$('#rate_text_range_max').html(ui.values[1]);
			},
			stop: function(event, ui) {
				$('#rate_range_min').val(ui.values[0]);
				$('#rate_range_max').val(ui.values[1]);
				document.searchoption.submit();
			}
		});
		
		// Brandselektion
		
		$(".tagcloud > .tabs > ul > li a").click(function(){
			$(".tagcloud > .tabs > ul > li a").removeClass('akt');
			$(this).addClass('akt');
			$('.tagcloud_content').hide();
			$('#'+$(this).attr('rel')).show();
		});
		
		
		$(".reiter_box > .tabs > ul > li a").click(function(){
			$(".reiter_box > .tabs > ul > li a").removeClass('akt');
			$(this).addClass('akt');
			$('.reiter_box_content').hide();
			$('#'+$(this).attr('rel')).show();
		});
		
		
		$(".showextended").click(function(){
			
			id 		= $(this).parent().attr('id');
			status 	= '0';
			if ($(this).parent().children('.extended').css('display') == 'none') {
				status = '1';
			}
			
			$(this).parent().children('.extended').toggle();
			rememberBoxStatus(id, status);
		});
		
		
		
		
		var defaultVal = 0;
		
		
		$(".ratingBar").mouseover(function() {
			
			$(this).mousemove(function(event){
				
				rating_value = event.pageX-196;
				$(this).children().width(rating_value);
				values = votingScala(rating_value);
				
				obj = $(this).parent().parent();
				$('#'+obj.attr('id')+' > .rating').html(values['rate']);
				$('#'+obj.attr('id')+' > .textual_rating').html(values['text']);
				
			});
			
			$(this).click(function(event){
				
				id = $(this).attr('id');
				currentVal = event.pageX-196;
				
				selectedRates[id] = currentVal;
				
				$('#value_'+id).val(currentVal);
			});
			
		});
		
		$(".ratingBar").mouseout(function() {
			
			obj 		= $(this).parent().parent();
			valueSet 	= $('#'+obj.attr('id')+' > input').val();
			id 			= $(this).attr('id');
			
			valueSet 	= "";
			
			if (selectedRates[id] != undefined) {
				valueSet = selectedRates[id];	
			}
			
			if (valueSet != "") {
				$('#'+obj.attr('id')+' .coloredBar').width(valueSet);
				values = votingScala(valueSet);
			} else {
				$('#'+obj.attr('id')+' .coloredBar').width(defaultVal);
				values = votingScala(defaultVal);
			}
			
			obj = $(this).parent().parent();
			$('#'+obj.attr('id')+' > .rating').html(values['rate']);
			$('#'+obj.attr('id')+' > .textual_rating').html(values['text']);
			
		});
		

		
		
		 
	});
	
	
	// Bereichsseite (automatischer Wechsel der Slideshow)
	var currentSlideshowPOsition = -5;
	
	function loadScrollView () {
			
		var api = $("div.scrollable").scrollable({api: true}); 
		
		if (currentSlideshowPOsition == -5) {
			api.move(5);
			currentSlideshowPOsition = 5;
		} else if (currentSlideshowPOsition == 5) {
			api.move(-5);
			currentSlideshowPOsition = -5;
		}

	}
		
	function votingScala(val) {
		
		maxScala 		= 	217;
		scalaUnits 		= 	10;
		pixelPerUnit	=	maxScala / scalaUnits;
		current			=	Math.floor(val / pixelPerUnit);
		//console.log(current);
		
		attributesText = new Array();
		attributesText[0]	=	'sehr schlecht';
		attributesText[1]	=	'sehr schlecht';
		attributesText[2]	=	'schlecht';
		attributesText[3]	=	'schlecht';
		attributesText[4]	=	'mittel';
		attributesText[5]	=	'mittel';
		attributesText[6]	=	'gut';
		attributesText[7]	=	'gut';
		attributesText[8]	=	'sehr gut';
		attributesText[9]	=	'sehr gut';
		attributesText[10]	=	'sehr gut';
		
		attributesRate = new Array();
		attributesRate[0]	=	'0.5';
		attributesRate[1]	=	'1.0	';
		attributesRate[2]	=	'1.5';
		attributesRate[3]	=	'2.0';
		attributesRate[4]	=	'2.5';
		attributesRate[5]	=	'3.0';
		attributesRate[6]	=	'3.5';
		attributesRate[7]	=	'4.0';
		attributesRate[8]	=	'4.5';
		attributesRate[9]	=	'5.0';
		attributesRate[10]	=	'5.0';
		
		main 			=	new Array();
		main['text'] 	= 	attributesText[current]
		main['rate'] 	= 	attributesRate[current]
		
		return main;
	}
	
	
	function convertPrice(val) {
		
		return Math.round(val);
		
	}
	
	
	
	function defaultInputText(obj, pretext) {
		
		
		if (pretext == "") {
			
			obj.value  = "";
			
		} else {
			
			if (obj.value == "") {
				obj.value  = pretext;	
			}
			
		}
		
	}
	
	function hideCurrentLayer() {
		
			if ($(currentDisplayedLayer)) {
				$(currentDisplayedLayer).hide();
				$('#overlay').hide();
			}
			
	} 
	
	function showCommentForm(id) {
				
		if (id) {
			$("#commentIframe").attr('src', '/product/addcomment/id/'+id);
			$("#layer_mbc_comments1").show();
			$("#overlay").show();
			currentDisplayedLayer = "#layer_mbc_comments1";	
		}
		
	}
	
	function showLoginForm(redirect) {

		
		$("#commentIframe").attr('src', '/user/quicklogin/redirect/'+escape(redirect));
		
		$("#layer_mbc_comments1").show();
		$("#overlay").show();
		currentDisplayedLayer = "#layer_mbc_comments1";	
		
	}
	
	
	function showTellaFriendForm(id) {
				
		if (id) {
			$("#tellafriendIframe").attr('src', '/product/tellafriend/id/'+id);
			$("#layer_mbc_tellafriend1").show();
			$("#overlay").show();
			currentDisplayedLayer = "#layer_mbc_tellafriend1";	
		}
		
	}
	
	function rememberBoxStatus(block, status) {
		$.get("/search/set", { bn: block, bv:  status} );
	}
	
	function searchResultToggle (obj, block) {
		
		
		
		if ($("#"+obj.id+" > a").attr('class') == 'close') {
			$("#"+obj.id+" > a").removeClass("close");
			$('#'+block).slideDown('fast');
			rememberBoxStatus(block, '1');
		} else {
			$("#"+obj.id+" > a").addClass("close");
			$('#'+block).slideUp('fast');
			//console.log($(obj).parent().find('input').attr('checked', 'false'));
			//$(obj).parent().find('input').attr('checked', false);
			rememberBoxStatus(block, '0');
		}
		
	}
	
	function rememberBoxStatus(block, status) {
		$.get("/search/set", { bn: block, bv:  status} );
	}
	
	
	//function addcomment(gender) {
	function addcomment(user_id, gender, nickname, date, text, image) {
		
		
		if (image == "") {
			image  = getGenderImage(gender);
		}
		
		var comment ='<div class="kommentar">\
				<a href="/user/index/id/'+user_id+'"><img src="'+image+'" alt="" /></a>\
				<div class="links">\
					<a href="/user/index/id/'+user_id+'">'+nickname+'</a>\
					<a href="/user/index/id/'+user_id+'">'+date+'</a>\
				</div>\
				<p>'+text+'</p>\
			</div>';
		
		$("#comments_empty").html('');
		amount = ($("#comment_amount").html());
		amount = parseInt(amount);
		amount++;
		
		$("#comment_amount").html(amount);
		$("#comment_items").append(comment);
		
		
	}
	
	
	function getGenderImage(gender) {
		
		genderImg 		= 	new Array();
		genderImg['1']	=	'/images/icons/profil_girl.jpg';
		genderImg['2']	=	'/images/icons/profil_boy.jpg';
		
		if (genderImg[gender]) {
			return genderImg[gender];
		} else {
			return genderImg[1];
		}
		
	}
	
	
	function brandSwitcher(category) {
		
		tabLinks = $(".tabs > ul > li a").removeClass('akt');
		
	}
	
	
	function addToLightbox (obj, product_id, lightbox_type_id) {
		
		obj = $(obj);
		
		
		amount = $('#lightbox_counter').html();
		
		if (obj.hasClass('akt')) {
			obj.removeClass('akt');
			$.get("/product/removefromlightbox", { id: product_id, lbt:  lightbox_type_id} );
			if (lightbox_type_id == 1) { 
				num = parseInt(amount)-1;
				if (num < 0) num = 0;
				$('#lightbox_counter').html(num);	
			}
		} else {
			
			$.get("/product/addtolightbox", { id: product_id, lbt:  lightbox_type_id}, 
				function(data) {
					if (data == 'false') {
						showLoginForm('id='+product_id+'&lbt='+lightbox_type_id);
					} else {
					
						obj.addClass('akt');	
						
						if (lightbox_type_id == 1) {
							num = parseInt(amount)+1;
							$('#lightbox_counter').html(num);
						}
					}
					
				}
			);
			
		}
		
	}
	
	function removeFromLightbox (obj, product_id) {
		
		amount = $('#lightbox_counter').html();
		
		obj = $(obj);
		obj.parent().parent().toggle('slow');
		
		num = parseInt(amount)-1;
		if (num < 0) num = 0;
		$('#lightbox_counter').html(num);
		
		$.get("/product/removefromlightbox", { id: product_id} );
		
	}
	
	
	function extendTeaserBox(obj) {
		
		obj = $(obj);
		obj = obj.parent().parent().children('.extended').toggle('slow');

	}
	
	function showVotingLayer(id) {
		
		if (id) {
			$("#votingIframe").attr('src', '/product/vote/id/'+id);
			$("#layer_mbc_voting1").show();
			$("#overlay").show();
			currentDisplayedLayer = "#layer_mbc_voting1";	
		}
		
		
	}
	function showOffersLayer(id) {
		
		if (id) {
			$("#offersIframe").attr('src', '/product/offers/id/'+id);
			$("#layer_mbc_offers1").show();
			$("#overlay").show();
			currentDisplayedLayer = "#layer_mbc_offers1";	
		}
		
		
	}
	
	function boxfour_prev(src, headline){
		
		var elements 	= eval('four_teaser_elements_'+src);

		var pos 		= eval(eval('box_four_slider_pos_'+src)-1);
		
		if (pos < 0) pos = 9;
		
		var keyword 	= elements[pos];
		
		eval ('box_four_slider_pos_'+src+"="+eval(pos)+";");
		
		$.get("/index/boxfourteaser", { keyword: keyword, layout_disabled: 1, src: src, headline: headline}, 
			function(data) {
				
				$('#boxfour_wrapper_'+src).html(data);
				
			});
		
		return false;
		
	}
	
	
	function boxfour_next(src, headline){
		
		var elements 	= eval('four_teaser_elements_'+src);
		
		var pos 		= eval(eval('box_four_slider_pos_'+src)+1);
		
		if (pos > 9) pos = 0;
		
		eval ('box_four_slider_pos_'+src+"="+eval(pos)+";");
		

		var keyword 	= elements[pos];
		
		$.get("/index/boxfourteaser", { keyword: keyword, layout_disabled: 1, src: src, headline: headline}, 
			function(data) {
				
				$('#boxfour_wrapper_'+src).html(data);
				
			});
		
		
		
		
		return false;
	}