// Global helper functions for enhanced page display

$(document).ready(function(){
						   
// adds class of 'active' to navigation link relating to the current page - relies on class of body tag matching id of link
$('ul#navigation a').each(function(i){	
	var page = 	window.location.pathname.split("/")[1];
	var href = $(this).attr('href').substring(window.location.protocol.concat("//", window.location.hostname).length).split("/")[1] || "";
	if(page === href){
	$(this).addClass('active');
	}
})
/* ==================================================================================================================================================*/
// adds hover functionality to form submit buttons by adding 'hover' class on mouse over
$("input[type='submit']").hover(function(){$(this).addClass('hover')}, function(){$(this).removeClass('hover')})
/* ==================================================================================================================================================*/
// handles the automatic clearing and populating of default values on focus and blur for text fields
$("input[type='text'], textarea").bind('focus', onTextFieldFocusHandler);
$("input[type='text'], textarea").bind('blur', onTextFieldBlurHandler);
$("input[type='text'], textarea").triggerHandler('blur');

function onTextFieldFocusHandler(evt){
	switch(this.tagName){
		case 'INPUT':
		if(this.value == this.defaultValue){$(this).val(''); $(this).removeClass('isDefault');}
		break;
		case 'TEXTAREA':
		if($.browser.msie){
			if($(this).text() == this.defaultValue){$(this).text(''); $(this).removeClass('isDefault');}
		}else{
			if(this.value == this.defaultValue){$(this).val(''); $(this).removeClass('isDefault');}	
		}
		break;
	}
}

function onTextFieldBlurHandler(evt){
	switch(this.tagName){
		case 'INPUT':
		if(this.value == ''){$(this).val(this.defaultValue); $(this).addClass('isDefault');}
		break;
		case 'TEXTAREA':
		if($.browser.msie){
			if($(this).text() == ''){$(this).text(this.defaultValue); $(this).addClass('isDefault');}
		}else{
			if(this.value == ''){$(this).val(this.defaultValue); $(this).addClass('isDefault');}	
		}
		break;
	}
}
/* ==================================================================================================================================================*/
// Applies the pngFix plugin to the document if it exists
if(typeof($(document).pngFix() && ($.browser.msie && $.browser.version < 7)) == 'function')$(document).pngFix();

});
