/**
 * enable semi-transparent PNG graphics for IE6 and IE5.5
 *
 * @author: Andreas Demmer <mail@andreas-demmer.de>
 */

/**
 * detected browser
 */
var browser;

/**
 * detected browser version
 */
var browserVersion;

/**
 * is detected browser an Internet Exploder
 */
var isIE;

/**
 * detect browser and version
 */
browserDetection = function () {
    browser = navigator.userAgent.toLowerCase();
    browserVersion = parseFloat( browser.substring( browser.indexOf('msie ') + 5 ) );
    isIE = ( (browser.indexOf("msie") != -1) && (browser.indexOf("opera") == -1) && (browser.indexOf("webtv") == -1));
}

/**
 * document ready function
 */
pngfix = function() {
    if(!isIE){return}
    if(browserVersion >= 7) {return}
    var canBeFixed = (browserVersion >= 5.5);
    var BackgroundImage = $(this).css('background-image');
    var isBackgroundImage = false;

    if(BackgroundImage != 'none'){
        isBackgroundImage = true;

        PngUrl = BackgroundImage.replace('url\(\'', '');
        PngUrl = PngUrl.replace('url\("', '');
        PngUrl = PngUrl.replace('\')', '');
        PngUrl = PngUrl.replace('")', '');
    }else{
        PngUrl = $(this).attr('src');
    }

    if(canBeFixed){
        $(this).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+PngUrl+"', sizingMethod='crop')");

        if (!isBackgroundImage) {
            $(this).attr('src', "resources/images/blank.gif");
        } else {
            $(this).css('background-image', 'none');
        }
    }
}

/**
 * processes PNG files with Microsoft filter, only on Internet Explorer 6
 */
fixIE6alphaTransparency = function () {
    if (isIE && browserVersion == 6) {
        $('.fixIe').each(pngfix);
    }
}