$(function() {
	intervalID = setInterval( "slideShow()", 5000 );
});

$(document).ready(function() {

	var newHeight = $("#news-box").height();	
	
	if (newHeight) { 
		newHeight = newHeight + 32;
		newHeight = newHeight + "px";
		$(".index-page #page").css("height", newHeight);
	}
	
	$("a.ex").click(function() {
		var curClass = $(this).parent().attr("class");
		if (curClass.indexOf("expanded") != -1) {
			var newClass = curClass.replace("expanded", "expand");
		}
		else if (curClass.indexOf("expand") != -1) {
			var newClass = curClass.replace("expand", "expanded");
		}
		$(this).parent().attr("class", newClass);
		return false;
	});
	
	$("div.more a").hover(function() {
		$(this).parent().css("background-image", "url(theme/img/arrow-black.gif)");
	},
	function() {
		$(this).parent().css("background-image", "url(theme/img/arrow.gif)");
	});
	
	$("#btn-close a").hover(function() {
		$(this).children("span").css("background-image", "url(/theme/img/pixel-black.gif)");	
		$(this).children("img").attr("src", "/theme/img/x-close-black.gif");
	},
	function() {
		$(this).children("span").css("background-image", "url(/theme/img/pixel.gif)");		
		$(this).children("img").attr("src", "/theme/img/x-close.gif");
	});
	
	$("#btn-nav a").hover(function() {
		$(this).children("span").css("background-image", "url(/theme/img/pixel-black.gif)");
	},
	function() {
		$(this).children("span").css("background-image", "url(/theme/img/pixel.gif)");
	});
	
	$(".recent-kitchen").click(function() {
		var thisPic = $(this).children("img").attr("src").replace(".jpg", "").replace("/media/recent/", "");
		var newPic = thisPic + "-large";
		$("#large-photo").children("img").css("display", "none");
		$("#" + newPic).css("display", "block");
		$("#large-photo .active").removeClass("active");
		$("#" + newPic).attr("class", "active");
		$("#overlay").css("display", "block");
		$("#photo-enlarge").fadeIn();
//		$("#photo-enlarge").css("display", "block");
		return false;
	});
	
	$("#btn-close a").click(function() {
		$("#overlay").css("display", "none");
		$("#photo-enlarge").css("display", "none");
		return false;
	});
	
	$("#photo-prev").click(function() {
		var curPic = $("#large-photo .active").attr("src").replace("-large.jpg", "").replace("/media/recent/", "").replace("kitchen-", "");
		var curPic = parseInt(curPic);
		var newPic = curPic - 1;
		var curry = $("#large-photo .active");
		
		if (!$(curry).prev().attr("id")) {
			$("#large-photo img:last").attr("class", "active");
			$("#large-photo img:last").css("display", "block");
		}
		else {
			$(curry).prev().attr("class", "active");
			$(curry).prev().css("display", "block");
		}
		$(curry).css("display", "none");
		$(curry).removeClass("active");
		return false;
	});
	
	$("#photo-next").click(function() {
		var curPic = $("#large-photo .active").attr("src").replace("-large.jpg", "").replace("/media/recent/", "").replace("kitchen-", "");
		var curPic = parseInt(curPic);
		var newPic = curPic + 1;
		var totalPics = $("#large-photo").children().size();
		var curry = $("#large-photo .active");
		
		if (!$(curry).next().attr("id")) {
			$("#large-photo img:first").attr("class", "active");
			$("#large-photo img:first").css("display", "block");
		}
		else {
			$(curry).next().attr("class", "active");
			$(curry).next().css("display", "block");
		}
		$(curry).css("display", "none");
		$(curry).removeClass("active");
		return false;
	});
	
	$("#slide-buttons a").click(function() {
		if ($(this).parent().attr("class") != "active") {
			stopSlideShow();
			var target = $(this).attr("id").replace("link-", "");
			$("#slides .active").fadeOut("slow");
			$("#slides .active").removeClass("active");
			$("#slide-" + target).fadeIn("slow");
			$("#slide-" + target).addClass("active");
			$("#slide-buttons .active").removeClass("active");
			$(this).parent().addClass("active");
			setTimeout("startSlideShow()", 12000); 
		}
		return false;								 
	});
	
	$("div.soort img").click(function() {
		var newImage = $(this).attr("src").replace(".jpg", "-large.jpg");
		$("#page-header img").attr("src", newImage);
		window.scrollTo(0,0);
	});
	
});

function slideShow() {
	var active = $("#slides .active");
	$(active).fadeOut();
	$(active).removeClass("active");
	if ($(active).next().length != 0) {
		$(active).next().fadeIn();
		$(active).next().addClass("active");
		var activeID = $(active).attr("id").replace("slide-", "");
		var nextID = parseInt(activeID) + 1;
		$("#slide-buttons .active").removeClass("active");
		$("#slide-buttons #link-" + nextID).parent().addClass("active");
	}
	else {
		$("#slide-1").fadeIn();
		$("#slide-1").addClass("active");
		$("#slide-buttons .active").removeClass("active");
		$("#link-1").parent().addClass("active");
	}
}

function stopSlideShow() {
	intervalID = clearInterval(intervalID);	
}

function startSlideShow() {
	intervalID = clearInterval(intervalID);	
	intervalID = setInterval( "slideShow()", 5000 );
}

