function setImagePagerText(a) {
	var b = 1;
	if(a != null) {
		b = $("div img", a)[0].id.split("_")[1]
	}$("#imagePagerIndex").text(b)
}
$(document).ready(function() {
	$("a.jsSelectOnMap").click(function(a) {
		a.preventDefault();
		scroll(0, 0);
		var b = parseInt($(this).attr("href").split("#").pop()) - 1;
		$("body").bind("mapLoadComplete", function() {
			$("body").unbind("mapLoadComplete");
			setTimeout(function() {
				selectOnMap(b)
			}, 100)
		});
		$("#resultsMapContainer").show();
		if(ajaxMapLoaded !== true) {
			a = window.location.href.replace("/listings/", "/ajax/listing/asyncmap/");
			ajaxLoadMap(a)
		}else {
			$("body").trigger("mapLoadComplete")
		}return false
	});
	$("a#map-img").click(function(a) {
		a.preventDefault();
		if(ajaxMapLoaded !== true) {
			$("#resultsMapContainer").show();
			a = window.location.href.replace("/listings/", "/ajax/listing/asyncmap/");
			ajaxLoadMap(a)
		}else {
			openBubble = null;
			map.HideInfoBox();
			$("#resultsMapContainer").toggle()
		}
	}).css({opacity:"1"});
	$("#slide-img").click(function(a) {
		a.preventDefault();
		a = $("a[@rel=gallery-listing-images]", "#listingSlideShow").get(0);
		tb_show(a.title || a.name || null, a.href || a.alt, a.rel || false);
		return false
	});
	$("#addListing", ".view-listing-buttons").click(function() {
		$("body").append('<form id="jsAddListingForm" action ="' + this.href + '" method="post"><input type="hidden" name="formredirect" value="' + window.location.href + '" /></form>').find("#jsAddListingForm").submit();
		return false
	});
	$("#saveSearch", ".view-listing-buttons").click(function() {
		$("body").append('<form id="jsSaveSearchForm" action ="' + this.href + '" method="post"><input type="hidden" name="formredirect" value="' + window.location.href + '" /></form>').find("#jsSaveSearchForm").submit();
		return false
	});
	if($("#listingCarousel").length > 0) {
		setImagePagerText();
		setTimeout(function() {
			$("#listingCarousel").jCarouselLite({btnNext:"#nextImageControl", btnPrev:"#prevImageControl", visible:1, circular:false, afterEnd:function(a) {
				setImagePagerText(a)
			}})
		}, 300);
		$("img.carouselImg", "#listingCarousel").click(function() {
			tb_show(null, this.src || this.href || null, this.rel || false);
			return false
		})
	}$("#resultSortControls #filterLaunchButton").length > 0 && $("#resultSortControls #filterLaunchButton").click(function(a) {
		a.preventDefault();
		a = "/featuredlistings";
		var b = $("#propertytypeSelect").val();
		if(b != "") {
			a = a + "/propertytype/" + b + "/"
		}window.location = a;
		return false
	});
	if($("#resultsListContainer").length > 0) {
		$("#resultsList .listing").hover(function() {
			$(this).addClass("selected")
		}, function() {
			$(this).removeClass("selected")
		});
		$("#resultSortControls #sortLaunchButton").length > 0 && $("#resultSortControls #sortLaunchButton").click(function(a) {
			a.preventDefault();
			a = $("#resultSortBySelect").val();
			a = encodeString(a);
			var b = window.location.href;
			if(b.lastIndexOf("/") == b.length - 1) {
				b = b.slice(0, b.length - 1)
			}b = b.indexOf("sort") > 0 ? b.replace(/(\/*)sort\/(\w*)\+(\w*)/, "") : b;
			window.location = b + "/sort/" + a;
			return false
		})
	}
});
