// Walton and Allen
// Main Site Javascript

$(document).ready(function() {	
	makeExtLinks();
	
	// Setup popup menus
	$(".popup").css("display","none");
	
	$(".popup").bind("mouseleave",function(){
		$(this).css("display","none");
	});

	$("#nav>ul>li>a").bind("mouseover",function(el){
		$(".popup").css("display","none");
	});
	
	$("a.has_popup").bind("mouseover",function(el){
		$(".popup").css("display","none");
		$("#popup_" + $(this).attr("id")).css("display","block");
	});
	
	$("a.has_popup").bind("click",function(el){
		el.preventDefault();
	});
	
	$("#tabs_search").tabs();
	
	if(	$("#current_search_type").val() == 'sales' ) {
		// Select sales tab
		$("#tabs_search").tabs("select",1);	
	}
});

function makeExtLinks() {
	$('.ext').click(function() {
		window.open(this.href);
		return false;
	});	
}

function initHome() {
	$("#tabs").tabs();
}

function initLandlordLogin() {
	$("#forgotten").click(function(el) {
		if(!$("#forgotten_password").is(":visible")) {
			$("#forgotten_password").fadeIn(500);
		} else {
			$("#forgotten_password").fadeOut(500);
		}
	
		return false;
	});
}

function initBlockSelection() {	
	$("input.submit").hide();
	
	$("#bid").change(function() {
		$("#building_select").submit();
	});
	$("#blid").change(function() {
		$("#block_select").submit();
	});
}

function initRecaptcha() {
	$("#recaptcha").load("/index.cfm?event=view.recaptcha");
}

function initProperty() {
	$("#property #tabs").tabs({
		cache:true
	});
	$("#property #tabs").tabs(
		"url",1,$("#mapLink").val()
	);
	
	//$("#email_page").click(function() {
	//	$("#email_area").load($("#emailPageLink").val());
	//	return false;
	//});
	
	if($("#img_nav").length) {
		$("#img_nav a").click(function() {	
			var imageDetails = $("#image" + $(this).html()).val().split("|");
			
			$("#property_image").attr("src","images/content/properties/main/" + imageDetails[0]);
			$("#enlarge").attr("href","images/content/properties/original/" + imageDetails[0]);
			$("#img_nav a").removeClass("current");
			$(this).addClass("current");
			if(imageDetails.length > 1) {
				$("#caption_area").html(imageDetails[1]);
				$("#enlarge").get(0).title = imageDetails[1];
			} else {
				$("#enlarge").get(0).title = "";
				$("#caption_area").html("");
			}
			
			$("#currentImageNo").val($(this).html());
			return false;
		});
	}
	
	$("#property_image").click(function(){
		$("#enlarge").click();
	});
	
	$("#enlarge").lightBox({
		imageBtnClose: 'images/site/lightbox-btn-close.gif'	
	});
	
	$("#print_page").click(function(){
		window.open($("#printPageLink").val(),"print","width=1000,height=300,toolbar=0,menubar=0,scrollbars=1");
		
		return false;
	});
}

function propertyIncludeDone() {
	window.setTimeout("removePropertyInclude()",5000);
}

function removePropertyInclude() {
	$(".include").fadeOut(1000);
}

