//	Custom jQuery functions and actions
//	Handcoded by Zarino Zappia

$(document).ready(
	function(){

		$(".post_date, .tag_list").next("p").addClass("first");
		$(".post:first, .project:first").addClass("first");
		$(".project, #sorry").each(function(){
			$(this).find("p:first").addClass("first");
		});
		
		var email_obfuscated = "m1a2il@z1ar2in22o.c2o.21uk";
		var email = email_obfuscated.replace(/1/g, "").replace(/2/g, "");
		$("#sorry p").eq(1).append(' at <a href="mailto:' + email + '">' + email + '</a>');
		
		$("div.project").css({height: "80px", overflow: "hidden"}).wrapInner('<div class="project_inner"></div>').hover(
			function(){
				child_height = $(this).children(".project_inner").height();
				$(this).stop().animate({height: child_height}, function(){
					//	Explicitly set overflow for Safari 2
					$(this).css({overflow: "visible"});
				});
			}, function(){
				var number_of_thumbs = $(this).find(".thumbnail").length;
				$(this).stop().animate({height: "80px"}, function(){
					//	Explicitly set overflow for Safari 2
					$(this).css({overflow: "hidden"});
				});
			}
		);
		
		
		$("div.project").each(
			function(){
				$(this).find("div.thumbnail a").eq(0).addClass("first");
				$(this).find("div.thumbnail a").eq(1).addClass("second");
				$(this).find("div.thumbnail a").eq(2).addClass("third");
			}
		);
		
		$("div.project div.thumbnail a").not(".video").each(
			function(){
				var background_image = $(this).attr("href");
				$(this).css({backgroundImage: "url(" + background_image + ")"});
				
				$(this).toggle(
					function(){
						thumbnail_number = $(this).parent().prevAll(".thumbnail").length;
						offset_number = (-125 * thumbnail_number) + "px";
						image_height = $(this).attr("rel");
						$(this).css({zIndex: "100"}).animate({width: "355px", height: image_height, left: offset_number}, 250);
						$(this).parents(".project").find("p").eq(0).animate({marginTop: (image_height - 80)}, 250);
						current_height = $(this).parents(".project").height();
						$(this).parents(".project").animate({height: current_height + (image_height - 80)}, 250);
						return false;
					}, function(){
						$(this).animate({width: "105px", height: "80px", left: "0px"}, 250, function(){ 
							$(this).css({zIndex: "1"}); 
						});
						$(this).parents(".project").find("p").eq(0).animate({marginTop: "0px"}, 250);
						$(this).parents(".project").animate({height: current_height}, 250);
						return false;
					}
				);
			}
		);
		
		
	}
);