    function nextImage() {
    	if (current_image < photos.length - 1) {
    		deSelectImage(current_image);
    		current_image++;
    	}
    	checkNextPrev();
    	selectImage(current_image);
    }

    function prevImage() {
    	if (current_image > 1) {
    		deSelectImage(current_image);
    		current_image--;
    	}
    	checkNextPrev();
    	selectImage(current_image);
    }
    

	function clickImage(i) {
		deSelectImage(current_image);
    	current_image = i;
    	checkNextPrev();
    	selectImage(current_image);
    }
    
    function reDrawThumbs() {
		var img_start = img_left;    	
    	for (i = 1; i <= 4; i++) {
			var s = '<a href="#" onclick="clickImage(' + img_start + '); return false;"><img id="photo_frame_img_' + img_start + '" src="http://images.newhomesmatch.com/thumbnail.php?filename=' + photos[img_start] + '&w=60&h=50&prop=1" alt="Project Photo" style="border: 1px solid #4a4c4b;"/></a>';
    		$('photo_frame_' + i).innerHTML = s;
    		img_start++;
    	}
    }
    
    function deSelectImage(i) {
    	$('photo_frame_img_' + i).style.border = '1px solid #4a4c4b';
    	//$('photo_frame_img_' + i).style.width = '60px';
    }
    
    function selectImage(i) {
    	//alert(typeof ($('photo_frame_img_' + i)));
    	if (!document.getElementById('photo_frame_img_' + i)) return;
    	$('photo_frame_img_' + i).style.border = '4px solid #ff7b40';
    	//$('photo_frame_img_' + i).style.width = '52px';
    }
    
    function checkNextPrev() {
    	var img = new Image();
    	//alert(photos[current_image]);
    	img.src = "http://images.newhomesmatch.com/thumbnail.php?w=300&h=250&filename=" + photos[current_image] + '&prop=1';
		//if (current_image == 1) document.getElementById('btn_prev').disabled = true;
		//else document.getElementById('btn_prev').disabled = false;
		//if (current_image == photos.length - 1) document.getElementById('btn_next').disabled = true;
		//else document.getElementById('btn_next').disabled = false;
		document.getElementById('curr_photo').innerHTML = current_image + ' of ' + total_images;
		document.getElementById('big_image_img').src = img.src;
		if (current_image > img_right) {
			img_right = current_image;
			img_left = img_right - 3;
			reDrawThumbs();
		}
		else {
			if (current_image < img_left) {
				img_left = current_image;
				img_right = img_left + 3;
				reDrawThumbs();
			}
		}
    }

    
    
    function showSTAF(obj, val) {
    	if ($('send_to_a_friend_div')) {
    		$('staf_comm_id').value = val;
    		$('send_to_a_friend_div').style.display = 'block';
    		return;
    	}
    	var s = '<div style="text-align: center; float: left; padding-left: 10px; font-weight: bold;">Send to a friend</div><div style="text-align: right; float: right; padding-left: 5px; padding-right: 5px;"><a href="#" onclick="hideSTAF(); return false;">x</a></div><div style="padding: 10px; text-align: left; clear: both; font-style: italic; font-size: 13px;"><input type="hidden" id="staf_comm_id" value="0"><b>Note:</b> To send to more than one person, separate addresses with a comma.<br /><table border="0" cellpadding="3" cellspacing="0"><tbody><tr><td align="left" style="white-space: nowrap; font-style: normal;">Send to:</td><td align="left"><input id="staf_to"></td></tr><tr><td align="left" style="white-space: nowrap; font-style: normal;">Your E-mail:</td><td align="left"><input id="staf_email"></td></tr><tr><td align="left" style="white-space: nowrap; font-style: normal;">Your Name:</td><td align="left"><input id="staf_name"></td></tr><tr><td align="left" style="white-space: nowrap; font-style: normal;">Subject:</td><td align="left"><input id="staf_subj"></td></tr><tr><td align="left" style="white-space: nowrap; font-style: normal;">Comments:</td><td align="left"><input id="staf_comm"></td></tr><tr><td align="right" colspan="2"><input type="button" onclick="sendEmail(); return false;" value="Send" /></td></tr></tbody></table></div>';
    	var div = document.createElement('div');
    	div.innerHTML = s;
    	div.id = "send_to_a_friend_div";
    	div.style.width = '280px';
    	div.style.backgroundColor = '#FFFFFF';
    	div.style.position = 'absolute';
    	div.style.zIndex = '10000';
    	div.style.border = '1px solid #000000';
		document.body.appendChild(div);
    	x = parseInt(screen.width / 2 - 140);
    	y = parseInt(screen.height / 2 - $('send_to_a_friend_div').offsetHeight);
    	div.style.top = y + 'px';
    	div.style.left = x + 'px';
    	$('staf_comm_id').value = val;
    }
    
    function hideSTAF() {
    	$('send_to_a_friend_div').style.display = 'none';
    	$('staf_comm_id').value = 0;
    }
    
    function sendEmail() {
    	xajax_sendEmail($('staf_to').value, $('staf_email').value, $('staf_name').value, $('staf_subj').value, $('staf_comm').value, $('staf_comm_id').value);
    }

    
    function check_selected() {
    	var i = 1;
    	var j = 0;
    	el = document.getElementById("plan_sel_" + i);
    	while (el) {
    		if (el.checked) {
    			j++;
    		}
    		i++;
	    	el = document.getElementById("plan_sel_" + i);
    	}
    	if (j > 3) {
    		alert("You can't select more then three projects to compare!");
    		return false;
    	}
    	return true;
    }
    
	function changeLoc(loc) {
		window.location.href = loc;
	}
    
   
    
    function getPlanInfo(plan) {
    	xajax_getPlanDetails(plan);
    }
    
//jQuery.fn.center = function()
//{
//    this.css("position","absolute");
//    this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
//    this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
//    return this;
//}
    
    
    function show_plan_div() {
    	$("plan_div").style.display = 'block';
    	$("plan_div").style.position = 'absolute';
    	document.body.appendChild($("plan_div"));
//    	$("plan_div").center();
    	var canvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
    	//alert(dump(canvas, "canvas"));
    	$("plan_div").style.top = canvas.scrollTop + 100 + 'px';
    	$("plan_div").style.left = parseInt(canvas.scrollTop / 2 - 250) + 'px';
		DragHeader.init($("drag_header"), $("plan_div"));    	
    }
    
    function hide_plan_div() {
    	document.getElementById("plan_div").style.display = 'none';
    }
    

function dump(obj, obj_name) {
  var result = "";
  for (var i in obj)
    result += obj_name + "." + i + " = " + obj[i] + "\n";
  return result;
}    
    
    function LocalResult(result, lrIcon) {
      this.result_ = result;
      //alert(dump(result));
//      alert(dump(result.phoneNumbers[0]));
      this.resultNode_ = this.unselectedHtml();
      gMap.addOverlay(this.marker(lrIcon));
      
    }

    LocalResult.prototype.marker = function(opt_icon) {
      if (this.marker_) return this.marker_;
      var marker = new GMarker(new GLatLng(parseFloat(this.result_.lat),
                                         parseFloat(this.result_.lng)),
                               opt_icon);
      GEvent.bind(marker, "click", this, function() {
        marker.openInfoWindow(this.selected() ? this.selectedHtml() :
                                                this.unselectedHtml());
      });
      this.marker_ = marker;
      return marker;
    }

    LocalResult.prototype.select = function() {
      if (!this.selected()) {
        this.selected_ = true;

        // Remove the old marker and add the new marker
        gMap.removeOverlay(this.marker());
        this.marker_ = null;
        gMap.addOverlay(this.marker(G_DEFAULT_ICON));

        // Add our result to the saved set
        document.getElementById("selected").appendChild(this.selectedHtml());

        // Remove the old search result from the search well
        this.resultNode_.parentNode.removeChild(this.resultNode_);
      }
    }

    LocalResult.prototype.unselectedHtml = function() {
      var container = document.createElement("div");
      container.className = "unselected";
      container.appendChild(this.result_.html.cloneNode(true));
//      var saveDiv = document.createElement("div");
//      saveDiv.className = "select";
//      saveDiv.innerHTML = "Save this location";
//      GEvent.bindDom(saveDiv, "click", this, function() {
//        gMap.closeInfoWindow();
//        this.select();
//        gSelectedResults.push(this);
//      });
//      container.appendChild(saveDiv);
      return container;
    }

    // Returns the HTML we display for a result after it has been "saved"
    LocalResult.prototype.selectedHtml = function() {
      return this.result_.html.cloneNode(true);
    }

    // Returns true if this result is currently "saved"
    LocalResult.prototype.selected = function() {
      return this.selected_;
    }
    
