
var CURRENT_PHOTO="photo0";var current_photo_index=0;var TOTAL_PHOTOS;var SCROLL_TIMER;var STEP_INTERVAL=30;var STEP_WIDTH=20;var SLIDE_WIDTH=85;var NUMBER_IN_TRAY=5;function swapMainPhoto(img_src){$("photo").src=img_src;}
function highlightThumb(thumb_id){$(CURRENT_PHOTO).toggleClassName('selected');$(thumb_id).toggleClassName('selected').blur();CURRENT_PHOTO=thumb_id;}
function previousPhoto(){current_photo_index--;if(current_photo_index>=0){var previous_photo_id="photo"+(current_photo_index);var previous_photo_src=$(previous_photo_id).rel;swapMainPhoto(previous_photo_src);highlightThumb(previous_photo_id);nudgeSlider(current_photo_index);}else{current_photo_index=0;}}
function nextPhoto(){current_photo_index++;if(current_photo_index<TOTAL_PHOTOS){var next_photo_id="photo"+(current_photo_index);var next_photo_src=$(next_photo_id).rel;swapMainPhoto(next_photo_src);highlightThumb(next_photo_id);nudgeSlider(current_photo_index);}else{current_photo_index=TOTAL_PHOTOS-1;}}
function nudgeSlider(photo_index){if(TOTAL_PHOTOS<=NUMBER_IN_TRAY){return;}
var number_to_center=Math.round(NUMBER_IN_TRAY/2-1);var multiplier=-photo_index+number_to_center;if(photo_index<number_to_center){multiplier=-photo_index+(number_to_center-photo_index);}
if(photo_index>=TOTAL_PHOTOS-number_to_center){multiplier=-photo_index+(TOTAL_PHOTOS+(number_to_center-photo_index));}
if(photo_index==0){multiplier=0;}
var new_pos=multiplier*SLIDE_WIDTH;$("thumbSlider").setStyle({left:new_pos+"px"});}
function scrollForward(){var slider_width=$("thumbSlider").getWidth();var tray_width=$("thumbTray").getWidth();var left_end=tray_width-slider_width;var slider_left_pos=parseInt($("thumbSlider").getStyle("left"));if(left_end<slider_left_pos){if(left_end+STEP_WIDTH>=slider_left_pos){var partial_step=slider_left_pos-left_end;$("thumbSlider").setStyle({left:slider_left_pos-partial_step+'px'});}else{$("thumbSlider").setStyle({left:slider_left_pos-STEP_WIDTH+'px'});SCROLL_TIMER=setTimeout('scrollForward()',STEP_INTERVAL);}}}
function scrollBackward(){var right_end=0;var slider_left_pos=parseInt($("thumbSlider").getStyle("left"));if(slider_left_pos<right_end){if(slider_left_pos>=right_end-STEP_WIDTH){var partial_step=right_end-slider_left_pos;$("thumbSlider").setStyle({left:slider_left_pos+partial_step+'px'});}else{$("thumbSlider").setStyle({left:slider_left_pos+STEP_WIDTH+'px'});SCROLL_TIMER=setTimeout('scrollBackward()',STEP_INTERVAL);}}}
function scrollStop(){clearTimeout(SCROLL_TIMER);}
function attachListingDetailEvents(page_context){CURRENT_PHOTO="photo0";current_photo_index=0;if($("TOTAL_PHOTOS")){TOTAL_PHOTOS=$("TOTAL_PHOTOS").getValue();}
if($("btnPreviousPhoto")){$("btnPreviousPhoto").observe('click',function(event){Event.stop(event);previousPhoto();$("btnPreviousPhoto").blur();});}
if($("btnNextPhoto")){$("btnNextPhoto").observe('click',function(event){Event.stop(event);nextPhoto();$("btnNextPhoto").blur();});}
if($("btnScrollBackward")){$("btnScrollBackward").observe('mouseover',function(){scrollBackward();});$("btnScrollBackward").observe('mouseout',function(){scrollStop();});}
if($("btnScrollForward")){$("btnScrollForward").observe('mouseover',function(){scrollForward();});$("btnScrollForward").observe('mouseout',function(){scrollStop();});}
$$('#thumbSlider a').each(function(s){s.observe('click',function(event){Event.stop(event);current_photo_index=parseInt((s.id).substr(5));swapMainPhoto(s.rel);highlightThumb(s.id);});});if($("btnSaveListingNeedLogin")){$("btnSaveListingNeedLogin").observe('click',function(event){alert("You must login/register before you can save listings");Event.stop(event);});}
if($("btnSaveListing")){$("btnSaveListing").observe('click',function(event){Event.stop(event);var listing_id=$("btnSaveListing").rel;var mlsparts=listing_id.split("_",2);var mls_id=mlsparts[0];var mls_no=mlsparts[1];saveThisListing(mls_id,mls_no);});}
if($("btnRequestMoreInfo")){$("btnRequestMoreInfo").observe('click',function(event){Event.stop(event);popWindow("btnRequestMoreInfo");});}
if($("btnScheduleAShowing")){$("btnScheduleAShowing").observe('click',function(event){Event.stop(event);popWindow("btnScheduleAShowing");});}
if($("btnCalculators")){$("btnCalculators").observe('click',function(event){Event.stop(event);popWindow("btnCalculators");});}
if($("btnTellAFriend")){$("btnTellAFriend").observe('click',function(event){Event.stop(event);popWindow("btnTellAFriend");});}
if($("btnBackToResults")&&page_context=="map"){$("btnBackToResults").observe('click',function(event){Event.stop(event);toggleFrame("Map");});}}
Event.observe(window,'load',function(){attachListingDetailEvents();});