$.fn.clearField = function(){
	return this.focus(function() {
		if( this.value == this.defaultValue){
			this.value = "";
		}
	}).blur(function(){
		if( !this.value.length){
			this.value = this.defaultValue;
		}
	});
};

$(document).ready(function(){
	// add class to links depending on extension
	//$("a[@href$=pdf]").addClass("pdf");
	$("a[@href$=pdf]").parent().addClass("pdf");
	$("a[@href$=zip]").addClass("zip");
	$("a[@href$=doc]").addClass("doc");
	$("a[@href$=xls]").addClass("xls");
	$("a[@href$=psd]").addClass("psd");
	
	$("#nav ul").superfish({ 
		delay:			1,	// one second delay on mouseout 
		animation:		{opacity:'show',height:'show'}, // fade-in and slide-down animation 
		speed:			'fast', // faster animation speed 
		autoArrows:		false, // disable generation of arrow mark-up 
		dropShadows:	false // disable drop shadows 
	});
	
	// automatically create external link class and open in new window if link is not local or ID anchor
	$("a[@href^='http']").not("[@href*=http://powerchex.dev.pepperdigital.com]").not("[@href*=http://www.powerchex.co.uk]").not("[@href*=http://powerchex.co.uk]").not("[href^=#]").addClass("external").attr('target','_blank');

	//Do the business on all input fields (text defaults)
	$("input").clearField();

	// ie png replacement
	if(navigator.appVersion.match(/MSIE [0-6]\./)){
		$('img[@src*=".png"]').addClass('png');
		$('input[@src*=".png"]').addClass('png');
		$('*').each(function(){
			if(this.currentStyle.backgroundImage != 'none' && this.currentStyle.backgroundImage.match(/\.png/)){
				var image = this.currentStyle.backgroundImage;
				image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
				$(this).css({
					'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=image, src='" + image + "')"
				});
			}
		});
	}
});