$(document).ready(function() {

	// To load a gallery on page load, use:
	// loadFlickr('72157620906549765','37054878@N03')
	
	$("#feed").hide();
	$("#home").show();
	
	$("#nav li, #nav li a").click(function(){
		$("#nav li").removeClass("active");
		$(this).addClass("active");
		var mylink = (this.firstChild);
		$("#feed").show();
		$("#home").hide();
		// console.log((mylink.href).indexOf("loadFlickr"));
		if ((mylink.href).indexOf("loadFlickr") != -1) {
			var myfunc = (mylink.href).split(":");
			eval(myfunc[1]);
			return false;
		} else {
			$("#feed").hide();
			$("#home").show();
			return false;
		endif };
	})
	
	$("#maillink a").click(function(){
		$("#feed").load("contact.html #mailform");
		$("#feed").show();
		$("#home").hide();
		return false;
	})
	
	
	$('#home a').lightBox();  // allows lightbox to work on home page

});

function addLB() {
	$('#feed a').lightBox();
}

function loadFlickr(setid, flickrid)
{
	// Display a loading icon in our display element
	$('#feed').html('<span><img src="images/ajax-loader.gif" height="32" width="32" alt="loader" /></span>');

	// Request the JSON and process it
	$.ajax({
		type:'GET',
		url:"http://api.flickr.com/services/feeds/photoset.gne",
		data:"set="+setid+"&nsid="+flickrid+"&lang=en-us&format=json&jsoncallback=?",
		success:function(feed) {
			// Create an empty array to store images
			var thumbs = [];


			// Loop through the items
			for(var i=0, j=feed.items.length; i < j && i < 20; ++i) 
			{
				//extract the title to put it in the title of the anchor and alt of the img
				var ttl = feed.items[i].title;

			
				// Manipulate the image to get thumb and medium sizes
				var img = feed.items[i].media.m.replace(
					/^(.*?)_m\.jpg$/, 
					'<a href="$1.jpg"  title='+ttl+'><img src="$1_m.jpg" alt='+ttl+' /></a>'
				);

				// Add the new element to the array
				thumbs.push(img);
			}

			// Display the thumbnails on the page
			$('#feed').html(thumbs.join(''));

			// A function to add a lightbox effect
			addLB();
		},
		dataType:'jsonp'
	});
}

	function validate() 
	  { 
		if (document.mailto.name.value == "") {
		 alert("Please enter your name.");
		 return false;
		 }
		 if (document.mailto.email.value.indexOf("@") == -1 || document.mailto.email.value == "") {
		 alert("Please enter a proper email address.");
		 return false;
		 }
		 if (document.mailto.topic.value == "") {
		 alert("Please enter a topic");
		 return false;
		 }
		 if (document.mailto.message.value == "") {
		 alert("Please enter a message");
		 return false;
		 }
	  }
