/**************************\
  GSSI Environment script
\**************************/

if (! GSSI) { var GSSI = new Object; };
if (! GSSI.Environment ) { GSSI.Environment = new Object(); };

GSSI.Environment.Agent = navigator.userAgent.toLowerCase();

GSSI.Environment.Browser = {  /* Browser sniffing based on Prototype's */
	IE:     !!(window.attachEvent && !window.opera),
	Opera:  !!window.opera,
	WebKit: GSSI.Environment.Agent.indexOf('applewebkit/') > -1,
	Gecko:  GSSI.Environment.Agent.indexOf('gecko') > -1 &&
			GSSI.Environment.Agent.indexOf('khtml') == -1
};

GSSI.Environment.Browser.IE6 = GSSI.Environment.Browser.IE && (GSSI.Environment.Agent.indexOf("msie 6")!=-1);
GSSI.Environment.Browser.IE7 = GSSI.Environment.Browser.IE && (GSSI.Environment.Agent.indexOf("msie 7")!=-1);

GSSI.Environment.OS = {
	Windows: GSSI.Environment.Agent.indexOf("win") != -1,
	Win2K:   GSSI.Environment.Agent.indexOf("windows nt 5.0") != -1,
	WinXP:   GSSI.Environment.Agent.indexOf("windows nt 5.1") != -1,
	Vista:   GSSI.Environment.Agent.indexOf("windows nt 6.0") != -1,
	Mac:     GSSI.Environment.Agent.indexOf("mac") != -1
};



GSSI.Environment.addClass = function ( node, name ){
	if(node) node.className = ((node.className || '') == '' ? '' : node.className + ' ') + name;
}

GSSI.Environment.withDOM = function () {
	try {
		if ( GSSI.Environment.Browser.IE ) {
			GSSI.Environment.addClass( document.body, "ie" );
			if ( GSSI.Environment.Browser.IE6 ) {
				GSSI.Environment.addClass( document.body, "ie6" );
			} else if ( GSSI.Environment.Browser.IE7 ) {
				GSSI.Environment.addClass( document.body, "ie7" );
			}
		} else if ( GSSI.Environment.Browser.Gecko ) {
			GSSI.Environment.addClass( document.body, "gecko" );
		} else if ( GSSI.Environment.Browser.WebKit ) {
			GSSI.Environment.addClass( document.body, "webkit" );
		} else if ( GSSI.Environment.Browser.Opera ) {
			GSSI.Environment.addClass( document.body, "opera" );
		}
	
		if ( GSSI.Environment.OS.Windows ) {
			GSSI.Environment.addClass( document.documentElement, "win" );
			if ( GSSI.Environment.OS.WinXP ) {
				GSSI.Environment.addClass( document.documentElement, "winxp" );
			} else if ( GSSI.Environment.OS.Win2K ) {
				GSSI.Environment.addClass( document.documentElement, "win2k" );
			} else if ( GSSI.Environment.OS.Vista ) {
				GSSI.Environment.addClass( document.documentElement, "vista" );
			}
		} else if ( GSSI.Environment.OS.Mac ) {
			GSSI.Environment.addClass( document.documentElement, "mac" );
		}
	} catch (e) {}
};






do {
	/* Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		if ( window.location.protocol != "https:" ) {
			document.write("<sc" + "ript id='__ie_gssi_observeDOMReady' defer='defer' src='javascript:void(0);'><\/sc" + "ript>");
			GSSI.Environment.DOMReadyBrowserDevice = document.getElementById("__ie_gssi_observeDOMReady");
			GSSI.Environment.DOMReadyBrowserDevice.onreadystatechange = function() {
				if (this.readyState == "complete") {
					GSSI.Environment.withDOM(); // call the onload handler
				}
			};
			break;
		}
	/*@end @*/
	
	/* Safari/Konqueror */
	/* WebKit must be tested for before DOM2 standard because WebKit supports document.addEventListener but NOT the 
	   DOMContentLoaded event. */
	if (/WebKit/i.test(navigator.userAgent)) { 
		Event.DOMReadyBrowserDevice = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(Event.DOMReadyBrowserDevice);
				GSSI.Environment.withDOM(); 
			}
		}, 10);
		break;
	}
	
	/* Mozilla/Opera9/DOM2 Compliant browsers */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", GSSI.Environment.withDOM, false);
		break;
	}

	/* Anything else */
	if (window.addEventListener) {
		window.addEventListener("load", GSSI.Environment.withDOM, false);
	} else if(window.attachEvent) {
		window.attachEvent("onload", GSSI.Environment.withDOM);
	}

} while(0);
