$.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$=zip]").addClass("zip");
	$("a[@href$=doc]").addClass("doc");
	$("a[@href$=xls]").addClass("xls");
	$("a[@href$=psd]").addClass("psd");
	
	// automatically create external link class and open in new window if link is not local or ID anchor
	$("a[@href^='http']").not("[@href*=http://www.alicepalace.co.uk]").not("[@href*=http://alicepalace.co.uk]").not("[href^=#]").addClass("external").attr('target','_blank');

	$("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 + "')"
				});
			}
		});
	}
});