/*******************************************************************************/
/* CROSS BROWSER CODING OBJECT ********************************************/
/* (c) Homenet Inc 2009 **********************************************************/
/*******************************************************************************/
/* Contains a namespace object that is created or you may manually change add this object **/
/* the namespace below by default to one of your sites global namespaces to to its library. ***/
/*   ****************************************************************************/
/* SYNTAX IN ANY JAVASCRIPT SCOPE:                                                                                  */
/* Call global object values by: Root.Browser.Name                                                                      */
/* Test whether it is a particular browser: Root.Browser.CheckVersion.IsOpera == true         */
/* SYNTAX IN CSS FOR BROWSER SPECIFIC MODIFICATIONS:                                       */
/* All browsers work except for Safari which makes the title text larger than it should         */
/* be and IE6 margins are too much so needs reduced then:                                                        */
/* #header div.title {float:left; margin-left:10px; font-size:14px;}                                            */
/* .browserSafari #header div.title {font-size:12px;}                                                                */
/* .browserIE6 #header div.title {margin-left:5px;}                                                                   */
/* CURRENT LIST OF CLASSES ON BODY TAG TO REFERENCE:                                         */
/* (only really need to concern with versions instead of base class for IE versions)              */
/* Internet Explorer: browserIE, browserIE6, browserIE7, browserIE8                                */
/* Firefox: browserFirefox, browserFirefox1, browserFirefox2, browserFirefox3              */
/* Safari: browserSafari, browserSafari1, browserSafari2, browserSafari3                      */
/* Google Chrome: browserChrome, browserChrome1                                                                  */
/* Opera: browserOpera                                                                                                                 */
/*****************************************************************************/

// Parent/root namespace (comment out if wish to add to your own existing parent namespace
var Backwebs = {};

// Browser class extended from root namespace and populated via self wrapped closure
Backwebs.Browser = {};
Backwebs.Browser.CheckVersion = { IsIE: false, IsFirefox: false, IsOpera: false, IsSafari: false, IsChrome: false, IsUnknown: false };
(function() {
	// Preliminary data needed
	var browserName = false;
	var version = 0;
	var ua = navigator.userAgent.toLowerCase();
	// Test each browser against the user agent
	if (/chrome[\/\s]+(\d+\.\d+)/.test(ua)) {
		browserName = "Chrome";
	}
	else if (/applewebkit/.test(ua)) {
		if (/version[\/\s]+(\d+\.\d+)/.test(ua))
			browserName = "Safari";
	}
	else if (/opera[\/\s]+(\d+\.\d+)/.test(ua)) {
		browserName = "Opera";
	}
	else if (/msie[\/\s]+(\d+\.\d+)/.test(ua)) {
		browserName = "IE";
	}
	else if (/mozilla[\/\s]+(\d+\.\d+)/.test(ua)) {
		browserName = "Firefox";
		if (!(/firefox[\/\s]+(\d+\.\d+)/.test(ua)))
			version = 3; // No "firefox" in user agent means they have FF3 (later build)
	}
	// Note if browser is unknown (mobile phones, etc) and parse version number
	if (browserName === false) {
		browserName = "Unknown";
		version = 0;
	}
	else {
		// Able to override above to have 0 here if unsure of version (for Firefox 3+ mainly) and just use base class
		if (version == 0)
			version = Number(RegExp.$1);
		else
			version = 0;
	}
	// Update object members based above testing
	Backwebs.Browser.CheckVersion["Is" + browserName] = true;
	Backwebs.Browser.Name = browserName;
	Backwebs.Browser.Version = Number(String(version).substring(0, 1));
})();

jQuery(document).ready(function() {
	// Add classes to body node for all versions of each browser and another for the specific version if applicable (ie6 comes to mind of course)
	jQuery("body").addClass('browser' + Backwebs.Browser.Name);
	if (Backwebs.Browser.Version != 0) {
		jQuery("body").addClass('browser' + Backwebs.Browser.Name + Backwebs.Browser.Version);
	}
});
