$(document).ready(function() {

	// Find equivalent of EE segment_1
	var segment_1 = location.pathname.split("/")[1];
	
	// About menu
	if (segment_1 == 'about') {
		$("#about").css("background-image","url(/images/layout/topnav-on/about.gif)");$("#about_menu").show();
	} else {
		$("#about").mouseover(function() { 
			$(this).css("background-image","url(/images/layout/topnav-on/about.gif)");$("#about_menu").show();
		});
		$("#about").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/about.gif)");$("#about_menu").hide();
		});		
	}
	
	// Type menu
	if (segment_1 == 'type') {
		$("#type").css("background-image","url(/images/layout/topnav-on/type.gif)");$("#type_menu").show();
	} else {
		$("#type").mouseover(function() {
			$(this).css("background-image","url(/images/layout/topnav-on/type.gif)");$("#type_menu").show();
		});
		$("#type").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/type.gif)");$("#type_menu").hide();
		});
	}
	
	// Contact menu
	if (segment_1 == 'contact') {
		$("#contact").css("background-image","url(/images/layout/topnav-on/contact.gif)");$("#contact_menu").show();
	} else {
		$("#contact").mouseover(function() {
			$(this).css("background-image","url(/images/layout/topnav-on/contact.gif)");
		});
		$("#contact").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/contact.gif)");
		});
	}

	// News menu
	if (segment_1 == 'news' || segment_1 == '') {
		$("#news").css("background-image","url(/images/layout/topnav-on/news.gif)");
	} else {
		$("#news").mouseover(function() {
			$(this).css("background-image","url(/images/layout/topnav-on/news.gif)");
		});
		$("#news").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/news.gif)");
		});
	}

	// Store menu
	if (segment_1 == 'store') {
		$("#store").css("background-image","url(/images/layout/topnav-on/store.gif)");$("#store_menu").show();
	} else {
		$("#store").mouseover(function() {
			$(this).css("background-image","url(/images/layout/topnav-on/store.gif)");$("#store_menu").show();
		});
		$("#store").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/store.gif)");$("#store_menu").hide();
		});
	}
	
	// What is menu
	if (segment_1 == 'whatis') {
		$("#whatis_menu").show();
	} else {
		$("#whatis").mouseover(function() {
			$("#whatis_menu").show();
		});
		$("#whatis").mouseout(function() { 
			$("#whatis_menu").hide();
		});
	}
	
	
	// Gallery menu
	if (segment_1 == 'gallery') {
		$("#gallery").css("background-image","url(/images/layout/topnav-on/gallery.gif)");$("#gallery_menu").show();
	} else {
		$("#gallery").mouseover(function() {
			$(this).css("background-image","url(/images/layout/topnav-on/gallery.gif)");$("#gallery_menu").show();
		});
		$("#gallery").mouseout(function() { 
			$(this).css("background-image","url(/images/layout/topnav-off/gallery.gif)");$("#gallery_menu").hide();
		});
	}
	
	// add caption to first large image ('visible' didn't work in safari)
	var caption =  $("#gallery-lg img:first").attr("alt")
	$("#gallery-lg").append("<div id='caption'>"+caption+"</caption>")
	
	// Thumbnails to Enlargements
	$("#gallery-th img").click(function() {
		var new_img = $(this).attr("src").replace("-th.","-lg.");
		var cur_img = $("#gallery-lg img:visible").attr("src");
		//console.info("replacing "+cur_img+" with "+new_img);
		if (cur_img != new_img) {			
			$("#gallery-lg > img:visible").fadeOut(400, function() {
				$("#gallery-lg #caption").html($("#gallery-lg img[src="+new_img+"]").attr("alt"))
				$("#gallery-lg img[src="+new_img+"]").fadeIn(400, function() {
					
				});
			});
		}
	});

	// Colorbox rules	
	$("a.colorbox").colorbox()

});

