
	$(function() {
			   
		/*--------------------------------------------------------*/
		/* GLOBAL
		/*--------------------------------------------------------*/
		
		update_sidebar_height();
		$("img").load(function() { update_sidebar_height(); });
		
		$("input.replace").focus(function() {
			var title=$(this).attr("title");
			if(title.length>0&&$(this).val()==title) {
				$(this).val("");
			}
		});		
		$("input.replace").blur(function() {
			var title=$(this).attr("title");
			if(title.length>0&&$(this).val()=="") {
				$(this).val(title);
			}
		});
		
		/*--------------------------------------------------------*/
		/* WORK
		/*--------------------------------------------------------*/
		
		$("div#work.landing div.left ul li h5 a").hover(function() { $(this).parent().parent().addClass("hover"); },function() { $(this).parent().parent().removeClass("hover"); });
		$("div#work a.viewer").click(function() { 
			var id = get_inverse_id($(this).find("img").attr("class"));
			show_viewer(id); return false; 
		});
		$("div#work div#viewer div.header a").click(function() { hide_viewer(); return false; });
		$("div#work.landing div.right ul a").click(function() { show_aha_moment($(this).parent().attr("class")); return false; });
		$("div#work div#aha_moments div.header a").click(function() { hide_aha_moments(); return false; });
		
		/*--------------------------------------------------------*/
		/* BLOG
		/*--------------------------------------------------------*/
	
		// POSTS
		$("div#blog div.posts div.post div.body img").each(function() {
			var src = $(this).attr("src");
			$(this).removeAttr("width"); $(this).removeAttr("height");
			$(this).attr("src","/blog/image.php?w=425&img="+src);
		});
		$("div#blog div.single div.post div.body img").each(function() {
			$(this).removeAttr("width"); $(this).removeAttr("height");
		});
	
		// COMMENTS
		$("div#comments").each(function() { $(this).find("div.comment:last").css("border-bottom","solid 2px #e7e6dc"); });
		$("div#comments a.reply").click(function() {
			var reply = $("div#comments div.reply").clone(true);
			$("div#comments div.top").removeClass("top");
			$("div#comments div.inline").removeClass("inline");
			$(reply).addClass("inline");
			$("div#comments div.reply").slideUp(600,function() { $(this).remove(); });
			$(reply).css("display","none");
			$(reply).find("input#comment_parent").val($(this).parent().find("input.comment_parent").val());
			$(this).parent().after(reply);
			$("div#comments div.reply").slideDown(600);
			return false;
		});
		$("div#comments a.cancel").click(function() {
			var reply = $("div#comments div.reply").clone(true).removeClass("inline").addClass("top");
			$("div#comments div.reply").slideUp(600,function() { $(this).remove(); });
			$(reply).css("display","none");
			$(reply).find("input#comment_parent").val(0);
			$("div#comments").prepend(reply);
			$("div#comments div.reply").slideDown(600);
			return false;										  
		});
		$("div#comments div.reply a.submit").click(function() {
			if( $("input#author").val()==$("input#author").attr("title") || $("input#email").val()==$("input#email").attr("title") || $("textarea#comment").val()==$("textarea#comment").attr("title")) {
				alert("Please enter all the fields and try again.");
			} else {
				$("form#comment_form").submit();
			}
		});
		$("div#comments div.reply .replace").focus(function() {
			if($(this).val()==$(this).attr("title")) {
				$(this).val("");	
			}
		});
		$("div#comments div.reply .replace").blur(function() {
			if($(this).val()=="") {
				$(this).val($(this).attr("title"));	
			}
		});
	
	});
			   
	/*--------------------------------------------------------*/
	/* VARIABLES
	/*--------------------------------------------------------*/
	
	var sidebar_adjust = 0, scroll_return = false;
			   
	/*--------------------------------------------------------*/
	/* MISC FUNCTIONS
	/*--------------------------------------------------------*/
	
	function update_sidebar_height() {
		var height = Math.abs($("div#main").height()-94+sidebar_adjust);
		if(height>Math.abs($("div#sidebar").css("height").replace(/px/,"")))
			$("div#sidebar").css("height",height+"px");
	}
	
	function adjust_sidebar(pixels) {
		sidebar_adjust = pixels;
		update_sidebar_height();
	}
	
	function show_viewer(id) {
		
		// GO TO PROPER LOCATION
		var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
		scroll_return = vscroll;
		if(typeof(scroll_return)!="number") { scroll_return=false; }
		$('html,body').animate({scrollTop: 64}, 600);
		
		// PREPARE OVERLAY
		var overlay_height = $("div#main").height();
		$("div#viewer_overlay").css({display:"block",opacity:0.5,height:overlay_height+"px"});
		
		// SHOW VIEWER
		$("div#viewer").css({display:"block"});
		
		// EMBED VIEWER
		swfobject.embedSWF("/swf/work_viewer.swf", "viewerSWF", "720", "462", "9", false, { contentsource:"/work/images.php?project_id="+project_id, startid:id }, { }, { id:"viewerSWFObj" });
		
	}
	
	function hide_viewer() {
		
		// GO TO PROPER LOCATION
		if(scroll_return) { $('html,body').animate({scrollTop: scroll_return}, 300); }
		
		// HIDE OVERLAY
		$("div#viewer_overlay").css({display:"none"});
		$("div#viewer").css({display:"none"});
		
		// REMOVE VIEWER
		$("div#viewer_container").html('<div id="viewerSWF"></div>');
		
	}
	
	function show_aha_moment(id) {
		
		// GO TO PROPER LOCATION
		var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
		scroll_return = vscroll;
		if(typeof(scroll_return)!="number") { scroll_return=false; }
		$('html,body').animate({scrollTop: 64}, 600);
		
		// PREPARE OVERLAY
		var overlay_height = $("div#main").height();
		$("div#aha_moments_overlay").css({display:"block",opacity:0.5,height:overlay_height+"px"});
		
		// SHOW VIEWER
		$("div#aha_moments").css({display:"block"});
		
		// SHOW CONTENT
		$("div#aha_moments div#aha_"+id).css({display:"block"});
		
	}
	
	function hide_aha_moments() {
		
		// GO TO PROPER LOCATION
		if(scroll_return) { $('html,body').animate({scrollTop: scroll_return}, 600); }
		
		// HIDE OVERLAY
		$("div#aha_moments_overlay").css({display:"none"});
		$("div#aha_moments div.content").css({display:"none"});
		$("div#aha_moments").css({display:"none"});
		
	}
	
	