(function(){

	// Map over jQuery in case of overwrite
	if ( typeof ECOOLING != "undefined" ){
		var _ECOOLING = ECOOLING;
	}

	var ECOOLING = window.ECOOLING = function() {
		// If the context is a namespace object, return a new object
		return this instanceof ECOOLING ? this.init() : new ECOOLING();
	};

	ECOOLING.prototype = {
	
	}


	jQuery.extend(ECOOLING,{
	
		//function that runs if call ECOOLING()
		init: function(){},


		dataStore: [],

/* ********* VALIDATE NEW METHOD  **************** */


		validatenew: function(newoptions){
			var prop = {													//the default properties
				fireWhen: 'onready'											//when to execute the code
			}
			var options = {};												//new object 
			jQuery.extend(options, prop, newoptions)						//extend the prop object with the newoptions object to create the options object 
			if(options.fireWhen==='onready'){
				jQuery(document).ready(function(){ECOOLING.validatenewprocess(options)})
			}else{
				ECOOLING.validatenewprocess(options)
			}
	
		},
		validatenewprocess: function(newoptions){
			var prop = {
				formId: 'validationForm',
				errorTag: 'p',
				errorClass: 'error',
				bigAlertClass: 'error',
				limitClass: 'limitvalidate',
				maxminClass: 'maxminvalidate',
				minClass: 'minvalidate',
				requiredClass: 'ecrequired',
				numericClass: 'numeric',
				language:'english'
			}
			var options = {};
			jQuery.extend(options, prop, newoptions)
			jQuery.getJSON("/wp-content/themes/ecooling_v2/"+options.language+".js",function(data,textStatus){
				ECOOLING.languagecache=data.language;
			})
			jQuery(options.errorTag + '.' + options.errorClass,jQuery('#' + options.formId)).remove();	//remove any the error messages
			jQuery("input."+options.requiredClass+", textarea."+options.requiredClass+", select."+options.requiredClass,jQuery('#' + options.formId)).bind("blur.ecvalidation",function(){ //bind a blur listener to all form fields
				ECOOLING.checkfieldnew(options,jQuery(this));
			});
			jQuery('#' + options.formId).submit(function(){													//bind a submit event to the form
				ECOOLING.dataStore=[];
				var $submitdiv = jQuery(this).find("div.submit");
				var $submitcache = $submitdiv.html();
				$submitdiv.html('<div class="callout message"><img src="/ecooling2/images/anim-loading.gif" class="align-left" /> Validating</div>')
				jQuery('#error,#bigAlertUl').remove();																	//remove any previously created submit error message
				jQuery(options.errorTag + '.'+ options.errorClass,jQuery('#' + options.formId)).remove();	//remove any previously created error message
				jQuery('div.error',jQuery('#' + options.formId)).removeClass("error");
				jQuery("."+options.requiredClass,jQuery('#' + options.formId)).each(function(){
					ECOOLING.checkfieldnew(options,jQuery(this));
				});
				jQuery("."+options.limitClass,jQuery('#' + options.formId)).each(function(){
					var eleme = jQuery(this)
					if(parseInt(jQuery.trim(eleme.val()).length,10)>0){
						ECOOLING.checkfieldnew(options,eleme);
					}
				})
				jQuery("."+options.minClass+", ."+options.numericClass,jQuery('#' + options.formId)).each(function(){
					var eleme = jQuery(this);
					if(eleme.val().length>0){
						ECOOLING.checkfieldnew(options,eleme);
					}
				})
				jQuery("."+options.maxminClass,jQuery('#' + options.formId)).each(function(){
					var eleme = jQuery(this);
					if(eleme.val().length>0){
						ECOOLING.checkfieldnew(options,eleme);
					}
				})

				var numWarnings=ECOOLING.dataStore.length;
				if (numWarnings>0){																		//if there are errors
					var $bigAlert = jQuery('<div></div>').attr({'id': 'error', 'class': options.bigAlertClass})							//create the div that will show any errors on submit
					var alertmessage=ECOOLING.languagecache["Please correct errors with following"].replace('||insertnumber||',numWarnings)
					$bigAlert.append('<span><strong>'+alertmessage+'</strong></span>')	//append the first line of the submit error message
					jQuery('<div class="clear">').insertAfter($bigAlert)
					$bigAlert.insertBefore('#' + options.formId);												//insert the error message before the form
					$bigAlert.prepend('<a name="erroranchor"></a>')
					jQuery('<div class="clear">').insertAfter($bigAlert)
					var $bigAlertUl = jQuery('<ul id="bigAlertUl" class="error-list"></ul>')
					jQuery.each(ECOOLING.dataStore,function(i,n){
						$bigAlertUl.append('<li>'+n+'</li>')
					})
					$bigAlertUl.insertBefore('#' + options.formId);
					$submitdiv.html($submitcache)
					window.location="#erroranchor";
					return false;																		//stop the submit from happening
				};
				$submitdiv.html('<div class="callout message"><img src="/ecooling2/images/anim-loading.gif" class="align-left" /> Submitting</div>')
				jQuery(".removeonsubmit",jQuery('#' + options.formId)).remove();
			});
		},
		checkfieldnew: function(newoptions,eleme){
			var prop = {
				errorTag: 'p',
				emailClass: 'email',
				phoneClass: 'phone'
			}
			var options = {};
			jQuery.extend(options, prop, newoptions);
			eleme.nextAll(options.errorTag).remove();																//remove any previously created error messages
			var $closediv = eleme.closest("div")
			$closediv.removeClass("error")
			if(eleme.is(".ecradioset")){																	//if the required element is a radio button
				var curfield=eleme.find("label:first").text();

				var errorMessage;
				if(typeof ECOOLING.languagecache["error"+eleme.attr("name")]==='undefined'){
					errorMessage = curfield + ' ' + ECOOLING.languagecache["is a required field"];								//create a variable of the error message
				}else{
					errorMessage = ECOOLING.languagecache["error"+eleme.attr("name")];								//create a variable of the error message
				}
				var radiocheckedcount=0																//create a counter set to 0
				jQuery(":radio",eleme).each(function(){											//for each radio button in the same listitem 	
					if(jQuery(this).is(":checked")){																//if the radio is checked
						radiocheckedcount++														//add 1 to the counter (should really never reach more than 1 with radio buttons)
					}
				})
				if(radiocheckedcount==0){															//if the counter is still at 0 then no radio buttons were checked
					options.errorMessage = errorMessage				
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield)
				}
			}
			if(eleme.is(".eccheckset")){																	//if the required element is a checkbox
				var curfield=eleme.find("label:first").text();
				var errorMessage;
				if(typeof ECOOLING.languagecache["error"+eleme.attr("name")]==='undefined'){
					errorMessage = curfield + ' ' + ECOOLING.languagecache["is a required field"];								//create a variable of the error message
				}else{
					errorMessage = ECOOLING.languagecache["error"+eleme.attr("name")];								//create a variable of the error message
				}
				var checkboxcheckedcount=0																//create a counter set to 0
				jQuery(":checkbox",eleme).each(function(){											//for each checkbox in the same list item 	
					if(jQuery(this).is(":checked")){																//if the radio is checked
						checkboxcheckedcount++														//add 1 to the counter (should really never reach more than 1 with radio buttons)
					}
				})
				//return false;
				
				if(checkboxcheckedcount==0){															//if the counter is still at 0 then no checkboxes were checked
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield)
				}
				if(jQuery(".createdcheckother",eleme).attr("checked")==true){
					if(jQuery(".checkboxother",eleme).val()==''){
						var errorMessage;
						if(typeof ECOOLING.languagecache["error"+eleme.attr("name")+"other"]==='undefined'){
							errorMessage = curfield + ' Other is a required field';								//create a variable of the error message
						}else{
							errorMessage = ECOOLING.languagecache["error"+eleme.attr("name")+"other"];								//create a variable of the error message
						}
						options.errorMessage = errorMessage
						ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
						ECOOLING.dataStore.push(curfield)
					}
				}
			}

			if (eleme.attr("ec:action")=="otherOption"){											//if this is a select field with an other afterward
				if(jQuery.trim(jQuery("option:selected",eleme).val())=='Other (please specify):') {							//if the other item is selected
					var $othertext = eleme.parents(":first").find("div.showingoption").find("input")					//set a variable to hold the jquery object of the other text field
					if($othertext.val()==''){														//if the other text field is empty
						$othertext.next('p').remove();											//remove any previously created error messages
						var curfield = jQuery("label[for="+eleme.attr("id")+"]");	//get the label of the current field
						if(curfield.length>0){
							var errorMessage
							if(typeof ECOOLING.languagecache["error"+eleme.attr("name")+"other"]==='undefined'){
								errorMessage = curfield.text() + ' Other is a required field';					//create a variable of the error message
							}else{
								errorMessage = ECOOLING.languagecache["error"+eleme.attr("name")+"other"];					//create a variable of the error message
							}
							options.errorMessage = errorMessage
						}
						ECOOLING.insertErrorMessagenew(options,$othertext,$closediv)
						ECOOLING.dataStore.push(curfield.text() + ' Other')
					}else{																			//if the field is not blank
						$othertext.next('p').remove();											//remove error messages
					}
				}
			}
			if((eleme.is(":text") || eleme.is("textarea") || eleme.is("select") || eleme.is(":password") || eleme.is(":file"))&&((jQuery.trim(eleme.val()) == '')||(eleme.val() == null))&&((!eleme.is(".eccanbeempty"))||(eleme.val() == null))){																	//if the required input is empty

				var curfield=jQuery("label[for="+eleme.attr("id")+"]");
				if(curfield.length>0){
					var errorMessage;
					if(typeof ECOOLING.languagecache["error"+eleme.attr("name")]==='undefined'){
						errorMessage = curfield.text() + ' ' + ECOOLING.languagecache["is a required field"];								//create a variable of the error message
					}else{
						errorMessage = ECOOLING.languagecache["error"+eleme.attr("name")];								//create a variable of the error message
					}
					options.errorMessage = errorMessage
				}
				
				ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
				ECOOLING.dataStore.push(curfield.text())

			}
			if(eleme.is('.' + options.emailClass)){																//if this is the email field
					if(eleme[0].value != '' && !/^[A-Z0-9'._%+-]+@(?:[A-Z0-9-]+\.(?!-))+[A-Z]{2,4}$/i.test(jQuery.trim(eleme[0].value))){			//if the field is not empty and fails the regular expression test

					var errorMessage = ECOOLING.languagecache["proper email format"];	//create the error messsage
					
					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

				}
			}
			if(eleme.is('.validatemacaddress')){																//if this is the email field
				if(eleme[0].value != '' && !/^[0-9a-f]{2}([;:-]?)([0-9a-f]{2}\1){4}[0-9a-f]{2}$|([0-9a-f]{4}([.]|$)){3}$/i.test(eleme[0].value)){			//if the field is not empty and fails the regular expression test

					var errorMessage = "Please enter the MAC address in one of the the following formats: xx-xx-xx-xx-xx-xx, xx:xx:xx:xx:xx:xx or xx;xx;xx;xx;xx;xx";	//create the error messsage

					var curfield=jQuery("label[for="+eleme.attr("id")+"]");

					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

				}
			}
			if(eleme.is('.ecnowhitespace')){																//if this is the email field
				if(eleme[0].value != '' && /\s/g.test(eleme[0].value)){			//if the field is not empty and fails the regular expression test

					var errorMessage = "Please do not use any spaces.";	//create the error messsage

					var curfield=jQuery("label[for="+eleme.attr("id")+"]");

					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

				}
			}
			if(eleme.is('.ec_passwordfirst')){																//if this field is the first of two password fields that need to be the same
				if((eleme.val()!==jQuery(".ec_passwordsecond",eleme.parents("form:first")).val())&&((jQuery(".ec_passwordsecond",eleme.parents("form:first")).val()).length>0)){
					var errorMessage = 'Please make sure the two password fields match';	//create the error messsage
					
					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())
				}
			}
			if(eleme.is('.ec_invalidvalue')){																//if this field has been invalidated elsewhere

					var errorMessage = 'Please use a valid value';	//create the error messsage
					
					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

			}
			if(eleme.is('#tlausername')){																//if this is the tla username field
				if(eleme[0].value != '' && !/\w{6,}/.test(eleme[0].value)){			//if the field is not empty and fails the regular expression test

					var errorMessage = 'Please use proper username format (at least 6 alphanumeric characters)';	//create the error messsage
					
					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

				}
			}
			if(eleme.is('#tlapassword')){																//if this is the tla username field
				var  tlaprob=false;
				if((jQuery("#tlausername")[0].value == '' || jQuery("#tlapassword")[0].value == '') && (jQuery("#tlausername").val() != '' || jQuery("#tlapassword").val() != '')&&(!tlaprob)){

					var errorMessage = 'Please fill out both the username and password';	//create the error messsage
					tlaprob=true;

					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())
				}
				if((jQuery("#tlapassword")[0].value != '' && jQuery("#tlapassword")[0].value.length < 6)&&(!tlaprob)){
					var errorMessage = 'Please use proper password format (at least 6 characters)';	//create the error messsage
					tlaprob=true;

					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())
				}
				if((jQuery("#tlapassword")[0].value !== '' || jQuery("#pswd2")[0].value !== '') && (jQuery("#tlapassword")[0].value !== jQuery("#pswd2")[0].value)&&(!tlaprob)){
					var errorMessage = 'Please make sure your password and your verified password match';	//create the error messsage
					tlaprob=true;

					var curfield=jQuery("label[for="+eleme.attr("id")+"]");
					
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())
				}
			}

			if(eleme.is('.' + options.limitClass)){																//if this is the phone field
				var limit=eleme.attr("rel")
				if(limit!=''&&!isNaN(limit)){
					limit=parseInt(limit,10);
					var ellength=parseInt((eleme.val()).length,10)
					if(ellength>limit){
						var errorMessage = 'Too many characters, please limit your input to ' + limit + ' characters. You entered ' + ellength + ' characters.';							//create the error messsage
				
						var curfield=jQuery("label[for="+eleme.attr("id")+"]");
						options.errorMessage = errorMessage
						ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
						ECOOLING.dataStore.push(curfield.text())

					}
				}
			}
			if(eleme.is('.' + options.minClass)){																//if this is the phone field
				var minval=eleme.attr("rel")
				if(minval!=''&&!isNaN(minval)){
					minval=parseInt(minval,10);
					var ellength=parseInt((eleme.val()).length,10)
					if(ellength<minval){
						var errorMessage = 'Too few characters, you need at least ' + minval + ' characters. You entered ' + ellength + ' characters.';							//create the error messsage
				
						var curfield=jQuery("label[for="+eleme.attr("id")+"]");
						options.errorMessage = errorMessage
						ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
						ECOOLING.dataStore.push(curfield.text())

					}
				}
			}
			if(eleme.is('.' + options.maxminClass)){																//if this is the phone field
				var elval = eleme.val();
				if(elval.length>0&&!isNaN(elval)){
					elval=parseInt(elval,10);
					var lims = jQuery.trim(eleme.attr("rel")).split("|");
					lims = jQuery.map(lims, function(n, i){
						var r = parseInt(n,10);
						if(!isNaN(r)){
							return parseInt(n,10);
						}
				    });
					if(lims.length===2){
						var errorMessage,curfield;
						if(elval<lims[0]){
							errorMessage = 'Number too low, can\'t be less than ' + lims[0] + '. You entered ' + elval + '.';							//create the error messsage
							curfield=jQuery("label[for="+eleme.attr("id")+"]");
							options.errorMessage = errorMessage
							ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
							ECOOLING.dataStore.push(curfield.text())
						}
						if(elval>lims[1]){
							errorMessage = 'Number too high, can\'t be more than ' + lims[1] + '. You entered ' + elval + '.';							//create the error messsage
							curfield=jQuery("label[for="+eleme.attr("id")+"]");
							options.errorMessage = errorMessage
							ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
							ECOOLING.dataStore.push(curfield.text())
						}
					}
				}
			}

			if(eleme.is('.' + options.numericClass)){																//if this is a field which should only be numeric (is marked by the class numeric)
				var curfield=jQuery("label[for="+eleme.attr("id")+"]");
				if(eleme[0].value != '' && isNaN(eleme[0].value)){											//if the field is not empty and it is not a number
					var errorMessage = 'Please enter a numeric value ' + curfield.text();						//create the error messsage
				
					options.errorMessage = errorMessage
					ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
					ECOOLING.dataStore.push(curfield.text())

				}
			}
			if(eleme.is('.ecemailcheck')){																//if this is a field which should only be numeric (is marked by the class numeric)
				var curfield=jQuery("label[for="+eleme.attr("id")+"]");
				jQuery.ajax({
					type:"POST",
					port: "emailcheck",
					mode: "abort",
					async: false,
					url:"/screener/screen_email.cfm",
					data:{'email':eleme.val()},
					success: function(data){
						if(jQuery.trim(data)==='false'){
							var errorMessage = 'We do not grant access to personal, non-business email accounts. Please use your business email address.';						//create the error messsage
				
							options.errorMessage = errorMessage
							var $container = eleme.closest("div")
							var $errexist = jQuery("."+options.errorClass,$container)
							if($errexist.length>0){
								$errexist.remove();
							}
							ECOOLING.insertErrorMessagenew(options,eleme,$closediv)
							ECOOLING.dataStore.push(curfield.text())
						}
					}
				})
			}
		},
		insertErrorMessagenew: function(newoptions,$insertAfterPoint,$closediv){
			var prop = {
				errorTag: 'p',
				errorMessage: 'There is an error with this field.'
			}
			var options = {};
			jQuery.extend(options, prop, newoptions)
			$closediv.addClass("error")

			var $errmess = jQuery('<' + options.errorTag + '></' + options.errorTag + '>')								//create the paragraph that will hold the rror message
			.text(options.errorMessage)																//put the error message in the paragraph
			.addClass(options.errorClass)																//add the error class to the paragraph
			
			$errmess.insertAfter($insertAfterPoint);															//insert the paragraph after the email field
		},

/* ********* AUTOCOMPLETE METHOD  **************** */



		autocomplete: function(newoptions){
			var prop = {													//the default properties
				fireWhen: 'onready'											//when to execute the code
			}
			var options = {};												//new object 
			jQuery.extend(options, prop, newoptions)						//extend the prop object with the newoptions object to create the options object 
			if(options.fireWhen==='onready'){
				jQuery(document).ready(function(){ECOOLING.autocompleteprocess(options)})
			}else{
				ECOOLING.autocompleteprocess(options)
			}
	
		},
		autocompleteprocess: function(newoptions){
			var prop = {
				autoFillTextReference: '#autofilltext',				//the selector for the element that the user is typing into
				container: '<ul class="autocomplete"></ul>',				//the container for the list of possible results
				attachContainerToText: 'yes',								//should the container be attached to the text field
				wrapperTag: 'li',											//the tag each possible result will be wrapped in
				wrapText: false,
				wrapTextOpen: '<a href="#">',
				wrapTextClose: '</a>',
				minChars: 1,												//minumum characters before results are returned
				jsonUrl: 'autojson.js',										//the url to get the json from
				highlightClass: 'selected',									//the class used for when a possible result is highlighted
				valueFn:function(datapass){									//the function to get results from the json
					var valuePass = datapass.FIRSTNAME + ' ' + datapass.LASTNAME;
					return valuePass;
				},
				onSelected:function(jsonmember,autoFill){							//function that gets called onselection of an item
				},
				paramName: 'value',											//value to use when passing value of textfield
				onShow: function(){},
				onHide: function(){},
				useSpinner: false,
				spinnerPath: '/ecooling2/images/anim-loading.gif'
			}
			var options = {};												//new object to  hold options
			jQuery.extend(options, prop, newoptions)						//overwrite defaul options with passed in options
			jQuery(options.autoFillTextReference).each(function(){
				var $autofilltext = jQuery(this);		//save a reference to the element being typed into
				var $autocomplete = jQuery(options.container).hide();			//hide the element which contains suggested values for the text field
				$autocomplete.insertAfter($autofilltext);						//insert the container after the text field
	
				var jsoncache;													//create a variable which will hold the returned json
				var autostatus = null;
				
				var selectedItem = null;										//make sure the selectedItem variable does not hold any previous references
				var setSelectedItem = function(item){							//function to select an item in the container
					selectedItem = item;										//set selecteditem to the passed in item index 
					if(selectedItem===null){									//if there is no selected item, hide the suggested items
						autostatus = null;
						$autocomplete.hide();
						options.onHide();
						return;
					}
					if (selectedItem < 0){										//if the passed item index is somehow negative
						selectedItem = 0;										//select the first item
					}
					if(selectedItem >= $autocomplete.find(options.wrapperTag).length){	//if the passed item index is greater than the number of options
						selectedItem = $autocomplete.find(options.wrapperTag).length-1;	//select the last item
					}
					jQuery(options.wrapperTag,$autocomplete).removeClass(options.highlightClass);	//remove all highligt classes from the suggested items
					$autocomplete.find(options.wrapperTag).eq(selectedItem).addClass(options.highlightClass);	//highlight the item at the passed index 
					if(options.attachContainerToText==='yes'){	//if the suggested items should be attached to the text field
						var attachcssoptions = {				//an object to set the css values of the suggested item container
							'width': $autofilltext.width()+'px',		//set the width of the container to the width of the text field
							'position':'absolute'				//set the position to absolute
						}
						$autocomplete.css(attachcssoptions);	//bind the css to the container element
					}
					if(autostatus=='on'){
						$autocomplete.show();	//show the container
						options.onShow();
					}
				}
		
				var populateSearchField = function(){			//function to populate the text field
					$autofilltext.val($autocomplete.find(options.wrapperTag).eq(selectedItem).text());  //set the value to value of the selected suggested item
					options.onSelected(jsoncache[selectedItem],$autofilltext)											//call the onselected function, pass thee json member for the selected item
					setSelectedItem(null);																//call the setSelectedItem function
				}
		
				var createDropItem = function(indexitem,valuepass,datapass){							//function which creates a suggestion in the container
					var $dropItem = jQuery('<' + options.wrapperTag + '></' + options.wrapperTag + '>');
					$dropItem.html(valuepass).mouseover(function(){										//create the item, set its value and bind a mouseover
						setSelectedItem(indexitem);														//mouseover highlights item
					}).click(function(){																//click populates field
						populateSearchField(datapass);
						return false;
					}).appendTo($autocomplete);															//append the new item to the container
					if(options.wrapText){
						$dropItem.wrapInner(options.wrapTextOpen + options.wrapTextClose);
					}
				}
			
				$autofilltext.attr('autocomplete','off').keyup(function(event,a){							//add an autocomplete off attribute to the text field and bind a keyup event
					if($autofilltext.val().length >= options.minChars){									//if the user has typed in more characters than the minimum
						if (((event.keyCode > 40 || event.keyCode == 8)||(a === "mousepaste"))&&event.keyCode!==undefined){									//if the key pressed was not a special character or was the backspace
							autostatus = 'on';
							var ajaxDataObj = {};														//create a new Object	
							ajaxDataObj[options.paramName] = $autofilltext.val();						//add the value of the text field to the data being sent in the ajax query 
							if(options.useSpinner){
								$autocomplete.empty().append(('<' + options.wrapperTag + ' class="loading"><img src="' + options.spinnerPath + '" /></' + options.wrapperTag + '>')).show();
							}
							jQuery.ajax({																//the ajax query 
								'url': options.jsonUrl,													//the url being queried 
								'data': ajaxDataObj,													//the data being sent with the query 	
								'dataType': 'json',														//expecting json to be returned 
								'port': "autocomplete",													//identify this as so it can be aborted independently of other ajax queries
								'mode': "abort",														//if any ajax queries are made with the same port value, cancel this one 
								'type': 'GET',															//is a get request
								'success': function(data){												//on success of the query 
									jsoncache = null;													//clear out the cache of the json
									if(data.length){													//if results were returned
										jsoncache=data;													//store the results where other functions can access them
										$autocomplete.empty().hide();											//empty the suggestions container
										for(var i = 0,datal = data.length;i<datal;i++){								//loop through the json
											var valuetoshow=options.valueFn(data[i]);					//call the function to format the data to be shown
											createDropItem(i,valuetoshow);								//add the suggestion to the container
										}
										setSelectedItem(0);												//make the first item selected
									}else{
										setSelectedItem(null);											//or set the selected item to null if there were no results
									}
								}
							})
						}
						else if(event.keyCode == 38 && selectedItem !== null){							//if user presses up arrow
							if(selectedItem==0){
								setSelectedItem(jQuery("li",$autocomplete).length);
							}else{
								setSelectedItem(selectedItem - 1);											//select previous item
							}
							event.preventDefault();
						}
						else if(event.keyCode == 40 && selectedItem !== null) {							//if user presses down arrow
							if(selectedItem==(jQuery("li",$autocomplete).length-1)){
								setSelectedItem(0);
							}else{
								setSelectedItem(selectedItem + 1);											//select next item
							}
							event.preventDefault();
						}
						else if(event.keyCode == 27 && selectedItem !== null) {							//if user presses escape key
							setSelectedItem(null);															//if there are less characters than the minimum clear selected item
							event.preventDefault();
						}
					}else{
						setSelectedItem(null);															//if there are less characters than the minimum clear selected item
						event.preventDefault();
					}
				})
				
				$autofilltext.keypress(function(event){													//bind keypress event
					if(event.keyCode == 13){									//if user presses enter key
						event.preventDefault();
					}
					if(event.keyCode == 13 && selectedItem !== null){									//if user presses enter key
						populateSearchField();															//populate search field
						event.preventDefault();
					}
					if(event.keyCode == 9 && selectedItem !== null){									//if user presses enter key
						populateSearchField();															//populate search field
						event.preventDefault();
					}
					if(event.keyCode == 38 && selectedItem !== null){							//if user presses up arrow
						event.preventDefault();
					}
					else if(event.keyCode == 40 && selectedItem !== null) {							//if user presses down arrow
						event.preventDefault();
					}
				}).blur(function(){																		//bind blur event to text field
					setTimeout(function(){																//hide suggestions on blur but leave time for a click event
						setSelectedItem(null);
					}, 250);
				});
				
				var iePaste = function(){
					$autofilltext.trigger("keyup",["mousepaste"]);
				}
				if(jQuery.browser.msie){
					$autofilltext[0].onpaste=function(){setTimeout(iePaste,100)};                     
				}else if(jQuery.browser.mozilla){
					$autofilltext[0].addEventListener('input',function(){$autofilltext.trigger("keyup",["mousepaste"]);},false);
				}
			});
		},

/* ********* CREATELOADING METHOD  **************** */



		createloading: function(newoptions){
			var prop = {
				loadingId: 'loadingtable',														// the id that will be added to the created table
				loadingTargetSelector: 'body',													// what the loading indicator will appear over
				loadingImage: '/marketing/images/anim-loading.gif'								// the image to use as the loading indicator
			}
			var options = {};
			jQuery.extend(options, prop, newoptions);											//overwrite the default options with any passed in options

			var $loadingImage=jQuery('<img class="dg_loadingimage" src="' + options.loadingImage + '">');	//creating the img

			var $loadingTarget = jQuery(options.loadingTargetSelector);							//the object that the  indicator will appear over

			var loadingTargetOffset =  $loadingTarget.offset()									//find the position of the element the indicator will appear over
			
			var $containTable = jQuery('<table id="' + options.loadingId + '" border="0" cellspacing="0" cellpadding="0"><tr><td></td></tr></table>');
																								//the table that will hold the indicator
			$containTable.css({																	//the css for the table
				'position': 'absolute',
				'left':loadingTargetOffset.left+'px',
				'top':loadingTargetOffset.top+'px'
			})
			jQuery("td",$containTable).css({													//the css for the td in the table
				'height': $loadingTarget.outerHeight(),
				'width': $loadingTarget.outerWidth(),
				'vertical-align': 'middle',
				'text-align': 'center'
			}).append($loadingImage);

			jQuery("body").append($containTable);

		},	
/* ********* ECOOLINGSLIDER METHOD  ***************** */


		ecoolingslider: function(newoptions){
			var prop = {													//the default properties
				fireWhen: 'onready'											//when to execute the code
			}
			var options = {};												//new object 
			jQuery.extend(options, prop, newoptions)						//extend the prop object with the newoptions object to create the options object 
			if(options.fireWhen==='onready'){
				jQuery(document).ready(function(){ECOOLING.ecoolingsliderprocess(options)})
			}else{
				ECOOLING.ecoolingsliderprocess(options)
			}
	
		},
		ecoolingsliderprocess: function(newoptions){
			var prop = {
				containerselector: '.ecoolingslider',
				panelselector: '.ecoolingsliderpanel',
				easeTime: 750,
				easeFunc: "easeInOutExpo",
				activeClass: "current",
				rotateClass: "rotator",
				rotateSpeed: 2500,
				starterClass: "starthere",
				leftArrowClass: "ec_leftarrow",
				rightArrowClass: "ec_rightarrow",
				captionpanel_leftArrowClass: "biggallery-prev",
				captionpanel_rightArrowClass: "biggallery-next",
				numberNavClass: "ec_numbernav",
				numberNavWrapClass: "ec_numbernavwrap",
				viewportClass: "ec_viewport",
				panelContainerClass: "ec_panelcontainer",
				widthOnUl: 'no',
				np_noshow: false,
				wrapArrowClass: "arrowwrap",
				wrapArrows:false,
				arrowPlacement: "outside",
				hideNumbers: false,
				hasCaptionPanel: false,
				captionContainer: "caption-content",
				captionItem: "caption-content-item"
			}
			var options = {};
			jQuery.extend(options, prop, newoptions);
	
			
			jQuery(options.containerselector).each(function(){
					
				var $currSlider = jQuery(this);
				var $containEl = $currSlider.parents("div:first");
				var isscreenshotgallery=false;
				var isquotes=false;
				var ishighlights=false;
				if($containEl.hasClass("noshownav")){
					options.np_noshow=true;
				}
				if($containEl.hasClass("gallery")){
					isscreenshotgallery=true;
				}
				if($containEl.hasClass("quotes")){
					isquotes=true;
				}
				if($containEl.hasClass("highlights")){
					ishighlights=true;
				}
				var $panels = jQuery('div'+options.panelselector,$currSlider);
				if(isquotes){
					var slideheight = $currSlider.height();
					$panels.each(function(i){
						var thisheight = jQuery(this).height();
						if(thisheight>slideheight){
							slideheight=thisheight;
						}
						$currSlider.height(slideheight);
					});
				}
				var isFader=false;
				var numPanels = $panels.length;
				if($containEl.hasClass("fader")){
					isFader=true;
					$panels.slice(1,numPanels).hide()
					$panels.each(function(i){
						jQuery(this).css({'z-index':numPanels-i})
					})
				}
				var shownav=true;
				var numPanels = $panels.length;
				if((numPanels===1)&&(options.np_noshow)){
					shownav=false;
				}
				var $leftArrow = jQuery('<div class="' + options.leftArrowClass + '"><a href="#"></a></div>');
				var $rightArrow = jQuery('<div class="' + options.rightArrowClass + '"><a href="#"></a></div>');
				if(!isscreenshotgallery&&shownav){
					if(options.wrapArrows){
						var $arrowWrapper = jQuery('<div class="'+options.wrapArrowClass+'"></div>').append($leftArrow).append($rightArrow);
					}
				}
				var $numberNav = jQuery('<ul class="' + options.numberNavClass + '"></ul>')
				var defaultSelected=false;
				var currPanel = 1;
				jQuery('div'+options.panelselector,$currSlider).wrapAll('<div class="' + options.viewportClass + '"></div>').wrapAll('<div class="' + options.panelContainerClass + '"></div>').each(function(index){
					if(jQuery(this).hasClass(options.starterClass)){
						defaultSelected=true;
						currPanel=index+1;
					}
					$numberNav.append('<li><a href="#" class="progress">' + (index+1) + '</a></li>');
				});
				var $viewport = jQuery("div."+options.viewportClass,$currSlider);
				if(!isscreenshotgallery&&shownav){
					if(options.arrowPlacement==='viewport'){
						if(options.wrapArrows){
							$arrowWrapper.appendTo($viewport);
						}else{
							$rightArrow.appendTo($viewport);
							$leftArrow.appendTo($viewport);
						}
					}else{
						if(options.wrapArrows){
							$arrowWrapper.insertAfter($currSlider);
						}else{
							$rightArrow.insertAfter($currSlider);
							$leftArrow.insertAfter($currSlider);
						}
					}
				}
				if(isscreenshotgallery&&shownav){
					jQuery("<li></li>").append($leftArrow).prependTo($numberNav)
					jQuery("<li></li>").append($rightArrow).appendTo($numberNav)
				}
				var panelWidth;
				if(jQuery.browser.safari){
					panelWidth = $currSlider.attr("rel").length>0 ? $currSlider.attr("rel") : parseInt(jQuery('div'+options.panelselector+':first',$currSlider).outerWidth());
				}else{
					panelWidth = parseInt(jQuery('div'+options.panelselector+':first',$currSlider).outerWidth())
				}
				var $panelContainer = jQuery("div."+options.panelContainerClass,$currSlider)
				jQuery("a.progress:first",$numberNav).addClass(options.activeClass);
				if(isscreenshotgallery){
					var panheightrun=function(){
						var panheight=jQuery('div'+options.panelselector,$currSlider).eq(0).outerHeight();
						jQuery('div.'+options.viewportClass,$currSlider).stop().animate({ height:panheight}, options.easeTime, options.easeFunc);
					}
					if(jQuery.browser.safari){
						setTimeout(panheightrun,500)
					}else{
						panheightrun()
					}
				}
				
				var removeFilter=function(element) {
					if(element.style.removeAttribute){
						element.style.removeAttribute('filter');
					}
				}
				//function to move the panels
				var movePanel = function(panel){
					if(isFader){
			            jQuery('div'+options.panelselector+':visible',$currSlider).fadeOut("normal");
        			    $panels.eq(panel).fadeIn("normal", function() {
							removeFilter(jQuery(this)[0]);
						});
					}else{
						var leftPos = (panel*panelWidth)*-1;
						$panelContainer.stop().animate({ left: leftPos}, options.easeTime, options.easeFunc);
						if(isscreenshotgallery){
							var panheight=jQuery('div'+options.panelselector,$currSlider).eq(panel).outerHeight();
							jQuery('div.'+options.viewportClass,$currSlider).stop().animate({ height:panheight}, options.easeTime, options.easeFunc);
						}
					}
				};
				
				//called when ever the user causes rotation
				var useraction = function(){
					if($currSlider.data("rotating")){
						$currSlider.trigger("mouseover");
					}
				};
				
				//events for numeric nav
				jQuery("a.progress",$numberNav).each(function(index){
					jQuery(this).click(function(){
						useraction();
						jQuery("a",$numberNav).removeClass(options.activeClass);
						jQuery(this).addClass(options.activeClass);
						currPanel = index+1;
						movePanel(index);
						return false;
					});					
				})

				//caption panel
				if(options.hasCaptionPanel){
					var $currentPageIndicator = jQuery("span.current-page",$currSlider).text(1);
					var $totalPagesIndicator = jQuery("span.total-pages",$currSlider).text(numPanels);
					var $captionContainer=jQuery("div."+options.captionContainer,$currSlider);
					var cp_captions=[];
					var $captions = $captionContainer.find("div."+options.captionItem).each(function(){
						var $this = jQuery(this);
						cp_captions.push($this.html());
						jQuery(this).remove();
					});
					var captionshow = function(currPanel){
						$captionContainer.fadeOut('slow',function(){
							$captionContainer.html(cp_captions[currPanel-1]).fadeIn("slow");
						});
					};
					var captionprogress = function(currPanel){
						$currentPageIndicator.text(currPanel);
						captionshow(currPanel);
					};
					captionshow(1)
				}
				
				var addclassSelector;
				
				if(shownav){
					//left arrow event
					var $leftArrowLinks;
					if(options.hasCaptionPanel){
						$leftArrowLinks = jQuery("a",$leftArrow).add("a."+options.captionpanel_leftArrowClass,$currSlider)
					}else{
						$leftArrowLinks = jQuery("a",$leftArrow)
					}
					$leftArrowLinks.click(function(){
						useraction();
						if(currPanel==1){
							currPanel=numPanels;
						}else{
							currPanel--;
						}
						jQuery("a",$numberNav).removeClass(options.activeClass);
						addclassSelector="a.progress:eq(" + (currPanel-1) + ")"
						jQuery(addclassSelector,$numberNav).addClass(options.activeClass);
						movePanel(currPanel-1);
						if(options.hasCaptionPanel){
							captionprogress(currPanel);
						}
						return false;
					});
					
					//right arrow event
					var $rightArrowLinks;
					if(options.hasCaptionPanel){
						$rightArrowLinks = jQuery("a",$rightArrow).add("a."+options.captionpanel_rightArrowClass,$currSlider)
					}else{
						$rightArrowLinks = jQuery("a",$rightArrow)
					}
					$rightArrowLinks.click(function(){
						useraction();
						if(currPanel==numPanels){
							currPanel=1;
						}else{
							currPanel++;
						}
						jQuery("a",$numberNav).removeClass(options.activeClass);
						addclassSelector="a.progress:eq(" + (currPanel-1) + ")"
						jQuery(addclassSelector,$numberNav).addClass(options.activeClass);
						movePanel(currPanel-1);
						if(options.hasCaptionPanel){
							captionprogress(currPanel);
						}
						return false;
					});
				}
				var $numberNavWrap=jQuery('<div class="' + options.numberNavWrapClass + '"></div>');
				$numberNavWrap.append($numberNav);
				if(shownav&&!options.hideNumbers){
					$currSlider.append($numberNavWrap);
				}
				$panelContainer.width(panelWidth*numPanels);
				
				var navWidth=numPanels*2;
				
				var setnavWidth = function(){
					jQuery("li",$numberNavWrap).each(function(){
						navWidth+=jQuery(this).width();
					})
					if(options.widthOnUl=='no'){
						$numberNavWrap.width(navWidth);
					}else{
						$numberNavWrap.find("ul").width(navWidth);
					}
				}
				
				if(!isscreenshotgallery){
					if(jQuery.browser.safari){
						setTimeout(setnavWidth,200)
					}else{
						setnavWidth();
					}
				}
				//selected default code
				if(defaultSelected===true){
					jQuery("a",$numberNav).removeClass(options.activeClass);
					addclassSelector="a.progress:eq(" + (currPanel-1) + ")"
					jQuery(addclassSelector,$numberNav).addClass(options.activeClass);
					var leftstatic = ((currPanel-1)*panelWidth)*-1;
					if(isscreenshotgallery){
						var panheight=jQuery('div'+options.panelselector,$currSlider).eq(currPanel-1).outerHeight();
						jQuery('div.'+options.viewportClass,$currSlider).stop().animate({ height:panheight}, options.easeTime, options.easeFunc);
					}
					$panelContainer.css({left: leftstatic+'px'});
				}
				
				//rotator code
				if($currSlider.hasClass(options.rotateClass)){
					var rotateit = function(){
						if(currPanel==numPanels){
							currPanel=1;
						}else{
							currPanel++;
						}
						jQuery("a",$numberNav).removeClass(options.activeClass);
						addclassSelector="a.progress:eq(" + (currPanel-1) + ")";
						jQuery(addclassSelector,$numberNav).addClass(options.activeClass);
						movePanel(currPanel-1);
					}
					var rotateInterval = setInterval(rotateit,options.rotateSpeed);
					$currSlider.data("rotating",true);
					$currSlider.mouseover(function(){
						clearInterval(rotateInterval)
						$currSlider.data("rotating",false);
					});
				}
				
			});
			
		}	
	},ECOOLING)
})();








