

CSSHandler = function () {

}

/**
 * Reads set CSS Values of property in element
 * FF and IE, others not tested
 *
 * @param OBJECT element
 * @param STRING property
 * @param STRING type (int(Math.round)|float|string)
 * @return STRING Value of Property
 */
CSSHandler.prototype.getCSSValue = function(element, property, type) {
    if (typeof(window.getComputedStyle) == 'function') {
        var value = window.getComputedStyle(element, null)[property];
    } else if (element.currentStyle) {
        var value = element.currentStyle[property];
    } else {
        return false;
    }
    switch (type) {
        case 'int':
            value = Math.round(parseFloat(value));
            break;
        case 'float':
            value = parseFloat(value);
            break;
        case 'string':
        default:
        break;
    }
    return value;
}

/*
 
progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://develop.bayern-tourist.info/images/bildergalerie/back.png",sizingMethod="scale") progid:DXImageTransform.Microsoft.Alpha(opacity:0);

*/

/**
 * Sets the opacity Crossbrowser
 *
 * @param OBJECT element
 * @param FLOAT opacity
 *
 * 
 */
CSSHandler.prototype.setOpacity = function (element, opacity) {
    opacity = opacity > 1 ? 1 : opacity < 0 ? 0 : opacity;
    if (userAgent.app=='MSIE') {
        if (element.style.filter.match(/Alpha\(opacity/)) {
            element.style.filter = element.style.filter.replace(/Alpha\(opacity:[^\)]*/, 'Alpha(opacity:'+(Math.round(opacity*100)))
        } else if (element.style.filter.indexOf('progid:') > -1) {
            element.style.filter +=' DXImageTransform.Microsoft.Alpha(opacity:'+(Math.round(opacity*100))+');';
        } else {
            element.style.filter ='progid:DXImageTransform.Microsoft.Alpha(opacity:'+(Math.round(opacity*100))+');';
        }
    } else {
        element.style.opacity = opacity;
    }
}
/**
 * Returns the opacity Crossbrowser
 *
 * @param OBJECT element
 */
CSSHandler.prototype.getOpacity = function (element) {
    if (userAgent.app=='MSIE') {
        /Alpha\(opacity:([0-9]{1,3})\)/.test(this.getCSSValue(element,'filter'));
        var opacity = RegExp.$1 / 100;
    } else {
        var opacity = parseFloat(this.getCSSValue(element,'opacity'));
    }
    return opacity;
}

/**
 * unset clip Crossbrowser
 */
CSSHandler.prototype.unclip = function (element) {
    if (userAgent.app=='MSIE' && userAgent.version < 8) {
        element.style.clip = 'rect(auto)';
    } else {
        element.style.clip = 'auto';
    }
}

window.cssHandler = new CSSHandler();