/**
 * @description utilities for solving ie6 png bugs
 * @namespace
 */
var png = 
{
  /**
   * @description <p>ie6 png hack</p>
   * after page loaded changes all png background images into filters in ie6
   * @see png.hackElement
   */
  hackEntire: function()
  {
    if ( YAHOO.env.ua.ie != 6 )
    {
      return false;
    }
    var elements_to_hack = YAHOO.util.Dom.getElementsByClassName( "xc_transparent_png" );
  
    for( i=0; i < elements_to_hack.length; i++ )
    {
      var act_el = elements_to_hack[i];
      this.hackElement( act_el );
    }
    
    return true;
  },
  /**
   * @description hacks an element only 
   * @param {HTMLelement} el the element to hack 
   */
  hackElement: function( el )
  {
    if ( YAHOO.env.ua.ie != 6 )
    {
      return false;
    }
    
    var value = YAHOO.util.Dom.getStyle( el, "background-image" );
    if ( value.indexOf( "png" ) == -1 )
    {
      return false;
    }
  
    var first_colon = value.indexOf( "\"" );
    var last_colon = value.lastIndexOf( "\"" );
    var raw_value = value.substr( first_colon+1, last_colon-first_colon-1 );
    el.style.backgroundImage = "none";
    el.style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + raw_value + "', sizingMethod='crop');";
    
    return true;
  },
  /**
   * @description reset background image after changing class for the element
   * @param {Object} el
   */
  reSetFilter: function( el )
  {
    if ( !ie6 )
    {
      return true;
    }
    
    if ( YAHOO.lang.isArray( el ) )
    {
      for ( i_el = 0; i_el < el.length; i_el++ )
      {
        var act_el = el[ i_el ];
        png.reSetFilter( act_el );
      }
      return true;
    }
    
    if ( !el )
    {
      return false;
    }
    el.style.filter = "";
    el.style.backgroundImage = "";
    var orig_image = YAHOO.util.Dom.getStyle( el, "background-image" );
    var first_colon = orig_image.indexOf("\"");
    var last_colon = orig_image.lastIndexOf("\"");
    var raw_value = orig_image.substr(first_colon+1, last_colon-first_colon-1);
    el.style.backgroundImage = "none";
    el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + raw_value + "', sizingMethod='crop');";
    return true;
  }
}

YAHOO.util.Event.onDOMReady(function()
{
  png.hackEntire();
})