$(document).ready(function(){
		// Navigation rollovers
		$("#nav a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			if (imgsrc) {
			matches = imgsrc.match(/_ON/);
			// don't do the rollover if state is already ON
			if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // strip off .gif
			$(this).children("img").attr("src", imgsrcON);
			}
		}
		});
		$("#nav a").mouseout(function(){
			if (!matches) {
			$(this).children("img").attr("src", imgsrc);
			}
		});

		// Determine the active section button
		if (location.pathname.substring(1)) {
			// get the path
			thePath = location.pathname.substring(1);
			thePath = thePath.match(/^\/?([a-z0-9_\.-]+)/); // only get the first part of the path
			thePath = '/' + thePath[0];
			navLink = $('#nav a[@href$="' + thePath + '"]');
			imgsrc = $(navLink).children("img").attr("src");
			if (imgsrc) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_ON.gif"); // strip off .gif
			$(navLink).children("img").attr("src", imgsrcON);
			}
		}

	// Table striping
	$("table.business").find("tr:odd").addClass("alt").end;
	//$("table.business").find("th:even").css({ background: "#FFFFFF", padding: "0" });
	$("table.business").find("tr:last").css({ background: "#FFFFFF", padding: "0" });

	// handle opening and closing of business detail records
	visible = '';
	$('.views a').click(function(){
		cid = $(this).attr("id");

		if (cid != visible) {
			$.get("/lib/modules/m_business_detail_ajax.php", { cid: cid }, function(data){
				// dump ajax data into container div
				$('#detail'+cid).html(data);

				// show the div
				$('#detail'+cid).slideDown();

				// Hide whatever other pane is open
				if (visible != '') {
					$('#detail'+visible).slideUp();
					//$('#detail'+visible+' .container').html('');
					}
				visible = cid;
				});
			}
	});

	$('.close a').click(function(){
		$('#detail'+visible).slideUp();
		//$('#detail'+visible+' .container').html('');
		visible = '';
	});

	});

	// 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() {
	// Business list dropdown
	$("#bizlist").change( function() {
			zoompoint(this.value);
		} );
	}


	// Main category dropdown, loads m_maps_bycat.php into #mapwrap
	function getMapsByCat(cat) {
		$.ajax({
		    type: "GET",
		   	url: "/lib/modules/m_maps_bycat.php",
		   	data: "cat="+cat,
		   	dataType: "html",
		   	success: function(data){

				$("#mapwrap").html(data);
				bindChange2();
   				}
		 })

	}

	$(document).ready(bindChange);
