﻿
$(document).ready(function() {

	$(".categoryListLink").click(function(e) {
		if (e.which){
			if (e.which != 1){
				return false;
			}
		}
        
		$.get($(this).attr("href"), function(response) {
			$("#resultscontainer").html(response);
		});

		//update breadcrumb
		var locationArray = $(this).attr("href").toString().split("/");
		var locationString = locationArray[locationArray.length - 1];

		$("#CategoryName").html(locationString);
		document.title = 'Yellow Pages - ' + Encoder.htmlDecode(locationString) + ' - Search the Guernsey Directory - Sure'; 

		$(".categoryListLink").each(function() {
		    $(this).removeClass($(this).attr("title") + "active");
		});

		$(this).addClass($(this).attr("ID"));
		recordAjaxNav($(this).attr("href"));
		return false;

	});

	$(".categoryListSearchLink").live("click", function(e) {

		if (e.which){
			if (e.which != 1){
				return false;
			}
		}


		$("#results").html("<div class='mainContentLoading'>");
		$.get($(this).attr("href"), function(response) {
		    $("#results").html(response);
		    initializeMarkers();
        });
        
        //update breadcrumb
		var locationArray = $(this).attr("href").toString().split("/");
		var locationString = locationArray[locationArray.length-1];

		$("#CategoryName").html($(this).html());
		document.title = 'Yellow Pages - ' + Encoder.htmlDecode($(this).html()) + ' - Search the Guernsey Directory - Sure'; 

		$(".categoryListSearchLink").removeClass("active");
		$(this).addClass("active");

		recordAjaxNav($(this).attr("href"));
		return false;

	});


	$("#results a.page-nav").live("click", function() {

		$.get($(this).attr("href"), function(response) {
			$("#results").html(response);
			initializeMarkers();
		});


		recordAjaxNav($(this).attr("href"));
		return false;

	});
});
