$.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("external").attr('target','_blank');
	
	// add class to links with rel="external"
	$('a[rel="external"]').addClass("external").attr('target','_blank');

	// automatically create external link class and open in new window if link is not local or ID anchor
	$("a[@href^='http']").not("[@href*=http://193.118.96.50]").not("[@href*=http://www.deloitte.com]").not("[@href*=http://annualreport.deloitte.co.uk]").not("[href^=#]").addClass("external").attr('target','_blank');


	$("#siteselectorlist select").bind("change", function(){
		//alert($(this).fieldValue());
		if($(this).fieldValue() != 'Global Site Selector'){
			window.location = $(this).fieldValue();
		}
	});

	$('#textsize a#textchange').click(function(){
		if($("#textsizer").css("display")=="block"){
			$("#textsizer").css("display","none");
		}
		else{
			$("#textsizer").css("display","block");
		}
		return false;
	});
	$('#textsizer a').click(function(){
		var theElement = $("body").css("font-size");
		var textSize = parseInt(theElement, 10);
		var unitOfMeasurement = theElement.slice(-2);

		if ((this).id == "font_inc"){
			textSize += 1;
		}
		else{
			textSize -= 1;
		}; 
		$('body').css("font-size", textSize + unitOfMeasurement);
		return false;
	});
	
	$(document).pngFix();

	$('#home #flash_header').flash({
		src: '/fast50/interface/flash/fast50-homepage-panel.swf',
		width: 520,
		height: 295
	},	
	{version: 8});
	$('#find_out_more #flash_header').flash({
		src: '/fast50/interface/flash/fast50-homepage-panel.swf',
		width: 520,
		height: 295
	},	
	{version: 8});
	$('#apply_now #flash_header').flash({
		src: '/fast50/interface/flash/applynow-header.swf',
		width: 520,
		height: 195
	},	
	{version: 8});
	$('#winners #flash_header').flash({
		src: '/fast50/interface/flash/winners-header.swf',
		width: 520,
		height: 195
	},	
	{version: 8});
	$('#regional_ranking_2008 .flash_map').flash({
		src: '/fast50/interface/flash/map-panel.swf',
		width: 395,
		height: 360,
		wmode: "opaque"
	},	
	{version: 8});
});