/**
 * @author Eddie Price
 * Mobile.Lib
 */

if (this.PW == null) {
    this.PW = {};
    this.PW.Mobile = {};
}

/** Initialize user agent string */
var uagent = navigator.userAgent.toLowerCase();

Detect = function(){
	var deviceIPhone = 'iphone';
	var deviceIPad = 'ipad';
	var deviceIPod = 'ipod';
	var deviceAndroid = 'android';
	var deviceS60 = 'series60';
	var deviceSymbian = 'symbian';
	var engineWebKit = 'webkit';
	var deviceWinMob = 'windows ce';
	var deviceBB = 'blackberry';
	var devicePalm = 'palm';
	var siteRedirect = '';

	/** Get/Set redirect location */
	this.setRedirect = function(_loc){
		siteRedirect = _loc;
	};
	
	this.uAgentCheck = function(_device){
		if (uagent.indexOf(_device) > -1) {
			if (siteRedirect != '') {
				window.location.href = siteRedirect;
			}
			else
			return true;
		}
		else 
			return false;
	};
	
	/** Detects if the current device is an iPhone. */
	this.isIPhone = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceIPhone);
	};
	
	/** Detects if the current device is an iPod. */
	this.isIPod = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceIPod);
	};
	
	/** Detects if the current device is an iPad. */
	this.isIPad = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceIPad);
	};
	
	/** Detects if the current device is an Android. */
	this.isAndroid = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceAndroid);
	};
	
	/** Detects if the current browser is a Windows Mobile device. */
	this.isWinMobile = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceWinMob);
	};
	
	/** Detects if the current browser is a BlackBerry */
	this.isBlackBerry = function(){
		return PW.Mobile.Detect.uAgentCheck(deviceBB);
	};
	
	/** Detects if the current browser is on a PalmOS device. */
	this.isPalmOS = function(){
		return PW.Mobile.Detect.uAgentCheck(devicePalm);
	};	
	
	/** Detects if the current device is an Android OS w/ webkit browser */
	this.isAndroidWebkit = function(){
		if (PW.Mobile.Detect.uAgentCheck(deviceAndroid)) {
			if (PW.Mobile.Detect.uAgentCheck(engineWebKit)) 
				if (siteRedirect != '') {
					window.location.href = siteRedirect;
				}
				else 
					return true;
		}
		else 
			return false;
	};
	
	/** Detects if the current browser is the S60/Symbian Open Source Browser. */
	this.isS60 = function(){
		if (PW.Mobile.Detect.uAgentCheck(engineWebKit) > -1) {
			if ((PW.Mobile.Detect.uAgentCheck(deviceS60) > -1 || PW.Mobile.Detect.uAgentCheck(deviceSymbian) > -1)) 
				return true;
			else 
				return false;
		}
		else 
			return false;
	};
}
this.PW.Mobile.Detect = new Detect();

$(document).ready(function () {
	$('div').live('pagecreate', function(event, ui){
		event.stopPropagation();
	});

	$('.topnav').click(function(){
		$(this.parentNode).find('.subnav').toggle();
	});
	$('.subnav li').click(function(){
		$(this.parentNode).toggle();
	});
	
	if($('#hasSubmitted').val() == '1'){
		$('.contact').click();
		$('#contact > .ui-content').attr('style', 'height:305px');
	}
	
	if ($('#notValid').val() == '1') {
		$('.contact').click();
	}
	
    if (PW.Mobile.Detect.isIPhone()) {
        $('.navbar').attr('style', 'top:47px !important;');
    }
	
});


		
		
