$(document).ready(function() {
	
	if ($.browser.msie && $.browser.version.substring(0,1) === '6') {
		$("#ie6").show();
	}
	
	$("#content, .info-short").hide(0);
	$("#content, .info-short").fadeIn("slow");
	
    $('.presentation').cycle({
		fx: 'fade',
		speed: 3000
	});
	
	$('#exclusive').cycle({
		fx: 'fade',
		speed: 2000,
		delay: -1000
	});
	
	$('.news').cycle({ 
	    fx:     'fade', 
	    timeout: 4000, 
	    delay:  -1000 
	});
	
	$("#presentation").fancybox({
		'padding'           : 0,
		'height'			: 404,
		'width'				: 717,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade'
	});
	
	$("#ref_bilder div a").each(function(){
		$(this).fancybox({
			'padding'           : 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic'
		});
	});
	/*
	$(".product input", this).click(function(){
		var checked = $(this).parent().children("input:checked").val();
		
		var title = $(this).parent().children("h3").attr("title");
		
		if (title == "Circle"){
			
			var link1 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CIRCLE%20250&visa=1-200&Sort=Beskr&Visn=Std";
			var link2 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CIRCLE%20350&visa=1-200&Sort=Beskr&Visn=Std";
			
			if (checked == 1){
				$(this).parent().children("a.buyproduct").attr("href", link1);
			} else {
				$(this).parent().children("a.buyproduct").attr("href", link2);
			}
			
		} else if (title == "Square"){
			
			var link1 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=SQUARE%20200&visa=1-200&Sort=Beskr&Visn=Std";
			var link2 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=SQUARE%20300&visa=1-200&Sort=Beskr&Visn=Std";
			
			if (checked == 1){
				$(this).parent().children("a.buyproduct").attr("href", link1);
			} else {
				$(this).parent().children("a.buyproduct").attr("href", link2);
			}
			
		} else if (title == "Melloni"){
			
			var link1 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-2004TC200-D30-24C&visa=1-1000&Sort=Beskr&Visn=Std";
			var link2 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-2004TC300-D30-24C&visa=1-1000&Sort=Beskr&Visn=Std";
			
			if (checked == 1){
				$(this).parent().children("a.buyproduct").attr("href", link1);
			} else {
				$(this).parent().children("a.buyproduct").attr("href", link2);
			}
			
		} else if (title == "Remer1"){
			
			var link1 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-D150P&visa=1-200&Sort=Beskr&Visn=Std";
			var link2 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-D200P&visa=1-200&Sort=Beskr&Visn=Std";
			
			if (checked == 1){
				$(this).parent().children("a.buyproduct").attr("href", link1);
			} else {
				$(this).parent().children("a.buyproduct").attr("href", link2);
			}
			
		} else if (title == "Remer2"){
			
			var link1 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-D150M&visa=1-200&Sort=Beskr&Visn=Std";
			var link2 = "http://shop.clearshower.com/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artgrp=&artnr=CL-D200M&visa=1-200&Sort=Beskr&Visn=Std";
			
			if (checked == 1){
				$(this).parent().children("a.buyproduct").attr("href", link1);
			} else {
				$(this).parent().children("a.buyproduct").attr("href", link2);
			}
			
		}
		
	});
	*/
	$(".product .toggleView a.switchColor", this).click(function(e){
		
		if ($(this).parent().children("img.black").is(":visible")){
			
			// Fade out black and show white:
			$(this).parent().children("img.black").fadeOut("medium");
			
			// Get alt-tag and change big image path:
			var fancy = $(this).parent().children("img.white").attr("alt");
			var title = $(this).parent().children("img.white").attr("title");
			$(this).parent().children("a.toggleLarge").attr("href", "img/" + title + "/" + fancy + ".jpg");
			
			$(this).parent().children("a.togglePointOne").attr("href", "img/" + title + "/blender-bw.jpg");
			$(this).parent().children("a.togglePointTwo").attr("href", "img/" + title + "/set2-bw.jpg");
			
		} else {
			
			// Fade in black and hide white:
			$(this).parent().children("img.black").fadeIn("medium");
			
			// Get alt-tag and change big image path:
			var fancy = $(this).parent().children("img.black").attr("alt");
			var title = $(this).parent().children("img.black").attr("title");
			$(this).parent().children("a.toggleLarge").attr("href", "img/" + title + "/" + fancy + ".jpg");
			
			$(this).parent().children("a.togglePointOne").attr("href", "img/" + title + "/blender-bb.jpg");
			$(this).parent().children("a.togglePointTwo").attr("href", "img/" + title + "/set2-bb.jpg");
		}

		e.preventDefault();
	});
	
	$(".product .toggleView a.toggleLarge").each(function(){
		$(this).fancybox({
			'padding'           : 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic'
		});
	});
	
	$(".product .info-button").each(function(){
		$(this).fancybox({
			'padding'      : 0,
			'transitionIn' : 'fade',
			'transitionOut' : 'fade',
			'speedIn'  : 600, 
			'speedOut'  : 200, 
			'overlayShow' : true
		 });
	});
	
	$("#duschikoner ul li", this).hover(function(){
		
		var title = $(this).children("span").attr("class");
		$("#beskrivning").stop(true, true).fadeIn();
		$("#beskrivning .mid div").fadeOut("fast", function(){
			
			if (title == "1_sv"){
				$("#beskrivning .mid div").html(
				"<h3>Belysning genom duschen:</h3>" + 
				"<small>När luft och vatten virvlar inuti duschen reflekteras ljuset på ett vackert sätt. Bäst effekt får du med spottbelysning uppifrån.</small>");
			
			} else if (title == "2_sv"){
				$("#beskrivning .mid div").html(
				"<h3>Vinklad duschning:</h3>" + 
				"<small>Om du inte vill blöta ner håret så vinklar du duschen. Luften i silen gör att vattnet pressas ut över hela duschens yta.</small>");
			} else if (title == "3_sv"){
				$("#beskrivning .mid div").html(
				"<h3>Luftblandning:</h3>" + 
				"<small>Med den medföljande insexnyckeln kan du justera mängden luft som blandas med vattnet i duschen. För att minska luftinblandningen, skruva medurs cirka 1-1.5 varv. Du ser och känner direkt hur vattenstrålarna förändras. Kom ihåg att aldrig belasta skruven med kraft eftersom att det kan skada gängorna. Justerbar luftblandning finns på modellerna Square och Circle.</small>");
			} else if (title == "4_sv"){
				$("#beskrivning .mid div").html(
				"<h3>Instruktioner:</h3>" + 
				"<small>Klicka att ladda ner instruktioner.</small>");
			} else if (title == "1_en"){
				$("#beskrivning .mid div").html(
				"<h3>Light through the shower:</h3>" + 
				"<small>When air and water whirls around inside the shower, light is beautifully reflected. Best effect is achieved with spot lights from above.</small>");
			} else if (title == "2_en"){
				$("#beskrivning .mid div").html(
				"<h3>Slanted Shower:</h3>" + 
				"<small>If you do not want to get your hair wet, just tilt the shower.  The air in the shower head makes the water flow with full pressure all over the shower.</small>");
			} else if (title == "3_en"){
				$("#beskrivning .mid div").html(
				"<h3>Air mixture:</h3>" + 
				"<small>With the included hex key you can adjust the amount of air that is mixed with water in the shower. In order to reduce the amount of air in the water turn clockwise around: 1-1.5 times. You can instantly see and feel how the water changes. Remember to not use force as it may damage the screw threads. Adjustable air mix is only available on Square and Circle.</small>");
			} else if (title == "4_en"){
				$("#beskrivning .mid div").html(
				"<h3>Download instructions:</h3>" + 
				"<small>Click to download instructions.</small>");
			} else if (title == "1_ger"){
				$("#beskrivning .mid div").html(
				"<h3>Beleuchtung von der Dusche:</h3>" + 
				"<small>Wenn Luft und Wasser wirbelt herum in der Dusche, wird das Licht wunderschön reflektiert. Beste Wirkung wird mit Spots von oben erreicht.</small>");
			} else if (title == "2_ger"){
				$("#beskrivning .mid div").html(
				"<h3>Abgewinkelt Dusche:</h3>" + 
				"<small>Wenn Sie nicht möchten, dass Ihre Haare nass werden, nur neigen die Dusche. Die Luft in den Brausekopf macht den Wasserfluss mit vollem Druck in der ganzen Dusche.</small>");
			} else if (title == "3_ger"){
				$("#beskrivning .mid div").html(
				"<h3>Luft-Gemisch:</h3>" + 
				"<small>Mit dem mitgelieferten Inbusschlüssel können Sie die Menge Luft, die mit Wasser in der Dusche vermischt wird. 1-1,5 mal: Um die Menge der Luft in das Wasser im Uhrzeigersinn drehen, um zu verringern. Sie können sofort sehen und spüren, wie das Wasser ändert. Vergessen Sie keine Gewalt an, da sie die Gewinde beschädigt werden kann. Einstellbare Luft-Gemisch ist nur auf Square und Circle.</small>");
			} else if (title == "4_ger"){
				$("#beskrivning .mid div").html(
				"<h3>Anleitung zum Herunterladen:</h3>" + 
				"<small>Hier klicken instructuions herunterladen.</small>");
			}
	
			$("#beskrivning .mid div").fadeIn();
			title = "";
			
		});
		
	}, function(){
		$("#beskrivning").fadeOut();
	});
	

	$(".togglePointOne, .togglePointTwo").fancybox({
		'padding'           : 0,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
	});
	
	// initialize scrollable
	$(".scrollable").scrollable();
	
	$(".massorToggle").fancybox({
		'padding'           : 0,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
	});
	
	$(".items div img", this).hover(function(){
		if (!$(this).hasClass("active")){
			$(this).stop(true, true).fadeTo("fast", 1.0);
		}
	}, function(){
		if (!$(this).hasClass("active")){
			$(this).stop(true, true).fadeTo("fast", 0.5);
		}
	});
	
	$("#thumbs .items div img").click(function() {
		
		// Check if current thumn is being clicked:
		if ($(this).hasClass("active")) { return; }
		
		// Fetch big image:
		var url = $(this).attr("alt");

		// Fadeout image and replace image:
		//var wrap = $("#big-images");
		$("#big-images img").fadeTo("slow", 0, function(){
		
			// Fade in wrapper:
			$("#big-images img").fadeTo("slow", 1);

			// Replace source:
			$("#big-images").find("img").attr("src", url);
			
			// Replace link URL:
			$("#big-images").find("a").attr("href", url.replace("big", "bigger"));
			
		});
		
		// Activate thumb
		$(".items img").removeClass("active");
		$(this).addClass("active");
		$(this).fadeTo("fast", 1.0);
		
		$(".items div img").each(function(){
			if (!$(this).hasClass("active")){
				$(this).fadeTo("slow", 0.5);
			}
		});
		
	// Simulate click on page load:
	});
	
	//.filter(":first").click()
	
	$(".items div img:first").addClass("active");
	$(".items div img:first").fadeTo("fast", 1);
	
	/*$(".items").tabs("#big-images div", {

		effect: 'fade',
		fadeOutSpeed: "slow",
		clickable: 'false'
		
	}).slideshow();*/
	
});

function toggleInfoBox(id){
	alert(id);
}

Cufon.replace('#menu, .hemvilla p, .title, .presentation-button',{
	fontFamily:'Fujiyama',
	hover: true
});
