$(document).ready(function(){
	
	// 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;
    });
    
    // Because our lightbox title attributes might include HTML tags, the title tooltips look naf.
    // To overcome this we will change the title attr on mouseover, and reinstate it on mousedown.
    $('.imageGallery a').mouseover( function() {
    	// Temporarily store title in element's data object.
    	elem = $(this);
    	if ($(this).data('title')==undefined || $(this).data('title')==null){	
    		$(this).data('title', elem.attr('title'));
    	}
    	$(this).attr('title', 'Enlarge image');
    });
    $('.imageGallery a').mousedown( function() {
    	// If we previously stored the title, reinstate it.
    	if ($(this).data('title')!=undefined && $(this).data('title')!=null){
    		$(this).attr('title', $(this).data('title'));
    	}
    });
	
 });

/* 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){}; 
})(); 

/*
=========
BASIC FUNCTIONS
=========
*/
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();
}

