function MobileDetector() 
{
	//----------- constants ----------//
	
	//Apple
	MobileDetector.ENGINE_WEBKIT 	= "webkit";
	MobileDetector.DEVICE_IPHONE 	= "iphone";
	MobileDetector.DEVICE_IPOD 		= "ipod";
	MobileDetector.DEVICE_IPAD 		= "ipad";
	
	//Android
	MobileDetector.DEVICE_ANDROID 	= "android";
	MobileDetector.DEVICE_XOOM 		= "xoom";
	
	//Windows phone
	MobileDetector.WINDOWS_7 		= "windows phone os 7";
	MobileDetector.ENGINE_IE_MOBILE = "iemobile";
	
	//Blackberry
	MobileDetector.DEVICE_BLACKBERRY = "blackberry";
	MobileDetector.ENGINE_RIM 		= "vnd.rim";
	
	//properties
	var agentString = "";
	var redirectString = "";
	
	//public methods
	this.setAgent = setAgent;
	this.setRedirectString =  setRedirectString;
	this.detectMobile = detectMobile;
	this.detectMobileAndRedirect = detectMobileAndRedirect;
	this.printAgent = printAgent;
	this.printRedirectString = printRedirectString;
	
	this.detectIpad = detectIpad;
	
	//setters
	function setAgent( val ) {
		agentString  = val;
	}
	
	function setRedirectString( val ) {
		redirectString  = val;
	}
	
	//---------public methods implementation ---//
	
	//---------detection methods ---------------//
	
	// Detects if the current device is an iPhone or iPod Touch.
	function detectIphoneOrIpod() {
   		if (agentString.search(MobileDetector.DEVICE_IPHONE) > -1 ||
       		agentString.search(MobileDetector.DEVICE_IPOD ) > -1)
       		return true;
   		else
       		return false;
	}
	
	// Detects if the current device is an iPad tablet.
	function detectIpad() {
   		if (agentString.search(MobileDetector.DEVICE_IPAD) > -1  && detectWebkit())
      		return true;
   		else
      		return false;
	}
	
	// Detects if the current browser is based on WebKit.
	function detectWebkit() {
   		if (agentString.search(MobileDetector.ENGINE_WEBKIT) > -1)
      		return true;
  		else
      		return false;
	}
	
	// Detects *any* iOS device: iPhone, iPod Touch, iPad.
	function detectIos() {
   		if (detectIphoneOrIpod() || detectIpad())
     		 return true;
   		else
      		return false;
	}
	
	//Detect Android OS
	function detectAndroid() {
   		if (agentString.search(MobileDetector.DEVICE_ANDROID) > -1)
     		 return true;
   		else
      		return false;
	}
	
	// Windows Phone 7 device.
	function detectWindowsPhone7() {
  		 if (agentString.search(MobileDetector.WINDOWS_7) > -1)
      		return true;
   		else
      		return false;
	}
	
	// Detects if the current browser is a BlackBerry of some sort.
	// Includes the PlayBook.
	function detectBlackBerry() {
   		if (agentString.search(MobileDetector.DEVICE_BLACKBERRY) > -1)
      		return true;
   		if (agentString.search(MobileDetector.ENGINE_RIM ) > -1)
      		return true;
  		else
      		return false;
	}
	
	//Detect if device is a mobile of any sort
	function detectMobile() {
		
		if (detectIphoneOrIpod())
			return true;
		if (detectAndroid())
			return true;
		if (detectWindowsPhone7())
			return true;
		if (detectBlackBerry())
			return true;
			
		return false;	
	}
	
	function detectMobileAndRedirect() {
		var test = 	detectMobile();
		if ( test == true ) {
			if ( redirectString != "" ) {
				window.location = redirectString;
			}
		}
	}
	
	//print methods
	function printAgent() {
		alert( agentString  );
	}
	
	function printRedirectString() {
		alert( redirectString );
	}
}




