$(document).ready(function() {
	// Ghost Text
	$("#input_2_1").attr("title", "Subscribe to my e-mail list");
    $(".populate input").each(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
        }
    });
    $(".populate input").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
        }
    });
    $(".populate input").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
        }
    });

	// Encrypt Email Addresses
	$(".mask").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
	// Archive Animation
	$(".archives .year a").not(".archives .year ul a").click( function() {
		if ( $(this).parent("li").hasClass("expanded") ) {
			$(this).next("ul").slideToggle();
			$(this).parent("li").removeClass("expanded");
		} else {
			$(this).next("ul").slideToggle();
			$(this).parent("li").addClass("expanded");
		}
		
		return false;
	});
	
	// Add Class to Fourth Thumbnail
	$(".thumbnails li:eq(3), .projectThumbnails li:eq(3)").addClass("fourth");
	
	// Portfolio Menu Animation
	$(".thumbnails li, .projectThumbnails li").hover( function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	
	// Image Galleries
	Shadowbox.init();
	$(".shadowbox a").click( function() {
		var random = Math.random() * 10;
		
		Shadowbox.setup("a.shadowbox", { gallery: random });
		$("a.shadowbox:first").trigger("click");
		
		return false;
	});
	
	// Make First Portfolio Thumbnail Active
	$(".thumbnails li:first").addClass("active");
	
	// Portfolio Item Load
	$(".thumbnails li a").click( function() {
		if( !$(this).parent("li").hasClass("active") ) {
			$(".thumbnails li.active").removeClass("active");
			$(this).parent("li").addClass("active");
			
			var url = $(this).attr("href") + " #portfolio";
			
			$("#portfolio").fadeOut( "normal", function() {
				$("#content").append('<div class="ajaxLoader">Loading...</div>');
				$("#portfolio").load( url , function() {
					$(".ajaxLoader").fadeOut( "normal", function() {
						$(".ajaxLoader").remove();
					});
					$("#portfolio").fadeIn( "normal" );
					$(".shadowbox a").click( function() {
						var random = Math.random() * 10;
						
						Shadowbox.setup("a.shadowbox", { gallery: random });
						$("a.shadowbox:first").trigger("click");
						
						return false;
					});
				});
			});
		}
		
		return false;
	});
	
	// Make First Portfolio Thumbnail Active
	$(".projectThumbnails:first").addClass("active");
	
	// Project Load
	$(".projectThumbnails li a").click( function() {
		if( !$(this).parents("ul").hasClass("active") ) {
			$("ul.active").removeClass("active");
			$(this).parents("ul").addClass("active");
			
			var url = $(this).attr("href") + " #portfolio";
			
			$("#portfolio").fadeOut( "normal", function() {
				$("#content").append('<div class="ajaxLoader">Loading...</div>');
				$("#portfolio").load( url , function() {
					$(".ajaxLoader").fadeOut( "normal", function() {
						$(".ajaxLoader").remove();
					});
					$("#portfolio").fadeIn( "normal" );
					$(".shadowbox a").click( function() {
						var random = Math.random() * 10;
						
						Shadowbox.setup("a.shadowbox", { gallery: random });
						$("a.shadowbox:first").trigger("click");
						
						return false;
					});
				});
			});
		} else {
			var random = Math.random() * 10;
			
			Shadowbox.setup("a.shadowbox", { gallery: random });
			$("a.shadowbox").eq( $(this).parent("li").index() ).trigger("click");
		}
		
		return false;
	});
	
	// Remove Depth Class from First Comment
	$("#comments li:first").removeClass("depth-1");
	
	// Slideshows
	$(".page-template-page-home-php #innerfade").innerfade({ timeout: 1000 });
	$(".page-id-13 #innerfade").innerfade();
});


