// execute your scripts when the DOM is ready. this is mostly a good habit
$(document).ready(function() {

	// News scroller
	// initialize scrollable
	$(".scrollable").scrollable({circular: true}).autoscroll({ autoplay: true });
	
	// Setup the "Til kommunerne" overlay
	/* $("img[rel]").overlay();
	$("img[rel]").overlay({
		top: 248,
		left: 300,
		fixed: 'true',
		onStart: function(event) {
			event.stopImmediatePropagation();
		}
	});

	$('.tilKommunerne').click(function(event) {
		event.stopImmediatePropagation();
	});

	$(document).click(function() {
		$("img[rel]").each(function() {
			$(this).overlay().close();
		});
	});
	*/
		
	// Show / Hide the DIV
	$(".tilKommunerne img").toggle(
		function() {
			$("#tilKommunerne").css('z-index', 10000).slideDown();
		},
		function() {
			$("#tilKommunerne").slideUp();
		}
	);
	
	// Make a link close the window
	$("a.close").click(
		function() {
			$("#tilKommunerne").slideUp();
		}
	);
	
	// Keep tabs on the mouse position
	var mouseInside = false;
	
	$("#tilKommunerne").hover(function() {
		mouseInside = true;
	}, function() {
		mouseInside = false;
	});
	
	// If mouse is outside of slide div and clicked, then hide the div
	$("body").mouseup(function() {
		if (! mouseInside)
			$("#tilKommunerne").slideUp();
	});
	
	
	// Frontpage slideshow
	$("a.groupedImages").fancybox();
	// Launch gallery when the gallery image is clicked
	$("#launchGallery").click(function() {
		$("a.groupedImages:first").trigger("click");
		}
	);
	
});

