// JavaScript Document
function  parseListingsXml(xml)
{
  $(xml).find("listing").each(function()
  {
	  var title = $(this).find("title").text();
	  var mlsID = $(this).find("mlsID").text();
	  var price = $(this).find("price").text();
	  
	  var street = $(this).find("street").text();
	  var city = $(this).find("city").text();
	  var state = $(this).find("state").text();
	  var zip = $(this).find("zip").text();
	  var address = street + "<br />" + city + ", " + state + " " + zip; 
	  
	  var picasaAlbumID = $(this).find("picasaAlbumID").text();
	  var picasaAuthkey = $(this).find("picasaAuthkey").text();
	  
	  var bedrooms = $(this).find("bedrooms").text();
	  var fullbaths = $(this).find("fullbaths").text();
	  var halfbaths = $(this).find("halfbaths").text();
	  var sqft = $(this).find("sqft").text();
	  var acres = $(this).find("acres").text();
	  
	  /*bedrooms = bedrooms + " Bedrooms";
	  fullbaths = fullbaths + " Full Bath(s)";
	  halfbaths = halfbaths + " Half Bath(s)";
	  sqft = sqft + " Sq Ft";*/
	  
	  var columnOne = $("<div>").addClass("column-one");
	  var columnTwo = $("<div>").addClass("column-two");
	  
	  var listing = $("<div>").addClass("listing ui-widget ui-widget-content ui-corner-all");
	  var title = $("<h5>").addClass("title").html(title).appendTo(columnOne);
	  var price = $("<p>").addClass("price").html(price).appendTo(columnOne);
	  var address = $("<p>").addClass("address").html(address).appendTo(columnOne);
	  columnOne.appendTo(listing);
	  
	  var features = $("<ul>").addClass("features");
	  AddFeature(bedrooms,features,"Bedroom(s)");
	  AddFeature(fullbaths,features,"Full Bath(s)");
	  AddFeature(halfbaths,features,"Half Baths(s)");
	  AddFeature(sqft,features,"Sq Ft");
	  AddFeature(acres,features,"Acres");
	  features.appendTo(listing);
	  
	  var picasa = $("<div>").attr("id","albumID-" + picasaAlbumID).addClass("images").appendTo(listing);
	  
	  listing.appendTo($("#listings-container"));
	  AttachAlbum("albumID-" + picasaAlbumID, picasaAuthkey, picasaAlbumID);
  });
  
}

function AttachAlbum(domID, authkey, albumid){
	if (authkey != 'None'){
	  var str = "#" + domID;
  jQuery(str).EmbedPicasaGallery('picasa@firstgalena.com',{
  matcher:    /./,  // string or regexp matching album title    http://picasaweb.google.com/lh/sredir?uname=firstgalenapicassa&target=ALBUM&id=5440875781910940337&authkey=Gv1sRgCJrooPbdv5HkqAE&feat=email
  authkey :           authkey,
  albumid :           albumid,
  size:      '72',  // thumb size (32,48,64,72,144,160))
  loading_animation: 'css/loading.gif',
  msg_back :   'Back'
});}
}

function FormatFeature(feature, format)
{
	if (feature.length > 0) {format = feature + " " + format;};
}


function AddFeature(feature, features, format){
	if (feature.length > 0) {features.append("<li>" + feature + " " + format + "</li>");}
}

function HomeBuildingReady(){
	currentImageLeft=0;
	jQuery("#fgc-home-building-gallery").EmbedPicasaGallery('picasa@firstgalena.com',{
	matcher: /./,  // string or regexp matching album title
	albumid : '5666097578922602881',
	authkey : 'Gv1sRgCJrooPbdv5HkqAE',
	size: '144',  // thumb size (32,48,64,72,144,160))
	loading_animation: 'css/loading.gif',
	msg_back : 'Back'
	});
	$("#fgc-gallery-next").click(function() {
	var count=$("#fgc-home-building-gallery .album > div").size();
	if (currentImageLeft +1 < count) {
	$("#fgc-home-building-gallery .album div:eq(" + currentImageLeft + ")").hide();
	currentImageLeft++;
	}
	});
	$("#fgc-gallery-previous").click(function() {
	if (currentImageLeft >= 0){
	currentImageLeft--;
	$("#fgc-home-building-gallery .album div:eq(" + currentImageLeft + ")").show();}
	});
	//DrawHomeBuildingServiceArea("fgc-hb-service-area-map");  Do this in the header blocking using new method
	// add hover class to logos
	$("#logos li div").hover(
	function () {
	$(this).addClass("hover");
	},
	function () {
	$(this).removeClass("hover");
	}
	);	
}
