/***************************************************************\
| |\  /|                                                We Put  |
| | >< Hypercosm           ie_png_fix.js                3d      |
| |/  \|                                                To Work |
|***************************************************************|
|                                                               |
|        This file contains some javascript utilities that      |
|        are used to work with the web browser.                 |
|                                                               |
|***************************************************************|
|                Copyright (c) 2008 Hypercosm, LLC.             |
\***************************************************************/


//
// correctly handle PNG transparency in Win IE 5.5 & 6.
//


var isIe = (navigator.appName == "Microsoft Internet Explorer");
var ieVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);
var useCorrectedPNGFix = isIe && (ieVersion >= 5.5) && (ieVersion < 7);
var correctingPNGImages = false;
var correctedPNGImages = false;


function correctPNG(img) {
  if (!useCorrectedPNGFix)
    return;

  var imgName = img.src.toUpperCase();
  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
    var imgID = (img.id) ? "id='" + img.id + "' " : "";
    var imgClass = (img.className) ? "class='" + img.className + "' " : "";
    var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
    var imgStyle = "display:inline-block;" + img.style.cssText;

    if (img.align == "left") imgStyle = "float:left;" + imgStyle;
    if (img.align == "right") imgStyle = "float:right;" + imgStyle;
    if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;

    var width = img.width;
    var height = img.height;

    // get width and height of invisible elements
    //
    if (width == 0)
      width = getElementAttribute(img, "width");
    if (height == 0)
      height = getElementAttribute(img, "height");

    var HTML = "<span " + imgID + imgClass + imgTitle
      + " style=\"" + "width:" + width + "px; height:" + height + "px;" + imgStyle + ";"
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
      + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>";
          
    img.outerHTML = HTML;
  }
}    // correctPNG


function correctPNGs() {
  if (!useCorrectedPNGFix)
    return;

  if (!correctingPNGImages) {
    correctingPNGImages = true;

    for (var i = 0; i < document.images.length; i++)
      correctPNG(document.images[i]);  

    correctedPNGImages = true;
  }
}  // correctPNGs


function swapPNG(image, src) {
  if (useCorrectedPNGFix)
    image.filters(0).src = src;
  else
    image.src = src;
}    // swapPNG