$(function(){
	// initialize in-field-labels
	$(".herobanner .search_form label, #dealer_controls .dealer_city_search label").inFieldLabels({
		"fadeOpacity":.75
	});

	// dealer locator: mouse over on continents (world map)
	$("#m_world area, #dealer_controls .select_continent a")
		.mouseover(function(){
			var continent = $(this).attr("class");
			$("#map.world #" + continent).addClass("mouseover");
		})
		.mouseout(function(){
			var continent = $(this).attr("class");
			$("#map.world #" + continent).removeClass("mouseover");
		});

	// fix missing max-height in IE6 for dealer locator lists
	if ($.browser.msie && $.browser.version.substr(0,1)==6){
		$("#dealer_controls .select_country div").height( ($("#dealer_controls .select_country div").height()>299) ? 300 : "auto" );
		$("#dealer_controls .select_state div").height( ($("#dealer_controls .select_state div").height()>269) ? 270 : "auto" );
	}

	// filter dealer locator list
	$("#dealer_controls .select_dealertype a").click(function(){
		var className = $(this).attr("class");
		if (className=="dealer_mareslab"){
			$("#map .dealer_list .dealer_list_inner tr.mareslab").show();
			$("#map .dealer_list .dealer_list_inner tr.authorized").hide();
		} else {
			$("#map .dealer_list .dealer_list_inner tr.mareslab").hide();
			$("#map .dealer_list .dealer_list_inner tr.authorized").show();
		}
	});

	// show hide info-overlay on product icons
	$(".features .icons li span.active").mouseover(function(){
		$(".legend li").hide();
		var span = $(this),
			top = span.offset().top + 28,
			left = $(".features").offset().left,
			className = span.attr("class").substring(0, span.attr("class").indexOf(" "));
	
		if (c_region == 'se')
		{
			top = span.offset().top - $(".legend").find(".legend_" + className).height() - 30;
		}
			
		$(".legend").css({"top": top, "left": left}).find(".legend_" + className).show();
		//.fadeIn('fast');
	}).mouseout(function(){
		$(".legend li").hide();
	});

	// toggle volume diagram
	$(".volume_diagram").click(function(ev){
		ev.preventDefault();
		$(this).find("img").slideToggle();
	});

	// initialize show-links for technology-texts / product detail
	$("#technology .tech-texts li").each(function(index){
		$(this).data("c_height", $(this).height());
	});
	$("#technology ul.tech-texts").css({"position":"static"}).find("li:not(:first)").hide();
	$("#technology ul.tech-texts li:first").css({"height":$("#technology ul.tech-texts li:first").data("c_height")})
	$("#technology .tech-links li").click(function(){
		var index = $(this).index(),
			currLink = $("#technology .tech-links li"),
			currText = $("#technology .tech-texts li:eq("+index+")");
		$("#technology .tech-texts li:visible").fadeOut(150, function(){
			currText.fadeIn(300, function(){
				currText.animate({height: currText.data("c_height")}, 300);
			});
		});
		currLink.removeClass("curr").parent().find("li:eq("+index+")").addClass("curr");
	});

	// scroll product detail images
	$(".turn_images a").click(function(ev){
		var clickedLink = $(this),
			images = $("#product_image_large li"),
			images_length = images.length,
			curr_image = $("#product_image_large li:visible").index();
		ev.preventDefault();
		
		if (clickedLink.hasClass("next")){
			if (curr_image < images_length-1){
				if (curr_image==0){
					$(".turn_images a.back").removeClass("back_inactive")
				}
				$("#product_image_large li:eq("+curr_image+")").hide().next().fadeIn();
				curr_image +=2;
				$("#curr_img").html(curr_image);
				if (curr_image==images_length){
					clickedLink.addClass("next_inactive")
				}
			}
		}
		if (clickedLink.hasClass("back")){
			if (curr_image > 0){
				if (curr_image==images_length-1){
					$(".turn_images a.next").removeClass("next_inactive")
				}
				$("#product_image_large li:eq("+curr_image+")").hide().prev().fadeIn();
				$("#curr_img").html(curr_image);
				if (curr_image==1){
					clickedLink.addClass("back_inactive")
				}
			}
		}
	});

	// news detail image slides
	$("#news_gallery .gallery_nav a").click(function() {
		if ( $("#" + this.rel).is(":hidden") ) {
			$("#news_gallery .gallery_output img").slideUp();
			$("#" + this.rel).slideDown();
		}
	});

	

	

});
