$(document).ready(function(){
	// add class to links depending on extension
	$("a[@href$=pdf]").addClass("pdf").attr('target','_blank');
	$("a[@href$=zip]").addClass("zip");
	$("a[@href$=doc]").addClass("doc");
	$("a[@href$=xls]").addClass("xls");
	$("a[@href$=psd]").addClass("psd");

	$("a[@href^='http']").not("[@href*=http://www.morganlovell.co.uk]").not("[@href*=http://staging.morganlovell.com]").not("[@href*=http://ml.dev.pepperdigital.com]").not("[href^=#]").addClass("external").attr('target','_blank');

	//$(document).pngFix();

	$("#nav_primary").superfish({
		delay:0,
		speed:'fast',
		autoArrows:false,
		dropShadows:false
	}); 

	$('#header_home').flash(
		{
			src: '/interface/flash/homepage_v2.swf',
			width: 960,
			height: 355,
			wmode: "opaque"
		},
		{
			version: '9'
		}
	);
	$('#gallery_flash').flash(
		{
			src: '/interface/flash/gallery.swf',
			width: 740,
			height: 437,
			wmode: "opaque"
		},
		{
			version: '9'
		}
	);

	$('#footer .callout .bg').hover(function(){
		$(this).find('img.img_top').fadeTo("slow", 0.0);
	},
	function(){
		$(this).find('img.img_top').fadeTo("slow", 1);
	});

	$("input").clearField();

	$('ul#nav_primary li').hover(function(){
		$(this).find('a:first').addClass('hover');
	},
	function(){
		$(this).find('a:first').removeClass('hover');
	});

	$('#case-study-filter').removeClass('hide');

	$("#filter-style").change(function(){
		window.location = $("#filter-style").val(); 
	});
	$("#filter-industry").change(function(){
		window.location = $("#filter-industry").val(); 
	});
	$("#filter-client").change(function(){
		window.location = $("#filter-client").val(); 
	});
});

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