$(function() {

		// Activate the sliding nav panel's
	$("#nav-main li#navbathroom a")
		.bind("click", function(e) {
			if ($("#nav-bathroom:visible").length)
				hideDropdownMenu("#nav-bathroom");
			else
				showDropdownMenu("#nav-bathroom");

			e.preventDefault();
			e.stopPropagation();
		});
	$("#nav-main li#navkitchen a")
		.bind("click", function(e) {
			if ($("#nav-kitchen:visible").length)
				hideDropdownMenu("#nav-kitchen");
			else
				showDropdownMenu("#nav-kitchen");

			e.preventDefault();
			e.stopPropagation();
		});
		
		// Stop dropdowns closing when clicked in
	$(".dropdown").bind("click", function(e) {
		e.stopPropagation();
	});
	
		// If anywhere else is clicked, close the dropdowns
	$("body").bind("click", function(e) {
		hideOpenDropdownMenus();
	});

		// Activate the image cycle on the home page
	$("body#home .box-slideshow")
		.wrapInner('<div class="slides"></div>')
		.append('<div class="pager"></div>');
	$("body#home .box-slideshow .slides")
		.cycle({
			fx: 'scrollLeft',
			timeout: 7500,
			pager: ".box-slideshow .pager",
			activePagerClass: 'active'
		});
		
		// Activate the image cycle on the Product detail page
	$("#box-pictures")
		.wrapInner('<div id="fullsize"></div>')
		.append('<div id="thumbnails"></div>');
	$("#box-pictures #fullsize").cycle({
		timeout: 0,
		pager: "#box-pictures #thumbnails",
		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="'+ slide.src +'"><img src="'+ slide.src +'" width="58" height="58" /></a>';
		}
	});

		// Create hotspots for the collection items
	if ($("#collectionitems").length) {
		$("#collectionitems .product").each(function() {
			var hotspot, data, link, _pos, _l, _t;
			data = $(this).data();
			link = $(".product-moreinfolink", this).attr("href");
			_pos = data.hotspot;
			_pos = _pos.split(',');
			_l = parseInt(_pos[0]);
			_t = parseInt(_pos[1]);

			hotspot = '<div class="hotspot"><div class="point"></div><div class="product">'+ $(this).html() +'</div></div>';
			$(hotspot)
				.data("href", link)
				.css({
					position: "absolute",
					left: _l,
					top: _t
				})
				.bind("click", function(e) {
					window.location = link;
				})
				.appendTo(".collectionpicture");
		});
	}
	
	
	
	
	
	// Add fancybox2 to blog photos
	$('body#blog .pictures a').fancybox();
	

});

function showDropdownMenu(selector) {
	hideOpenDropdownMenus();
	$(selector).slideDown('fast');
}

function hideDropdownMenu(selector) {
	$(selector).slideUp('fast');
}

function hideOpenDropdownMenus() {
	$(".dropdown:visible").slideUp('fast');
}

