﻿var UserInterface=Class.create();UserInterface.prototype={initialize:function(){this.state=0;this.inProcess=false;this.hPopupInterval=null;this.CurrentHash="";this.imageSize=270;this.isShownR=1;this.StreetViewLatLng=null;this.CurrentSlide=0;this.hSlideshowTimer=null;this.oldOffsetPosition=0;this.theOffset=63;this.locationText="";this.keepLocationText=false;this.locationTextboxId="LeftSidebarMain_txtLocation";this.locationButtonId="LeftSidebarMain_btnSearchLocation";this.keywordText="";this.keepKeywordText=false;this.keywordTextboxId="LeftSidebarMain_txtKeywords";this.keywordButtonId="LeftSidebarMain_btnKeywords";this.previewWindow=null;this.pageLinks=null;this.thumbNails=null;},searchBoxSelection:function(select){var id=select.id;if(id==this.locationTextboxId){this.locationText=select.value;this.searchBoxButtonShow(true,$(this.locationButtonId));}
else if(id==this.keywordTextboxId){this.keywordText=select.value;this.searchBoxButtonShow(true,$(this.keywordButtonId));}
select.value='';},searchBoxBlur:function(select){setTimeout(function(){UI.searchButtonClicked(select);},100);},searchButtonClicked:function(select){var id=select.id;if(id==UI.locationTextboxId){UI.searchBoxButtonShow(false,$(UI.locationButtonId));if(UI.keepLocationText){UI.keepLocationText=false;}
else{select.value=UI.locationText;}}
else if(id==UI.keywordTextboxId){UI.searchBoxButtonShow(false,$(UI.keywordButtonId));if(UI.keepKeywordText){UI.keepKeywordText=false;}
else{select.value=UI.keywordText;}}},searchBoxKeyPressed:function(event,select){var evt=event?event:window.event;if(evt.keyCode==13){var id=select.id;if(id==UI.locationTextboxId){UI.searchBoxItemPopulated();}
else if(id==UI.keywordTextboxId){UI.keepKeywordText=true;UI.searchBoxButtonShow(false,$(UI.keywordButtonId));__doPostBack('LeftSidebarMain$btnSearchLocation','');}}},searchBoxButtonShow:function(showIt,btnSearch){if(showIt){btnSearch.removeClassName("btnHide");btnSearch.addClassName("btnVisible");}
else{btnSearch.removeClassName("btnVisible");btnSearch.addClassName("btnHide");}},searchBoxItemPopulated:function(){UI.keepLocationText=true;UI.searchBoxButtonShow(false,$(UI.locationButtonId));__doPostBack('LeftSidebarMain$btnSearchLocation','');},saveSearchBoxSelection:function(select,type){if(type=='focus'){if(select.value=='My Kauai Search')
select.value='';}
else if(type=='blur'){if(select.value.length<1)
select.value='My Kauai Search';}},LoadListng:function(mlsnumber,event){if(event){if(event.stopPropagation)
event.stopPropagation();else
event.cancelBubble=true;}
window.location="#popup"+mlsnumber;},StartCheckingListing:function(){if(this.CurrentHash!=window.location.hash){if(window.location.hash.indexOf("#popup")==0){this.OpenListingPopup();}
if(window.location.hash.indexOf("#popup")==-1){this.CloseListingPopup();}
this.CurrentHash=window.location.hash;}},OpenListingPopup:function(){this.ClearPopupVars();var mlsnumber=window.location.hash.substring(6);__doPostBack('btnUpdatePopUps',mlsnumber);},CloseListingPopup:function(){$find('ListingMain_ModalPopupExtenderListing').hide();this.ClearPopupVars();},ClearPopupVars:function(){this.stopSlideShowMainImage();this.CurrentSlide=0;document.scrollTop=0;LM.dispose();SVM.dispose();},CopyToClipboard:function(){if(window.clipboardData&&clipboardData.setData)
clipboardData.setData("Text",$('ListingMain_ShareDetailsurl_copy').value);else
alert("Sorry, Your browser does not support this");},AddToFavorites:function(url,title){if(window.sidebar)
window.sidebar.addPanel(title,url,"");else if(window.external)
window.external.AddFavorite(url,title);},ChangeListingTab:function(tab){$$('#list_properties div a').each(function(el,index){if(index!=tab)el.removeClassName('selected');else el.addClassName('selected');});switch(tab){case 0:$('pictures').style.display='block';$('listingdetailsmap').style.display='none';break;case 1:$('pictures').style.display='none';$('listingdetailsmap').style.display='block';$('listingdetailsmap').style.height=432+'px';if(SVM.map==null){SVM.LoadMap();if(this.StreetViewLatLng!=null){var marker=new google.maps.Marker({position:this.StreetViewLatLng,map:SVM.map,title:"Camera Position"});var marker1=new google.maps.Marker({position:SVM.map.center,map:SVM.map,title:"Camera view point"});}}
SVM.ToggleStreetView(true,this.StreetViewLatLng);break;}},ChangePicture:function(btnId,totalPhotos){var direction=btnId.indexOf('leftArrow')>-1?'previous':'next';var prefixId=direction=='previous'?btnId.replace('leftArrow',''):btnId.replace('rightArrow','');var repeaterImage=$(prefixId.replace("__",'_ibtnMain_'));var currentImageSource=repeaterImage.src;if(currentImageSource.indexOf('noimage.jpg')>-1)
return;var pointJpgIndex=currentImageSource.indexOf('.jpg');var currentImageNumber=currentImageSource.substring(pointJpgIndex-2,pointJpgIndex);var currentImageNumberFirstChar=currentImageNumber.charAt(0).replace('0','');var currentImageNumberSecondChar=currentImageNumber.charAt(1);var ImageNumber=currentImageNumberFirstChar+currentImageNumberSecondChar;var NewImageNumber='';if(ImageNumber<totalPhotos&&direction=='next')
NewImageNumber=Number(ImageNumber)+1;else if(ImageNumber==totalPhotos&&direction=='next')
NewImageNumber='1';else if(ImageNumber>1&&direction=='previous')
NewImageNumber=Number(ImageNumber)-1;else if(ImageNumber==1&&direction=='previous')
NewImageNumber=totalPhotos;if(NewImageNumber<10)
NewImageNumber='0'+NewImageNumber.toString();repeaterImage.src=currentImageSource.replace(currentImageNumber+'.jpg',NewImageNumber+'.jpg');$('propertyimage').src=repeaterImage.src;},ListViewSort:function(column){$('LeftSidebarMain_hdnSortColumn').value=column;$('LeftSidebarMain_hdnSortDirection').value=($('LeftSidebarMain_hdnSortDirection').value=='ASC'?'DESC':'ASC');},switchMainImage:function(index,stopSlideShow){if(stopSlideShow)
this.stopSlideShowMainImage();$$('#thumbnails div.border').each(function(el,index){el.removeClassName('selected')});var images=$$('#thumbnails div.border img');if(index>=images.length)
index=0;if(index<0)
index=images.length-1;$("ListingMain_imgMain").src=images[index].src;$(images[index].parentNode).addClassName('selected');this.CurrentSlide=index;$('ListingMain_imgCounter').innerHTML=++index;},slideshowMainImage:function(){this.hSlideshowTimer=setInterval(function(){UI.switchMainImage(++UI.CurrentSlide,false);},3000);$('btnSlideshow').stopObserving('click');$('btnSlideshow').observe('click',UI.stopSlideShowMainImage.bind(this));$('btnSlideshow').update("Stop Slideshow");$('btnSlideshow').addClassName("stop");},stopSlideShowMainImage:function(){clearInterval(this.hSlideshowTimer);$('btnSlideshow').stopObserving('click');$('btnSlideshow').observe('click',UI.slideshowMainImage.bind(this));$('btnSlideshow').update("Play Slideshow");$('btnSlideshow').removeClassName("stop");},getNextMainImage:function(){this.switchMainImage(++UI.CurrentSlide,true);},getPrevMainImage:function(){this.switchMainImage(--UI.CurrentSlide,true);},GetCurrentMapBounds:function(){var map=null;if(WM.CurrentView=="map")
map=GM;else if(WM.CurrentView=="list")
map=GML;if(map!=null){var bounds=map.GetMapBounds();var currentBounds=bounds.A+","+bounds.S+","+bounds.W+","+bounds.N+","+bounds.E;$('LeftSidebarMain_hdfMapInfo').value=currentBounds;}},SetListingDetailsSearchSlide:function(page,aimate){if(aimate){offset=page*-540;new Effect.Move('search_results_world',{x:0,y:offset,mode:'absolute'});}
else{$('search_results_world').style.top=page*-540+"px";}
$$('span.results_links a').each(function(el,index){if(page==index)
el.addClassName("active");else
el.removeClassName("active");});return false;},slideElementRegisterPopup:function(el,direction){if(direction=="up"){new Effect.SlideUp(el);}
else if(direction=="down"){new Effect.SlideDown(el);}
else{alert("wrong parameter input");}},showHideMoreInfoInSidebar:function(el,hideShow){if(hideShow=="hide"){$(el).hide();}
else{$(el).appear();}},ShowHideSearchDropdown:function(el){if($(el).hasClassName('show')){$(el).removeClassName('show');$(el).addClassName('hide');}else{$(el).removeClassName('hide');$(el).addClassName('show');}},ExpandNavigationMenu:function(el,state){if(state=="show")
$(el).show();else
$(el).hide();},ShowDetailsInstant:function(link){this.previewWindow=window.open(link,'','width='+screen.width+',height='+screen.height+',scrollbars=yes,toolbar=no,location=no,status=no,directories=no,resizable=no');setTimeout(function(){UI.setWindow},200);},SetWindow:function(){UI.previewWindow.focus();},SetStatusCheckboxesState:function(){if(!$find("LeftSidebarMain_chkActive").get_Checked()&&!$find("LeftSidebarMain_chkEscrow").get_Checked()&&!$find("LeftSidebarMain_chkSold").get_Checked()){$find("LeftSidebarMain_chkReduced").set_Enabled(false);$find("LeftSidebarMain_chkDistressed").set_Enabled(false);}
else{$find("LeftSidebarMain_chkReduced").set_Enabled(true);$find("LeftSidebarMain_chkDistressed").set_Enabled(true);}},resizeIframe:function(frameid){try{var currentfr=document.getElementById(frameid);if(currentfr&&!window.opera){currentfr.style.float="left";}
if(currentfr.contentDocument&&currentfr.contentDocument.body.offsetHeight){currentfr.style.height=(currentfr.contentDocument.body.offsetHeight+20)+"px";}
else if(currentfr.Document&&currentfr.Document.body.scrollHeight){currentfr.style.height=currentfr.Document.body.scrollHeight+"px";}}
catch(err){}},setNearbyListingsLink:function(page,pageLinks){pageLinks.each(function(s){s.removeClassName('active');});pageLinks[page].addClassName('active');}};
