// General Javascript for Saddlebrook Website
//
$(document).ready(function() {


//
// Floorplan Style Name Addition

$(".floorplanImg img").each(function(){
	var imgalt = $(this).attr("alt");
    $(this).parent("a").append("<br />"+imgalt);
});




//
// Border Removal

	$("#navigation li:last a").css("border","0");
		$("#footer ul li:first").css("padding","0 20px 0 0");
		$("#footer ul li:last").css("borderRight","0");
		$("#communityNav a:last").css("borderRight","0");
	$("#plans .floorplan:last").css("borderBottom","0");


$(".comAdjust").click(function(e){e.preventDefault(); return false;});
$(".dropMenu").parent("li").hover(function(){
	$(this).find(".Dropdown").stop(true,true).slideDown(250);
	},function(){
	$(this).find(".Dropdown").stop(true,true).slideUp(250);

	});




//
// Info Buttons on Community Pages - Sliding Effects

$("#communityInfo").hide();

//$("#communityInfoButton").click(function(event){
//	event.preventDefault();
//	$("#communityPhoto").toggle();
//	$("#communityInfo").toggle();
//	});





//
//	Load Gallery for Community

$("#communityGallery").hide();
$("#galleryButton").click(function(){
	var	galDir	=	$("#galleryButton").attr("rel");
	$("#communityGallery").html("<iframe src='galleries/"+galDir+"/index.html' width='645' height='630'></iframe>");
	});

$("#communityNav .sliderButton").click(function(event){
		event.preventDefault();

		var CIstatus = $("#communityInfo").css("display");
		var CGstatus = $("#communityGallery").css("display");

		if	($(this).attr("id") == "galleryButton") {
				if(CGstatus == "none"){
					$(".communitySlider li").hide();
					$("#communityGallery").show();
				}else if (CGstatus == "list-item"){
					$(".communitySlider li").hide();
					$("#communityPhoto").show();
				}


		}else if ($(this).attr("id") == "communityInfoButton") {
				if(CIstatus == "none"){
					$(".communitySlider li").hide();
					$("#communityInfo").show();
					$(".communitySlider li ul li").show();
				}else if (CIstatus == "list-item"){
					$(".communitySlider li").hide();
					$("#communityPhoto").show();
				}

		}


});








//
// Ask Heather Popup - Homepage
$(".askHeatherPopup").hide();
$(".askHeatherBox").hover(
      function () { $(".askHeatherPopup").show(); },
      function () { $(".askHeatherPopup").hide(); }	  );

$(".askHeatherPopup").hover(
      function () { $(".askHeatherPopup").show(); },
      function () { $(".askHeatherPopup").hide(); }   );






//
// Image Tabs for Floor Plans
$(".xlrgImages img").each(function(){
	var imgAlt = $(this).attr("alt");
	$(this).parent("li").attr("id", ""+imgAlt);
	});

$("#tabs li:first").addClass("active");


$("#tabs a").click(function(event){
		event.preventDefault();

		$("#tabs li").removeClass("active");
		$(this).parent("li").addClass("active");

		var imgToView	=	$(this).attr("href");
			$(".xlrgImages li").fadeTo(700, 0).slideUp("fast");
			$("li"+imgToView).slideDown("fast").fadeTo(700, 1);


});







//
//	Previous Page Button

$(".backButton").click(function(event){
	event.preventDefault();
	history.go(-1)
	});




//
//	Sidebar Height
var contentHeight	=	$("#thinPage #content").height();
	$(".side").height(contentHeight - 520);



//
//	Defination list expand/collapse

	$("dd").hide();
	$("dt").each(function(){
		$(this).wrapInner("<a href='' class='dlist'></a>");
	});

	$(".dlist").click(function(event){
		event.preventDefault();
		var targetDD	=	$(this).parent("dt").next("dd");
		$("dd").not(targetDD).slideUp("fast");
    	$(targetDD).slideToggle("fast");
	});









//
//	Current Page Highlighting
//		!!!! - -	MAKE ANY CHANGES BELOW IN COMMUNITY LISTING MENU ALSO 	- - !!!!

var url = location.href;
var lastSlash = url.lastIndexOf("/");
var lastMark = url.lastIndexOf("-");

var firstQuestionMark = url.indexOf("?");
if(firstQuestionMark == -1) {firstQuestionMark = url.length;}

var fileName = url.substring(lastSlash + 1, firstQuestionMark);
var parentFile = url.substring(lastSlash + 1, lastMark);
var cityName = $("body").attr("id");


//
//	Community Listing Menu

/*	$("#communityListing").load("communities.html #communityListingMain");

	$("#communityListing").load("communities.html #communityListingMain", function(){
		//	Get the city from the Body ID, Collapse/Expand the appropriate Navigation
			var cityName = $("body").attr("id");

				if (cityName ==""){
				}else {
					$(".communitiesByCity").hide();
					$("#communityListingMain").find("h3").addClass("inactive");
					$("."+cityName+" .communitiesByCity").show();
					$("."+cityName+" h3").removeClass("inactive");
				}


		$("#communityListingMain h3").click(function(event){
			$(this).toggleClass("inactive");
			$(this).next(".communitiesByCity").slideToggle("slow");
		});


	});


*/




//
//	Community by City Hide/Expand


$(".sidebar .arrowList a[href='"+fileName+"']").parent("li").addClass("highlight");
$(".sidebar .arrowList a[href='"+parentFile+".html']").parent("li").addClass("highlight");
if (cityName ==""){
	}else {
		$(".communitiesByCity").hide();
		$("#communityListingMain").find("h3").addClass("inactive");
		$("."+cityName+" .communitiesByCity").show();
		$("."+cityName+" h3").removeClass("inactive");
	}

$("#communityListingMain h3").click(function(event){
	$(this).toggleClass("inactive");
	$(this).next(".communitiesByCity").slideToggle("slow");
	});










//
//	Homeworks Collector Ajax
$(".homeworks").hide();

 $(".homeworksInfo").submit(function(event){
	event.preventDefault();

	var name = $("#name").val();
	var email = $("#email").val();
	var address = $("#address").val();
	var phone = $("#phone").val();
	var state = $("#state").val();
	var city = $("#city").val();
	var zip = $("#zip").val();
	
	if ( name == "") {
		$("#name").addClass("error");	
		return;
	}
	else if ( email == "") {
		$("#email").addClass("error");	
		return;
	}
	else {
	
     $("#homeworksResponse").load("./contact/phpMailSendandLog-ajax.php", {name: ""+name+"", email: ""+email+"", address: ""+address+"", state: ""+state+"", city: ""+city+"", zip: ""+zip+"", phone: ""+phone+""}, function(){
			$(".homeworksInfo").hide();
			$(".homeworks").show();
			});
	}
 	});





//
//	Best Value Changer

$("#bestValueList .communityIndividualPrice").hide();
$(".communityIndividualPrice[rel='gb']").show()
$("#bestValueCommunities a[rel='gb']").addClass("active");

$("#bestValueCommunities a").click(function(e){
	e.preventDefault();

	var selectCommunity = $(this).attr("rel");
	$(".floorplan").fadeOut(500);
		$("#bestValueCommunities a").removeClass("active");	
		$("#bestValueCommunities a[rel='"+selectCommunity+"']").addClass("active");
			setTimeout( function(){ 
				$(".communityIndividualPrice").hide();  
				$(".communityIndividualPrice[rel='"+selectCommunity+"']").show(); 
				}, 500);
		$(".floorplan").fadeIn(500);
	return false;

	});





//
//	Community Links for MIR homes

	$(".communityAnchor").each(function(){
		var loc = $(this).attr("name");
		var name = $(this).next("h2").text();
		$("#comList").append("<li><a href='#"+loc+"'>"+name+"</a></li>");
	});











//
//	Numbered list for communities page


	//	1 - target only the communities page
	
	$(".numListReplace li").each(function(){
		var numero = $(this).index();
	//	2 - remove the background images from list elements
		$(this).css("background-image","none");	
		var height	=	$(this).height();
		
	//	3 - add spans with numbers generated from reading the list
		$(this).find("a").prepend("<span class='numero'>"+numero+"</span>");
		
		$(this).find(".numero").css("height", height);
		
	});





$(".soldHome").hide(function(){
	$(this).parent("h4").before("<div class='replaceSold'></div>");	
	});



$(".soldHome2").hide(function(){
	$(this).parent("h4").before("<div class='replaceSold2'></div>");	
	});






//
//	Little Tweeks
$(".realtor p:last").css("marginBottom","0px");
$(".communityLogo + p").css("width","400px");
$(".communityLogo + ul").css("width","400px");


//
//	Browser Detector

var os = $.browser.OS();
	if (os == "Mac") {
		$("#navigation a").css("padding","10px 27px");
	}else if (os == "Windows")	{
		$("#navigation a").css("padding","10px 28px");
	}

});
