$().ready(function() {		
		// validate form on keyup and submit
		$("#sf_form").validate({
			rules: {
				first_name: { required: true },
				last_name: { required: true },
				company: { required: true },
				address: { required: true },
				city: { required: true },
				state: { required: true },
				phone: { required: true },
                zip: { required: true },
                title: { required: true },
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				first_name: "Please enter your first name",
				last_name: "Please enter your last name",
				company: "Please enter your company",
				address: "Please enter your address",
				city: "Please entery your city",
				state: "Please select your state",
				phone: "Please enter your phone number",
				email: "Please enter a valid email address"
			}
		});
});



$(function () {
          $('#slider').ulslide({

              effect: {
                  type: 'slide',
                  // slide or fade
                  axis: 'x',
                  // x, y
                  distance: 7 // Distance between frames
              },

              pager: 'ul.switcher a',
              duration: 1000,
              autoslide: 10000,	/*HN 11/15/2011 - increased duration to 10 seconds*/
              width: 657,
              height: 320,
              nextButton: '#e1_next',
              prevButton: '#e1_prev',
              mousewheel: true

          });
      });

jQuery(function() {

	hideFormText();

	new touchNav({

		navBlock: 'nav'

	});

	addArrow();

	fixHeight();

})



// fixHeight

function fixHeight() {

	var box = jQuery('#wrapper > .w1 > .w2 > .w3');

	var h = jQuery(window).height();

	

	function setH() {

		h = jQuery(window).height();

		box.css({

			minHeight: h

		})

	}

	setH();

	

	jQuery(window).resize(setH);

}



function hideFormText() {

	var _inputs = document.getElementsByTagName('input');

	var _txt = document.getElementsByTagName('textarea');

	var _value = [];

	

	if (_inputs) {

		for(var i=0; i<_inputs.length; i++) {

			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {

				

				_inputs[i].index = i;

				_value[i] = _inputs[i].value;

				

				_inputs[i].onfocus = function(){

					if (this.value == _value[this.index])

						this.value = '';

				}

				_inputs[i].onblur = function(){

					if (this.value == '')

						this.value = _value[this.index];

				}

			}

		}

	}

	if (_txt) {

		for(var i=0; i<_txt.length; i++) {

			_txt[i].index = i;

			_value['txt'+i] = _txt[i].value;

			

			_txt[i].onfocus = function(){

				if (this.value == _value['txt'+this.index])

					this.value = '';

			}

			_txt[i].onblur = function(){

				if (this.value == '')

					this.value = _value['txt'+this.index];

			}

		}

	}

}



function addArrow() {

	jQuery( "ul.side-nav li ul" ).parents( "li" ).children( "a" ).append( "<span class='arrow'>&nbsp;</span>" ); 

}



// navigation accesibility module

function touchNav(options) {

	this.options = {

		mobileReg: /(ipad|iphone|ipod|android|blackberry|iemobile)/gi,

		hoverClass: 'hover',

		followLink: false,

		menuItems: 'li',

		menuOpener: 'a',

		menuDrop: 'div',

		navBlock: null

	}

	for(var p in options) {

		this.options[p] = options[p];

	}

	this.init();

}

touchNav.prototype = {

	init: function() {

		this.isMobile = (this.options.mobileReg).test(navigator.userAgent);

		if(typeof this.options.navBlock === 'string') {

			this.menu = document.getElementById(this.options.navBlock);

		} else if(typeof this.options.navBlock === 'object') {

			this.menu = this.options.navBlock;

		}

		if(this.menu) {

			this.getElements();

			this.addEvents();

		}

	},

	getElements: function() {

		this.menuItems = this.menu.getElementsByTagName(this.options.menuItems);

	},

	hideActiveDropdown: function() {

		if(this.activeParent) {

			for(var i = 0; i < this.menuItems.length; i++) {

				this.removeClass(this.menuItems[i], this.options.hoverClass);

			}

			this.activeParent = null;

		}

	},

	getOpener: function(obj) {

		for(var i = 0; i < obj.childNodes.length; i++) {

			if(obj.childNodes[i].tagName && obj.childNodes[i].tagName.toLowerCase() == this.options.menuOpener.toLowerCase()) {

				return obj.childNodes[i];

			}

		}

		return false;

	},

	getDrop: function(obj) {

		for(var i = 0; i < obj.childNodes.length; i++) {

			if(obj.childNodes[i].tagName && obj.childNodes[i].tagName.toLowerCase() == this.options.menuDrop.toLowerCase()) {

				return obj.childNodes[i];

			}

		}

		return false;

	},

	addEvents: function() {

		// mobile event handlers

		if(this.isMobile) {

			for(var i = 0; i < this.menuItems.length; i++) {

				this.menuItems[i].touchNav = this;

				if(this.getDrop(this.menuItems[i])) {

					this.addHandler(this.getOpener(this.menuItems[i]), 'click', this.bind(this.clickHandler,this.menuItems[i]));

				}

			}

			this.addHandler(document.body, 'click', this.bind(this.outsideHandler, this));

			this.addHandler(document.body, 'touchstart', this.bind(this.outsideHandler, this));

		}

		// desktop event handlers

		else {

			for(var i = 0; i < this.menuItems.length; i++) {

				this.menuItems[i].touchNav = this;

				this.addHandler(this.menuItems[i], 'mouseover', this.mouseoverHandler);

				this.addHandler(this.menuItems[i], 'mouseout', this.mouseoutHandler);

			}

		}

	},

	outsideHandler: function(e) {

		var childFlag = false;

		if(this.activeParent) {

			this.outsideTarget = e.target || e.currentTarget || e.srcElement;

			while (this.outsideTarget.parentNode) {

				if(this.activeParent == this.outsideTarget) {

					childFlag = true;

					break;

				}

				this.outsideTarget = this.outsideTarget.parentNode;

			}

			if(!childFlag) {

				this.hideActiveDropdown();

			}

		}

	},

	mouseoverHandler: function() {

		this.touchNav.addClass(this, this.touchNav.options.hoverClass);

	},

	mouseoutHandler: function() {

		this.touchNav.removeClass(this, this.touchNav.options.hoverClass);

	},

	clickHandler: function(e) {

		// get current dropdown

		var tNav = this.touchNav;

		tNav.currentElement = e.currentTarget || e.srcElement;

		tNav.currentParent = tNav.currentElement.parentNode;



		// hide previous drop (if exists)

		if(tNav.activeParent && !tNav.isParent(tNav.activeParent, tNav.currentParent) && tNav.currentParent != tNav.activeParent) {

			tNav.hideActiveDropdown();

		}



		// handle current drop

		if(tNav.hasClass(tNav.currentParent, tNav.options.hoverClass)) {

			tNav.removeClass(tNav.currentParent, tNav.options.hoverClass);

			if(tNav.options.followLink) {

				window.location.href = tNav.currentElement.href;

			}

		} else {

			tNav.addClass(tNav.currentParent, tNav.options.hoverClass);

			tNav.activeParent = tNav.currentParent;

			return tNav.preventEvent(e);

		}

	},

	preventEvent: function(e) {

		if(!e) e = window.event;

		if(e.preventDefault) e.preventDefault();

		if(e.stopPropagation) e.stopPropagation();

		e.cancelBubble = true;

		return false;

	},

	isParent: function(parent, child) {

		while(child.parentNode) {

			if(child.parentNode == parent) {

				return true;

			}

			child = child.parentNode;

		}

		return false;

	},

	addHandler: function(object, event, handler) {

		if (typeof object.addEventListener != 'undefined') object.addEventListener(event, this.bind(handler,object), false);

		else if (typeof object.attachEvent != 'undefined') object.attachEvent('on' + event, this.bind(handler,object));

	},

	removeHandler: function(object, event, handler) {

		if (typeof object.removeEventListener != 'undefined') object.removeEventListener(event, handler, false);

		else if (typeof object.detachEvent != 'undefined') object.detachEvent('on' + event, handler);

	},

	hasClass: function(obj,cname) {

		return (obj.className ? obj.className.match(new RegExp('(\\s|^)'+cname+'(\\s|$)')) : false);

	},

	addClass: function(obj,cname) {

		if (!this.hasClass(obj,cname)) obj.className += " "+cname;

	},

	removeClass: function(obj,cname) {

		if (this.hasClass(obj,cname)) obj.className=obj.className.replace(new RegExp('(\\s|^)'+cname+'(\\s|$)'),' ');

	},

	bind: function(func, scope){

		return function() {

			return func.apply(scope, arguments);

		}

	}

}

// mobile browsers detect

browserPlatform = {

	platforms: [

		{ uaString:['symbian','midp'], cssFile:'symbian.css' }, // Symbian phones

		{ uaString:['opera','mobi'], cssFile:'opera.css' }, // Opera Mobile

		{ uaString:['msie','ppc'], cssFile:'ieppc.css' }, // IE Mobile <6

		{ uaString:'iemobile', cssFile:'iemobile.css' }, // IE Mobile 6+

		{ uaString:'webos', cssFile:'webos.css' }, // Palm WebOS

		{ uaString:'Android', cssFile:'android.css' }, // Android

		{ uaString:['BlackBerry','/6.0','mobi'], cssFile:'blackberry6.css' },	// Blackberry 6

		{ uaString:['BlackBerry','/7.0','mobi'], cssFile:'blackberry7.css' },	// Blackberry 7+

		{ uaString:'ipad', cssFile:'ipad.css', miscHead:'<meta name="viewport" content="width=device-width" />' }, // iPad

		{ uaString:['safari','mobi'], cssFile:'safari.css', miscHead:'<meta name="viewport" content="width=device-width" />' } // iPhone and other webkit browsers

	],

	options: {

		cssPath:'css/',

		cssPath:'/p2h_wordpress/iediscovery/wp-content/themes/iediscovery/css/',

		mobileCSS:'allmobile.css'

	},

	init:function(){

		this.checkMobile();

		this.parsePlatforms();

		return this;

	},

	checkMobile: function() {

		if(this.uaMatch('mobi') || this.uaMatch('midp') || this.uaMatch('ppc') || this.uaMatch('webos')) {

			this.attachStyles({cssFile:this.options.mobileCSS});

		}

	},

	parsePlatforms: function() {

		for(var i = 0; i < this.platforms.length; i++) {

			if(typeof this.platforms[i].uaString === 'string') {

				if(this.uaMatch(this.platforms[i].uaString)) {

					this.attachStyles(this.platforms[i]);

					break;

				}

			} else {

				for(var j = 0, allMatch = true; j < this.platforms[i].uaString.length; j++) {

					if(!this.uaMatch(this.platforms[i].uaString[j])) {

						allMatch = false;

					}

				}

				if(allMatch) {

					this.attachStyles(this.platforms[i]);

					break;

				}

			}

		}

	},

	attachStyles: function(platform) {

		var head = document.getElementsByTagName('head')[0], fragment;

		var cssText = '<link rel="stylesheet" href="' + this.options.cssPath + platform.cssFile + '" type="text/css"/>';

		var miscText = platform.miscHead;

		if(platform.cssFile) {

			if(document.body) {

				fragment = document.createElement('div');

				fragment.innerHTML = cssText;

				head.appendChild(fragment.childNodes[0]);

			} else {

				document.write(cssText);

			}

		}

		if(platform.miscHead) {

			if(document.body) {

				fragment = document.createElement('div');

				fragment.innerHTML = miscText;

				head.appendChild(fragment.childNodes[0]);

			} else {

				document.write(miscText);

			}

		}

	},

	uaMatch:function(str) {

		if(!this.ua) {

			this.ua = navigator.userAgent.toLowerCase();

		}

		return this.ua.indexOf(str.toLowerCase()) != -1;

	}

}.init();
