$(document).ready (function () {
	
	// Menu
	$("#header ul li, #submenu img").bind ("mouseover", {n: "over"}, display_menu);
	$("#header ul li, #submenu img").bind ("mouseout", {n: "out"}, display_menu);
				
	// Shadow
	$(".image img").shadow ();
	
	// Fancybox
	$("a[rel='fancybox']").fancybox({
		'hideOnContentClick': true,
		'overlayShow': false		
	});
	
	// Previous / Next item
	$(".next").bind ("click", {n: "next"}, image_slider);
	$(".previous").bind ("click", {n: "prev"}, image_slider);
});

function image_slider (e) {
	
	// Settings
	var type = e.data.n;
	var current = $("div.detail img.active");
	var image = false;	
					
	
	if (type == "next") {
		image = $(current).parent ().next ();
		
		if (typeof (image.attr ("href")) == 'undefined') {
		
			image = $(current).parent ().parent ().children ("a:first-child");
		}
	}			
		
	if (type == "prev") {
		image = $(current).parent ().prev ();
		
		if (typeof (image.attr ("href")) == 'undefined') {
			
			image = $(current).parent ().parent ().children ("a:last-child");
		}	
	}
	
	if ((typeof ($(image).children ("img[rel!='control']").attr ("src")) != 'undefined') && ($(image).children ("img[rel!='control']").attr ("src") != $(current).attr("src"))) {
		
		$(image).children ("img").css ({display: "block"}).addClass ("active");
		
		
		$(current).removeClass ("active").css ({display: "none"});	
	}
}
		