	function round(number,X) {
	// rounds number to X decimal places, defaults to 2
	    X = (!X ? 2 : X);
	    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}

	// Take in the full GPS coordinates, and convert to
	// latitude and longitude for Yahoo Maps
	function convertGps(gps)
	{
		// if this is already a formatted
		// latitude/longitude string, just return it
		if (!gps.match(/^N/)) {
		return gps;
		}

		//var gps = "N 39 26.16 W 82 32.43";
		degN = gps.match(/^N ([0-9]+)/);
		degW = gps.match(/W ([0-9]+)/);

		minN = gps.match(/^N [0-9]+ ([0-9\.]+)/);
		minW = gps.match(/W [0-9]+ ([0-9\.]+)/);

		latitude = (degN[1]*1.0) + minN[1]/60.0;
		longitude = (degW[1]*1.0) + minW[1]/60.0;

		latitude = round(latitude,6);
		longitude = round(longitude,6);

		longitude = '-' + longitude
		//alert(latitude + ',' + longitude);
		return latitude + ',' + longitude;
	}


	// process query strings
	var qsParm = new Array();
	function qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
	var pos = parms[i].indexOf('=');
	if (pos > 0) {
	var key = parms[i].substring(0,pos);
	var val = parms[i].substring(pos+1);
	qsParm[key] = val;
	}
	}
	}
	qs();


	// Map functions ------------------------------------------/

	// this function is used to re-bind where necessary
	function bindChange(){

		// Main category dropdown, loads m_maps_bycat.php into #mapwrap
		$("#mapcats select").change( function() {
			getMapsByCat(this.value);
		});

		// Triggers when an ajax request starts
		 $("#loading").ajaxStart(function(){
	   		$(this).show();
	 		});
	 	$("#loading").ajaxSuccess(function(){
	   		$(this).hide();
	 		});
	}

	// re-bind the business dropdown after ajax load
	function bindChange2() {
	 	$("#bizlist").change( function() {
			var parms = this.value.split(',');
			if (parms[1] == '') { parms[1] = 9; }
				zoompoint(parms[0],parms[1]);
		} );

	}

	function getMapsByCat(cat) {
			$.ajax({
			    type: "GET",
			   	url: "/lib/modules/m_maps_bycat.php",
			   	data: "cat="+cat,
			   	dataType: "html",
			   	success: function(data){
			   		$("#mapContainer").hide(); // hide the old container
					$("#mapContainer").empty();
			   		$("#mapwrap").empty();
					$("#mapwrap").html(data); // fill with maps_bycat.tpl
					bindChange2();
					$("#bizContainer").show(); // show the new map container

	   				}
			 })

	}

	

	$(document).ready(bindChange);
	
	if (qsParm['cat']) {
		getMapsByCat(qsParm['cat']);
	}
	
	$(document).ready(function() {
	
		$('input.query').click(function() {
			if ($(this).val() == 'Search') {
			$(this).val('');
			}
		});
		
		
		
	// Postcards ----------------------------------------------------------------------- */
		
		// validate signup form on keyup and submit
		$("#postcard").validate({
			event: "submit",
			rules: {
				your_name: { required: true },
				your_email: { required: true, email: true },
				rec_name: { required: true },
				rec_email: { required: true, email: true }
			},
			messages: {
				your_name: "<- Enter your name",
				your_email: "<- Enter your email address",
				rec_name: "<- Enter the recipient's name",
				rec_email: "<- Enter the recipient's email address"
			}
		});

	
	// Calendars ----------------------------------------------------------------------- */
	
		$('dl.upcoming:nth-child(even)').addClass('alt');
	
		var curdate = new Date();
		var month = curdate.getMonth() + 1;
		
		$('#gotomonth option[value='+month+']').attr('selected', 'selected');
		
		
	// Dropdown navigation ------------------------------------------------------------- */
		
		$('.sf-menu li:nth-child(even)').addClass('alt');
		
		$('ul.sf-menu').superfish({ 
			delay: 0,                            		// delay on mouseout in ms 
			animation: {opacity:'100',height:'show'},  // fade-in and slide-down animation 
			speed:'fast'                           		// faster animation speed 
		}); 


		// function for turning nav images off and on
		function activeNav(obj,state) {
			imgsrc = $(obj).attr("src");
			if (state == 'ON') {
				imgsrcON = imgsrc.replace('OFF', 'ON');
			} else {
				imgsrcON = imgsrc.replace('ON', 'OFF');
			}
			$(obj).attr("src", imgsrcON);
		}		
		
		
		// highlight active nav dropdown
	if (typeof(pageID) != 'undefined') {
		$('li.nav_'+pageID).addClass('active');
		
		
		// while hovering over dropdown items, keep the parent image highlighted
		$('ul.sf-menu ul').mouseover(function() {
			navparent = $(this).parent('li').find('img');
			activeNav(navparent,'ON');
		}); 
		
		
		$('ul.sf-menu ul').mouseout(function() {
			if (typeof(navparent) != 'undefined') {
			// find this ul's parent, then find the img within
			navparent = $(this).parent('li').find('img');
				// don't allow a rollback if it's the current section
				if ($(navparent).attr('id') != 'nav_'+section) {
				activeNav(navparent,'OFF');
				}
			}
		}); 
		
		// highlight active nav image
		$('#nav_'+section).each(function() {
			activeNav(this,'ON');
		});
		
	} // end check for pageID
		
	// Navigation Rollovers ------------------------------------------------------------- */
	
		// Preload all rollover images
		$(".navbar img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace('OFF', 'ON');
			newImg = new Image(); // create new image obj
			$(newImg).attr("src", rollON); // set new obj's src
		});
		
		$(".navbar a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			
			if (typeof(imgsrc) != 'undefined') {
			imgsrcON = imgsrc.replace('OFF', 'ON');
			$(this).children("img").attr("src", imgsrcON);
			}
			
		});
		
		// Handle mouseout
		$(".navbar a").mouseout(function(){
			if (typeof(imgsrc) != 'undefined') {
			$(this).children("img").attr("src", imgsrc);
			}
		});

		
		// renewals
		function checkBox(name,value,state) {
			currentValue = document.forms['form2'].removed.value;
			addValue = value+"|";
			//see if it's been unchecked
			if (state == false) {
				newValue = currentValue.replace(value,"");
				} else {
				newValue = addValue + currentValue;
				}
			// Strip off the last pipe
			newValue = newValue.replace(/^\||\|$/ig,"");
			newValue = newValue.replace("||","|");
			//document.forms[0].eval(attr).value=newValue;
			document.forms['form2'].removed.value=newValue
		}

		$("input.radiofee").click(function() {
			$("#feetotal1").html(this.value);
			$("#feetotal2").html(this.value);
			$("#tierfee").val('$' + this.value + '.00');
			$("#totaltier").html(this.value);

			grandtotal = parseInt($('#totaldues').html()) + parseInt($('#totalfees').html()) + parseInt($('#totaltier').html());
			$('#totalgrand').html(grandtotal);
		});
		

		
	// Members Only ------------------------------------------------------------- */	
	
	// Initially populate the word count
	$('textarea.update').each(function() {
		desc = $(this).val();
		attrID = $(this).attr('id');
		if (desc.length != 0) {
			result = desc.split(/ /);
			$('.length.'+attrID).html(result.length +' words used.');
		}
	});
	
	

	
	// count words in description field
	$('textarea.update').keyup(function(){

		desc = this.value;
		result = desc.split(/ /);
		attrID = $(this).attr('id');
		
		if (attrID == 'cText') { maxwords = 75; } else { maxwords = 15; } 
		
		if (result.length > maxwords) {
			max = desc.length;
			newdesc = desc.substring(0, max - 1);
			this.value = newdesc;
			$(".warning."+attrID).show();
		} else {
			$(".warning."+attrID).hide();
			$(".length."+attrID).html(result.length +' words used.');
		}

	});


	// Homepage Social Icons ----------------------------------------------------------------------- */
	
	$('#socialBar a').mouseover(function() {
		social = $(this).find('img').attr('alt');
		$('#socialBar li.first span').html(social);
	});
	
	$('#socialBar a').mouseout(function() {
		$('#socialBar li.first span').html('');
	});
		
	});
