
// define an object to hold some utility functions

jQuery.Utils = {};





// for each element matching supplied selector, substitute the commented image for the default text
// setup e.g. <h1>Welcome<!--<img src="welcome.gif" alt="Welcome" />--></h1>

jQuery.Utils.insertImageAlternative = function(selector) {

var reg_exp = /^(.*)<!--(.*)-->$/;

jQuery(selector).each(

   function(i)
   {
   html = jQuery(this).html();

      if (match_array = reg_exp.exec(html))
      {

         if (match_array.length) jQuery(this).html(match_array[2]);

      }

   }

);

};





// for each element matching supplied selector, alter target attribute so link opens in new browser window

jQuery.Utils.openLinkInNewWindow = function(selector) {

jQuery(selector).each(

   function(i)
   {
   jQuery(this).attr('target', '_blank');
   }

);

};





// for each element matching supplied selector, alter behaviour so link opens in a popup window

jQuery.Utils.openLinkInPopupWindow = function(selector, width, height) {

   if (width == undefined)
   {
      width = (screen && screen.width) ? screen.width: 1024;
   }

   if (height == undefined)
   {
      height = (screen && screen.height) ? screen.height: 768;
   }

jQuery(selector).bind('click', 

   function(i)
   {
   href = jQuery(this).attr('href');
   window.open(href, '', 'toolbar=0,resizable=1,scrollbars=1,width=' + width + ',height=' + height);
   return false;
   }

);

};





// for each element matching supplied selector, apply transparency fix for png images in ie 6 

jQuery.Utils.fixPNGTransparency = function(selector) {

jQuery(selector).each( 

   function(i)
   {

      if (!document.body.filters) return; // return if not Internet Explorer
      if (!jQuery.browser.msie) return; // return if not Internet Explorer
      if (jQuery.browser.version > 6) return; // return if not Internet Explorer 6 and below

   src = jQuery(this).attr('src');
   width = jQuery(this).attr('width');
   height = jQuery(this).attr('height');

   filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='" + src + "')";

   jQuery(this).css({filter:filter, width:width, height:height});
   jQuery(this).attr({src:'images/pixel.gif'});
   }

);

};
