
var ua = navigator.userAgent.toLowerCase();

var isStrict = document.compatMode == "CSS1Compat",
    isOpera = ua.indexOf("opera") > -1,
    isSafari = (/webkit|khtml/).test(ua),
    isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
    isIE = !isOpera && ua.indexOf("msie") > -1,
    isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
    isGecko = !isSafari && ua.indexOf("gecko") > -1,
    isGecko3 = !isSafari && ua.indexOf("rv:1.9") > -1,
    isBorderBox = isIE && !isStrict,
    isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
    isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
    isAir = (ua.indexOf("adobeair") != -1),
    isLinux = (ua.indexOf("linux") != -1),
    isSecure = window.location.href.toLowerCase().indexOf("https") === 0;

Framework = {
	
	/**
	 * True if the application is ready and the OnReady function has been fired
	 * @type Boolean
	 */	
	isReady : false,
	
	/**
	 * True if the browser is in strict mode
	 * @type Boolean
	 */
	isStrict : isStrict,
	
	/**
	 * True if the page is running over SSL
	 * @type Boolean
	 */
	isSecure : isSecure,	
	
	/**
	 * True if the detected browser is Opera.
	 * @type Boolean
	 */
	isOpera : isOpera,
	
	/**
	 * True if the detected browser is Safari.
	 * @type Boolean
	 */
	isSafari : isSafari,
	
	/**
	 * True if the detected browser is Safari 3.x.
	 * @type Boolean
	 */
	isSafari3 : isSafari3,
	
	/**
	 * True if the detected browser is Safari 2.x.
	 * @type Boolean
	 */
	isSafari2 : isSafari && !isSafari3,
	
	/**
	 * True if the detected browser is Internet Explorer.
	 * @type Boolean
	 */
	isIE : isIE,
	
	/**
	 * True if the detected browser is Internet Explorer 6.x.
	 * @type Boolean
	 */
	isIE6 : isIE && !isIE7,
	
	/**
	 * True if the detected browser is Internet Explorer 7.x.
	 * @type Boolean
	 */
	isIE7 : isIE7,
	
	/**
	 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
	 * @type Boolean
	 */
	isGecko : isGecko,
	
	/**
	 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
	 * @type Boolean
	 */
	isGecko2 : isGecko && !isGecko3,
	
	/**
	 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
	 * @type Boolean
	 */
	isGecko3 : isGecko3,
	
	/**
	 * True if the detected browser is Internet Explorer running in non-strict mode.
	 * @type Boolean
	 */
	isBorderBox : isBorderBox,
	
	/**
	 * True if the detected platform is Linux.
	 * @type Boolean
	 */
	isLinux : isLinux,
	
	/**
	 * True if the detected platform is Windows.
	 * @type Boolean
	 */
	isWindows : isWindows,
	
	/**
	 * True if the detected platform is Mac OS.
	 * @type Boolean
	 */
	isMac : isMac,
	
	/**
	 * True if the detected platform is Adobe Air.
	 * @type Boolean
	 */
	isAir : isAir,
	
	docReadyProcId : null,
	
	/**
	 *
	 *
	 */
	onReady : function() {
		// Execute only once
		if (Framework.isReady) {
			return;
		} 
		
		// Set is ready
		Framework.isReady = true;
		
		// Delete event listener
		if (Framework.isGecko || Framework.isOpera) {
			document.removeEventListener("DOMContentLoaded", Framework.onReady, false);
		}
		
		// Remove interval
		if (Framework.docReadyProcId){
			clearInterval(Framework.docReadyProcId);
			Framework.docReadyProcId = null;
		}	
		
		// Set styles
		var bd = document.body || document.getElementsByTagName('body')[0];
        if(!bd){ return false; }
        var cls = [' ',
                Framework.isIE ? "framework-ie " + (Framework.isIE6 ? 'framework-ie6' : 'framework-ie7')
                : Framework.isGecko ? "framework-gecko " + (Framework.isGecko2 ? 'framework-gecko2' : 'framework-gecko3')
                : Framework.isOpera ? "framework-opera"
                : Framework.isSafari ? "framework-safari" : ""];

        if(Framework.isMac){
            cls.push("framework-mac");
        }
        if(Framework.isLinux){
            cls.push("framework-linux");
        }
        if(Framework.isBorderBox){
            cls.push('framework-border-box');
        }
        if(Framework.isStrict){             
        	var p = bd.parentNode;
            if(p){
                p.className += ' framework-strict';
            }
        }
        bd.className += cls.join(' ');
	},

	/**
	 *
	 *
	 */	
	initOnReady : function () {
		// Try to fire the onReady function
		if( Framework.isGecko || Framework.isOpera) {
		    document.addEventListener('DOMContentLoaded', Framework.onReady, false);
		} else if (Framework.isIE){
		    Framework.docReadyProcId = setInterval(function(){
		        try{
		            // throws errors until DOM is ready
		            Framework.isReady || (document.documentElement.doScroll('left'));
		        }catch(e){
		            return;
		        }
		        Framework.onReady();  // no errors, fire
		    }, 5);
		
			document.onreadystatechange = function(){
				if(document.readyState == 'complete'){
					document.onreadystatechange = null;
					Framework.onReady();
				}
		    };
		} else if (Framework.isSafari){
		    Framework.docReadyProcId = setInterval(function(){
		        var rs = document.readyState;
		        if(rs == 'complete') {
		            Framework.onReady();
		         }
		    }, 10);
		}
	}
}

Framework.initOnReady();