$(document).ready(function()
{	

	// Drop down menus for IE6
	$("#nav li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	
	$("#nav li:last-child").addClass("last");
	
	$('a.lightbox').lightBox();

	
	// Links with rel="external" open in a new window
	$("a[rel='external']").attr("target","_blank");
	
	// Print link functionality
	$("a.print").click(
		function () 
		{
			if (window.print)
				window.print();
			else
				alert("Sorry, your browser doesn't support the print feature. Use the File menu on your browser to select Print.");
			return false;	
		}
	);

	$("p > img.image-left").closest("p").css("padding","0");
	$("p > img.image-right").closest("p").css("padding","0");
	
	// Fix PNG for IE6
	$(document).pngFix();
	
	
	
	
	/*
	// Menu toggles
	$("a.description-toggle").show();
	//$("a.description-toggle").parent().next("ul").wrap("<div class=\"description\"></div>");
	$("div.description").hide();
	
	$("a.description-toggle").each(
		function( intIndex )
		{
			var closeLink = $("<p  class=\"description-close\"><a href=\"#\">Close</a></p>");
			$(this).parent().next(".description").append(closeLink);
			
			$(closeLink).click(function () 
				{
					$(this).closest("div.description").slideUp();
					
					var showHideLink = $("a.description-toggle").eq(intIndex);
					var showHideLinkText = $(showHideLink).text();
					var showHideNewText = showHideLinkText.replace(/Hide/, "View");
					$(showHideLink).text(showHideNewText);
					
					$(this).closest("li").removeClass("active");
					
					return false;
				});
			}
	);
	
	$("a.description-toggle").click(function () 
	{
		var linktext = $(this).text();
		if ($(this).parent().next("div.description").eq(0).is(":hidden")) 
		{
			var newtext = linktext.replace(/View/, "Hide");
			$(this).text(newtext);
			$(this).parent().next("div.description").eq(0).slideDown();
			$(this).closest("li").addClass("active");
			return false;
		} 
		else 
		{
			var newtext = linktext.replace(/Hide/, "View");
			$(this).text(newtext);
			$(this).parent().next("div.description").eq(0).slideUp();
			$(this).closest("li").removeClass("active");
			return false;
		}
	});

	
	var galleryRandomNumber = Math.floor(Math.random()*12);
	var initialGalleryImage = $(".gallery .thumbnails li").eq(galleryRandomNumber).next("img")
	var initialGalleryCaption = $(".gallery .thumbnails
		*/
	
	
	$(".thumbnails a").click(
		function () 
		{
			var imagepath = $(this).attr("href");
			var caption = $(this).next("div.caption").text();
			//alert("path="+imagepath+" caption="+caption);
			
			 $("#gallery-image").attr({ 
	          src: imagepath,
	          alt: caption
	        });

			$("#gallery-caption").text(caption);
			
			return false;
		}
	);
	
	
	$(".thumbnails a").each(
		function( intIndex )
		{
			var imagepath = $(this).attr("href");
			jQuery.preLoadImages(imagepath);
		}
	);
	
	
	
	
});







/* Google map functions */
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});




(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
