/**
 * DOM Load
 */
$(document).ready(function() {
	pageEnhance();	
});

/**
 * General "init" function for progressively enhancing the page on DOM load
 */
function pageEnhance() {
	newWindowLinks();
	clickable();
	defaultText();
	inPageLinksScrollTo();
	$("#site-description").click(function(){
		window.location = "/";
	})
}



/* Remove default value and replace */
function defaultText() {
	$(".defaultText").unbind("focus,blur").focus(function () {		
		if ($(this).val() == $(this)[0].defaultValue) {
        	$(this).val("");
        }
	 }).blur(function() {
        if ($(this).val() == "") {
        	$(this).val($(this)[0].defaultValue);
     	}
	 });
}


/* Clickable blocks */
function clickable() {
	$(".clickable:has(a):not(.disabled)").live("click",function() {
		var link = $("a",this).eq(0).attr("href");
		window.location = link;
	}).hover(function(){
		if(!$(this).hasClass("disabled")) {
			$(this).addClass("hover").css({"cursor":"pointer"});
		}
	},function(){
		$(this).removeClass("hover").css({"cursor":"default"});
	})
}


/**
 * animate page to a #elementid
 */
function inPageLinksScrollTo() {
	$(".scrollTo").click(function(){
		var href 	= $(this).attr("href");
		var	target	= $(href);
		if(target.size()>0) {
			var offset 	= target.offset()
			$('html,body').animate({scrollTop:offset.top},1000)
			return false;
		} else {
			return true;
		}
	})
}



/**	
 * Target new windows
 */
function newWindowLinks(){
	$('a[rel=external],a.pop').live("click",function(){
		window.open($(this).attr('href'));
		return false;
	});
}



