/* Mobile Redirect
The purpose of this script is to redirect any visitors to hollytegeler.com/mobile if they are using a mobile device.
Tablets are not considered mobile devices
*/

(function(){
		
  var user_agent = navigator.userAgent;
  var is_mobile = false;
  var new_url = 'http://hollytegeler.com/mobile';
  var normal_url = 'http://cargocollective.com/hollytegeler';
    
   //OS level agents rather than device
   //These are stored in a separate array since we want to do a case sensitive lookup to avoid false positives
   //Android is left out since we need to deal with Android tablets
   var mobile_os_agents = [
     'iPhone',
     'BlackBerry',
     'Windows Phone OS 7',
     'Palm',
     'Symbian',
     'webOS'
   ];
   
   //Combine all of our regex patterns to a single regex for speed
   var mobile_os_agent_test = new RegExp(mobile_os_agents.join('|'), 'g'); 
   
   //Test for mobile OS
   if (mobile_os_agent_test.test(user_agent)){
   	is_mobile = true;
   }
   
   //Tests for android. These are separate due to having to exclude android tablets
   if(user_agent.match(/Android/)) {
   	is_mobile = true;
   
   	//Any honeycomb devices are not considered mobile
   	if(user_agent.match(/android 3/i) || user_agent.match(/honeycomb/i)) {
   		is_mobile = false;
   	}
   
   	//All pre honeycomb android tablets
   	var android_tablets = [
   		'Advent|Vega', //Advent Vega
			'archos', //Archos all tablets
			'augen', //AUGEN Electronics
			'camangi', //Camangi
			'csl', //CSL
			'cherry', //Cherry Mobile
			'coby|kyros', //Coby Kyros
			'dell streak', //Dell Dell Streak
			'entourage', //Entourage eDGe
			'hardkernel|odroid-t', //Hardkernel ODROID-T
			'maylong', //Maylong M-150
			'maipad|mx005', //Maipad MX005
			'nationite|midnite', //Nationite MIDnite
			'notion|adam', //Notion Ink Adam
			'smart devices|smartq', //Smart Devices SmartQ-V5 SmartQ-V7SmartQ-T7
			'1&1|smartpad', //1&1 SmartPad
			'velocity|cruz', //Velocity Micro Cruz
			'dawa|d7', //Dawa D7
			'viewsonic', //ViewSonic GTablet ViewPad
			'sch-i800|sgh-t849|gt-p1000|sgh-t849|shw-m180S|galaxy_tab|galaxy tab', //Samsung Galaxy Tab
			'folio', //Toshiba Folio 100
			'zte', //ZTE Light
   	];
   	
   	//Test for any pre honeycomb android tablets
   	var android_tablet_test = new RegExp(android_tablets.join('|'), 'ig');
   	if(android_tablet_test.test(user_agent)) {
   		is_mobile = false;
   	}
   	
   }
   
   //Redirect if necessary
   if(is_mobile) {
   	window.location = new_url;
   }
   else {
   	window.location = normal_url;
   }
})();
