//---------------------------------------------------------------------
// ibrows.js - browser compatibility layer
//   by Satoshi Nakajima (copyright 2007)
//   version 0.10 (Nov. 21th, 2007)
//
// [Usage]
// 1. Free to use for either commercial or non-commercial
// 2. Feedback is welcome
// 3. I recommand to use this file as-is. If you stil want to modify, please
//   Keep this section as-is
//   Change the name by appending your identity (e.g., "ibrows010Joe.js")
//   Clearly indicate that it's modified from the original version.
//---------------------------------------------------------------------
var iBrowse = function() {
};

(function(){
    var ua = navigator.userAgent.toLowerCase();
    var env = {
        userAgent:  ua,
        webkit:     /webkit/.test(ua),
        opera:      /opera/.test(ua),
        compatible: /compatible/.test(ua),
        msie:       /msie/.test(ua),
        mozilla:    /mozilla/.test(ua)
    };
    env.msie = env.msie && !env.opera;
    env.mozilla  = env.mozilla && !(env.compatible || env.webkit);
    iBrowse.env = env;
})();

iBrowse.setOpacity = function(obj, a) {
    obj.style.opacity = a;
};

iBrowse.getWindowWidth = function() {
    return window.innerWidth;
};

iBrowse.getWindowHeight = function() {
    return window.innerHeight;
};

iBrowse.setText = function(obj, text) {
    obj.innerText = text;
};

//================================
// Compatibility layer for FireFox
//================================

iBrowse.setTextFF = function(obj, text) {
    obj.textContent = text;
};

(function(){
    if (iBrowse.env.mozilla) {
        iBrowse.setText = iBrowse.setTextFF;
    }
})();

//================================
// Compatibility layer for MSIE
//================================
iBrowse.setOpacityIE = function(obj, a) {
    obj.style.filter = 'alpha(opacity=' + a*100 + ')';
};

iBrowse.getWindowWidthIE = function() {
    return document.body.clientWidth;
};

iBrowse.getWindowHeightIE = function() {
    return document.body.clientHeight;
};

(function(){
    if (iBrowse.env.msie) {
        iBrowse.setOpacity = iBrowse.setOpacityIE;
        iBrowse.getWindowWidth = iBrowse.getWindowWidthIE;
        iBrowse.getWindowHeight = iBrowse.getWindowHeightIE;
    }
})();
