$(document).ready(function(){
	
	// Fix IE6 PNG support using jQuery supersleight plugin
	$('h1').supersleight({shim: '/img/transparent.gif'});
	
	// Initialise Superfish dropdown menus
	$('ul.sf-menu').superfish({ 
        delay: 0,							// no delay on mouseout
        animation:   {height:'show'},
		speed: 'fast',
        autoArrows: false,					// disable generation of arrow mark-up 
        dropShadows: false					// disable drop shadows 
	});
    
    // Removes input field default text on focus, replaces it on blur
	$('input[type="text"]').focus(function() {  
		if (this.value == this.defaultValue){  
			this.value = '';  
		}  
		if(this.value != this.defaultValue){  
			this.select();  
		}  
	});  
	$('input[type="text"]').blur(function() {  
		if ($.trim(this.value) == ''){  
			this.value = (this.defaultValue ? this.defaultValue : '');  
		}  
	});
	
	// Defuscate any hrefs in format you(replace+with+at+symbol)domain.com. Replaces the mailto and the link text.
	// Note that emails are being encrypted in the CMS via the cleanup_rich_text function
	$('p').defuscate({link: true});
    
    // Any links with rel="external" attribute will open in new window
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
 });

/* Popup windows
 *********************************************/
var newWindow = null;
function popup(theURL, winName, features) { 
	closePopup(winName);
	newWindow=window.open(theURL,winName,features);
	newWindow.focus();
}
function closePopup(winName) {
	if (newWindow && newWindow.open && !newWindow.closed) newWindow.close();
}


/* IE6: Turn on image caching
 * Stops image flicker on rollovers
 *********************************************/
(function(){
	/*Use Object Detection to detect IE6*/
	var m = document.uniqueID /*IE*/ 
	&& document.compatMode /*>=IE6*/ 
	&& !window.XMLHttpRequest /*<=IE6*/ 
	&& document.execCommand ; 
	try{ 
		if(!!m){ 
			m("BackgroundImageCache", false, true) /* = IE6 only */ 
		} 
	}catch(oh){}; 
})(); 