(function($){
	$(".thumb").click(function() {
	    $("#showcase").addClass("loading");
		$img = $(this).attr("href");
		$title = $(this).attr("title");
		$desc = $(this).parent().find(".imageDesc").clone();
		$date = $(this).parent().find(".imageDate").clone();
		$("#details").empty();
		$("#details").hide();
		
		$("#details").append("<h2>" + $title + "</h2>");
		
		var img = new Image();
		$(img).load(function () {  
			$("#details").append(this);
			//imgResize($(this));
		  
		  $("#details").append($date);
		  $("#details").append($desc);
		  $("#details").fadeIn("fast");
		  $("#showcase").removeClass("loading");
		}).attr('src', $img)
		    .one("load",function(){ //fires (only once) when loaded
				$("#details").find(".imageDesc").css("width",$(this).width());
            }).each(function(){
                if(this.complete) //trigger load if cached in certain browsers
					$("#details").find(".imageDesc").css("width",$(this).width());
            });
;
		
		return false;
	});
	
	function imgResize($img) {
	    var old_height = $img.height();
		var old_width = $img.width(); 
		if(old_width > 750) {
			var ratio = (old_height / old_width );
			var new_width = 750;
			var new_height = (750 * ratio);
			$img.height(new_height).width(new_width);
			
			$img.after("<a class=\"fb\" href=\"" + $img.attr('src') + "\">fullsize</a>");
		}
	}
	
	var $filters = $('a.filter');
	var $imgThumbs = $('ul.thumbs li');
		
	$filters.click(function () {
	    $filters.removeClass("active");
        var filterName = $(this).attr("id");
		//Make them all disipear
		$('ul.thumbs').fadeOut('normal', function () {
			if(filterName != 'seeAll') {
				$imgThumbs.find('a.'+filterName).parent().show();
				$imgThumbs.find('a').not('.'+filterName).parent().hide();
			} else {
				$imgThumbs.show();
			}          
          $('ul.thumbs').fadeIn('fast');
        });
					
		$(this).addClass("active");
			
		return false;
	});
	
	$("#galleryFilter").click(function(){
	  if ($(this).hasClass("open")){
	    $(this).attr("class","closed");
		$(".filters").slideUp('fast');
	  } else {
	    $(this).attr("class","open");
		$(".filters").slideDown('fast');
	  }
	  
	  return false;
	});

})(window.jQuery);
