/*  
Name: SkiVite Global JavaScript
-----------------------------------------
Purpose: Provides the global JavaScript components necessary for SkiVite to run as specified. Please only use fully tested JavaScript that degrades gracefully in the browser. This JavaScript document should be included in all pages output by SkiVite.
Author: Joe Baz, Above the Fold (http://www.abovethefolddesign.com/)

Version History
-----------------------------------------
1.0
@ First draft of document

*/

/* 
Script Name: Browser Detection
------------------------------------------
Purpose: Detects browser and stores browser version into a variable for later use. For SkiVite, IE specific styles are used and will not pass a CSS standards check. This will therefore allow a CSS validator to successfully test against the standards-compliant CSS created for SkiVite and not the skivite-ie.css stylesheet. You can query three properties of the BrowserDetect object:

    * Browser name: BrowserDetect.browser
    * Browser version: BrowserDetect.version
    * OS name: BrowserDetect.OS

Script Dependencies: None
Author: Quirksmode (http://www.quirksmode.org/js/detect.html)
Co-Author: Joe Baz, Above the Fold  (http://www.abovethefolddesign.com/)
*/
var BrowserDetect = {
	init: function () { /* This function gets initialized upon load. Provides the placeholder values for 3 objects: browser, version and OS. */
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) { /* Per the initialized browser object, this function will search for the full string of the browser object */
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			// document.write("<b>dataString["+i+"]:</b> "+data[i].string+"<br />"); /* Uncomment to view test output */
			var dataProp = data[i].prop;
			// document.write("<b>dataProp["+i+"]:</b> "+data[i].prop+"<br />"); /* Uncomment to view test output */
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					// document.write("<b>dataString:</b> "+data[i].subString+"<br />"); /* Uncomment to view test output */
					return data[i].identity;
					
			}
			else if (dataProp)
				// document.write("<b>dataProp:</b> "+data[i].subString+"<br />"); /* Uncomment to view test output */
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) { /* Grabs the version number from the full dataString variable, that is: browser object */
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		// document.write("<b>browser version:</b> "+parseFloat(dataString.substring(index+this.versionSearchString.length+1))+"<br />"); /* Uncomment to view test output */
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




/* Script Name: Load IE StyleSheet
------------------------------------------
Purpose: Using the browser detection script, this will check if for the following UserAgents: IE + (5, 5.5 or 6) + Win. If this is met, then the skivite-ie.css will be loaded. If not, nothing happens. 
Script Dependencies: Browser Detection
Author: Joe Baz, Above the Fold  (http://www.abovethefolddesign.com/)
*/
var styleSheetIES = {
	init: function () { /* This function gets initialized upon load. */
		var ieVersions = new Array("5", "5.5", "6"); /* Initiate the array containing the supported versions of IE. */
		
		if((BrowserDetect.browser == "Explorer") && (BrowserDetect.OS == "Windows")) { /* This must me IE and Windows */
			var version = BrowserDetect.version;
			for (version in ieVersions) {
				document.write('<link href="/css/skivite-ie.css" rel="stylesheet" type="text/css" media="screen" />'); 		
				break; /* Make sure the loop ends after it finds the first match, otherwise it will continue writing the <link> */
			}
		}
	}
}
styleSheetIES.init();




/* Function Name: Launch Script onLoad
------------------------------------------
Purpose: This function can be called anytime you would like to force a script or function to run without requiring user intervention. 
Script Dependencies: none
Author: Jermey Keith 
*/
/* Function Purpose: Some browsers do not support the AddLoadEvent JS function, so we accommodate this with the older window.onload function. */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) oldonload();
			func();
		}
	}
}

function shortenTripTitle() {
	var els = document.getElementsByClassName('navManuItem');
	els.each(function(a) {
		a.childElements()[0].innerHTML.truncate(10);
	});
}

Event.observe(window, 'load', shortenTripTitle);