/*#############################################################################

FILE:	mobileRedirect.js

	Copyright (c) 2005 Navitaire Inc. All rights reserved.

	This source code is (i) proprietary to and a trade secret of Navitaire Inc.
	and (ii) protected by copyright law and international treaties.
	Unauthorized disclosure, reproduction, distribution or alteration of this
	source code, or any portion of it, may result in severe civil and criminal
	penalties and will be prosecuted to the maximum extent possible under
	the law.

	www.navitaire.com


#############################################################################*/
/*globals window,document, navigator, SA */
if (!window.SA) {
	window.SA = {};
}

SA.redirection_mobile = function(configuration) {

	// Retrieve the User Agent of the browser
	var agent = navigator.userAgent.toLowerCase(),
   

	// configuration object
	config = configuration || {},

	// new url for the mobile site domain 
	mobile_url = config.mobile_url,
	
	//get desktop url
	desktop_url = config.desktop_url,
	
	//get version i.e. if script is meant for desktop or mobile site
	version = config.version,

	// Check if the UA is a mobile one (iphone, ipod, android, blackberry)
	isUAMobile = !!(agent
			.match(/(iPhone|iPod|blackberry|android 0.5|htc|lg|midp|mmp|mobile|nokia|opera mini|palm|pocket|psp|sgh|smartphone|symbian|treo mini|Playstation Portable|SonyEricsson|Samsung|MobileExplorer|PalmSource|Benq|Windows Phone|Windows Mobile|IEMobile|Windows CE|Nintendo Wii)/i)),

	// Check if the device is a Tablet such as iPad, Samsung Tab, Motorola Xoom or Amazon Kindle
	isUATablet = !!(agent.match(/(iPad|SCH-I800|xoom|kindle)/i));

	// Check that User Agent is mobile
	if (isUATablet || isUAMobile) {
		var html_version = '';
		if (window.applicationCache || window.localStorage) {
			//html 5
			html_version = '/Consumer/home';
		} else {
			//html 4
			html_version = '/Consumer/m/home';
		}
		//Redirecting to mobile site
		window.location.href = 'http:' + "//" + mobile_url + html_version;
	} else if(version == 'mobile') {
		//redirecting to desktop site
		window.location.href = 'http:' + "//" + desktop_url;
	}
	
};
