$(document).ready(function(){

	$('.thumbstrip_img').imgpreload ({
		each: function()
		{
			var hvr_img = $(this).attr("src").split("vign_").join("");
			$.imgpreload(hvr_img);
		}
	});
	
	// hover actions for gallery thumbnails
	$(".thumbstrip_img").hover(function() {
		url_no_hvr = $(this).attr("src");
		$(this).attr("src", $(this).attr("src").split("vign_").join(""));
	}, function() {
		$(this).attr("src", url_no_hvr);
	});

	// hover actions for archive thumbnails
	$(".archive_thumbstrip_img").hover(function() {
		$(this).attr("src", $(this).attr("src").split("images/").join("conf/thumb_gen.php?p=images/"));
	}, function() {
		$(this).attr("src", $(this).attr("src").split("conf/thumb_gen.php?p=").join(""));
	});
	
	
	$('img[id*="img_id"]').click(function() {
		//Get thmb_x from image's parent <div> for correct offset
		var thmb_x = $(this).parent('a').offset().left + ($(this).parent('a').outerWidth() / 2);
		var dest_x = $("#thumbstrip").offset().left + ($("#thumbstrip").outerWidth() / 2);
		var distance = dest_x - thmb_x;

		$("#thumbs").animate({ left: '+='+distance }, 'slow');

		var img_id = $(this).attr("id").split("img_id").join("");
		GetImg(img_id);
	});
	
	$('#thumbs li a').click(function(event) {
		var loc_hash = '#!/';
		loc_hash += $(this).parent('li').attr('id');
		//location.hash = loc_hash;
		event.preventDefault();
	});
	
	function GetImg(img_id){	
		$('#img_canvas').load('conf/getimg.php',{ "id" : img_id }, function() {
			$("img#med_img").load(function() {
				var dropshadow_w = $("#med_img").width();
				var dropshadow_h = $("#med_img").height();
				$("#img_canvas").css("background-image","url(conf/dropshadow.php?w="+dropshadow_w+"\\&h="+dropshadow_h+")");
			});
			var img_title = $("#med_img").attr("alt");
			$('h2').html(img_title);
		});
	}

});
