	/*
		KSALLINK Mobile Redirect.	
	*/
	function mobile_detect(){
		//static vars
		var browswer_agent, breakout, redirect_url, no_redirect_url, redirect_tabblet_url;
		
		//string vars
		var str_mobile, str_tabblet, str_parms, val_url;
		
		//Set static varibles
		this.browser_agent = navigator.userAgent;
		this.breakout = location.search;
		this.redirect_url = "http://www.ksallink.com/mobile";
		this.no_redirect_url = "http://www.ksallink.com/";
		this.redirect_tabblet_url = "http://www.ksallink.com/tabblet";
		this.agent_lower = agent_lower;
		this.find_mobile = find_mobile;
		this.check_mobile_type = check_mobile_type;
		
		function find_mobile(){
			if (this.browser_agent != 'undefined'){
				this.str_mobile = agent_lower(this.browser_agent);
				this.str_mobile = check_mobile_type(this.str_mobile);
				this.str_parms = get_url_var(this.breakout);
				
				if (this.str_parms == "1"){
					//right now do nothing and exit from script and load full page(in furtue setting cookie)
					/*
					if ((this.str_mobile == "opera mini")){
						//do nothing(Opera mimi has issues with dialog boxes)
					}
					else {
						if (confirm("Question")){
							//set_cookie();
						}
						else {
							//do nothing
						}
					}
					*/
				}
				else{
					if (this.str_mobile == "mobile"){
						location.replace(this.redirect_url);	
					}					
				}
			}
		}
		
		function check_mobile_type(mobile_agent){
			if ((mobile_agent.match(/android/i)) && (mobile_agent.match(/mobile/i))){
				mobile_agent = "mobile";				
			}
			if ((mobile_agent.match(/ipad/i))){
				mobile_agent = "tabblet"	
			}
			if ((mobile_agent.match(/iphone/i))){
				mobile_agent = "mobile";
			}
			if ((mobile_agent.match(/ipod/i))){
				mobile_agent = "mobile";
			}
			if ((mobile_agent.match(/blackberry/i))){
				mobile_agent = "mobile";
			}
			if ((mobile_agent.match(/iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile/i))){
				mobile_agent = "mobile";
			}
			if ((mobile_agent.match(/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i))){
				mobile_agent = "mobile";
			}
			if ((mobile_agent.match(/opera mini/i))){
				mobile_agent = "mobile";
			}			
			
			return mobile_agent;
		}
		
		function get_url_var(url){
			var str_split;
			
			this.val_url = url;
			//strip ? out of url
			this.val_url = this.val_url.substring(1);
			str_split = this.val_url.split("&");
			
			for(i = 0; i < str_split.length; i++)
			{
				var str_split = str_split[i].split("=");
				var m = str_split[0];
			}
			
			return m;
		}
		
		function agent_lower(value){
			value = value.toLowerCase();
			
			return value;
		}
	}

var obj = new mobile_detect();
obj.find_mobile();
