/**	
	@author			nathaniel skulic <nate@skulic.name>
	@copyright 		Copyright 2007, Nathaniel Skulic. All Rights Reserved.
	@fileOverview	
*/

window.xpath = !!(document.evaluate);
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.khtml = window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;
else if (document.getBoxObjectFor != null) window.gecko = true;

/* Copyright (c) 2007 Nate Skulic. All rights reserved. */

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();
	

/* 
Trident 	Internet Explorer
Tasman 	Internet Explorer for Mac
Gecko 	All Mozilla software, including Firefox; Galeon; Flock
WebKit 	Safari; iCab 4; Epiphany;
KHTML 	KDE
Presto 	Opera; Nintendo DS Browser; Internet Channel
iCab 	iCab 1-3
Prince XML 	Prince XML
*/

oil.browser = {
	is_ie:false,
	engine: {name: 'unknown', version:'unknown'},
	platform: {
		name: (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()
	},
	features: {
		xhr: (Boolean)(window.XMLHttpRequest),
		xpath: (Boolean)(document.evaluate), 
		air: (Boolean)(window.runtime)
	},
	initialize: function(){
	}
};


if (window.opera) 
	oil.browser.engine = {name: 'presto', version: (document.getElementsByClassName) ? 950 : 925};
else if(window.ActiveXObject) {
	oil.browser.engine = {name: 'trident', version: (oil.browser.features.xhr) ? 5 : 4};
	// IE=0//@cc_on+1
	// var jscript = NaN/*@cc_on||@_jscript_version@*/; // http://dean.edwards.name/weblog/2007/03/sniff/#comment85164
	// var java = _.java ? true : false;
	/* 
	var IEVersion = 0 /*@cc_on+ScriptEngineMajorVersion()@*/;
	oil.browser.engine.jscript = NaN/*@cc_on||@_jscript_version@*/;
	
	if (oil.browser.engine.jscript) oil.browser.engine.version = 4;
	if (oil.browser.engine.jscript >= 5.5) oil.browser.engine.version = 5.5; // IE 5.5 +
	if (oil.browser.engine.jscript == 5.7) oil.browser.engine.version = 7; // IE 7.0 Vista */
	
	oil.browser.is_ie = true;
}
else if (!navigator.taintEnabled) 
	oil.browser.engine = {name: 'webkit', version: (oil.browser.features.xpath) ? 420 : 419};
else if (document.getBoxObjectFor != null) 
	oil.browser.engine = {name: 'gecko', version: (document.getElementsByClassName) ? 19 : 18};

oil.browser.engine.strict = (document.compatMode == "CSS1Compat");
oil.browser.engine[oil.browser.engine.name] = oil.browser.engine[oil.browser.engine.name + oil.browser.engine.version] = true;
oil.browser.platform[oil.browser.platform.name] = true;

/* 

Script: Browser.js
        The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.

License:
        MIT-style license.


function $exec(text){
        if (!text) return text;
        if (window.execScript){
                window.execScript(text);
        } else {
                var script = document.createElement('script');
                script.setAttribute('type', 'text/javascript');
                script.text = text;
                document.head.appendChild(script);
                document.head.removeChild(script);
        }
        return text;
};

Native.UID = 1;

var $uid = (oil.browser.engine.trident) ? function(item){
        return (item.uid || (item.uid = [Native.UID++]))[0];
} : function(item){
        return item.uid || (item.uid = Native.UID++);
};

var Window = new Native({

        name: 'Window',

        legacy: window.Window,

        initialize: function(win){
                $uid(win);
                if (!win.Element){
                        win.Element = $empty;
                        if (oil.browser.engine.webkit) win.document.createElement("iframe"); //fixes safari 2
                        win.Element.prototype = (oil.browser.engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
                }
                return $extend(win, Window.Prototype);
        },

        afterImplement: function(property, value){
                window[property] = Window.Prototype[property] = value;
        }

});

Window.Prototype = {$family: {name: 'window'}};

new Window(window);

var Document = new Native({

        name: 'Document',

        legacy: window.Document,

        initialize: function(doc){
                $uid(doc);
                doc.head = doc.getElementsByTagName('head')[0];
                doc.html = doc.getElementsByTagName('html')[0];
                doc.window = doc.defaultView || doc.parentWindow;
                if (oil.browser.engine.trident4) $try(function(){
                        doc.execCommand("BackgroundImageCache", false, true);
                });
                return $extend(doc, Document.Prototype);
        },

        afterImplement: function(property, value){
                document[property] = Document.Prototype[property] = value;
        }

});

Document.Prototype = {$family: {name: 'document'}};

new Document(document);



*/
