﻿var photoArray = null;
var photoCount = null;
var currentPhotoIdx = 0;
var OnSlideShow = false;

$(document).ready(function() {
        photoArray = $(".detThbs li img").get();
        photoCount = $(".detThbs li img").size();
        $("#thumbnails").jCarouselLite({
            btnNext: "#thbForward",
            btnPrev: "#thbBack",
            mouseWheel: true,
            speed: 300,
            visible: 4,
            scroll: 1,
            circular: false
        }); 
        
       $("#aPropertyNote").click(function(e)
       {
        var height = $('#divNote').height();
        var width = $('#divNote').width();
        leftVal = ($("#container").width() / 2) +"px";
        topVal = "400px"; 
        $('#divNote').css({left:leftVal,top:topVal}).fadeIn(250);
       });           
       
       $("#detPropDetails div ul").each(function(){
            if ($(this).children("li").size()<=1)
            {
                $(this).hide();
            }
       })

       if ($("#voiceGuidePanel p").html()!="")
       {
            $("#voiceGuidePanel").css("height","24px");
       }
       //photoArray = $(".detThbs li img").get();
       //photoCount = $(".detThbs li img").size();
       
       var SearchType = getQuerystring("searchType", "");
       if (SearchType.toLowerCase()=="map")
       {
            $("#searchTools .RegularSearch").hide();
            $("#searchTools .MapSearch").show();
       }
       
    });


    function GotoProperty(idx, max)
    {  
        
        val = getQuerystring("PropertyIdx");
      
        if(val != "")
        {   
           
            newval = parseInt(val) + idx; 
            if(newval <= 0) newval = 1;
            if(newval >=max ) newval = max;
            querystring = ReplaceQueryString(location.href, "PropertyIdx", newval);
        }
        else
        {
            querystring = ReplaceQueryString(location.href, "PropertyIdx", "1");
        }
        querystring = ReplaceQueryString(querystring, "PropertyDetail", "").replace("&PropertyDetail=", "");
        
        
        location.replace(querystring)
    }
    
    function BackToResults()
    {
        queryString = ReplaceQueryString(location.search, "PropertyIdx", "");
        queryString = ReplaceQueryString(queryString, "PropertyItem", "");
        queryString = ReplaceQueryString(queryString, "PropertyDetail", "").replace("&PropertyDetail=", "");
        location.replace("PropertyResult.aspx" + queryString);
    }
    
    function GoRefineSearch() {
       var tab = getQuerystring("SearchPageName", "PropertySearch.aspx");
       var BackToResultString = window.location.href;
       BackToResultString = BackToResultString.replace(/propertydetail.aspx/i,tab);
       window.location = BackToResultString;
    }

    function Propertyprint()
    {   
       // alert(location.search);
        window.open("PropertyPrint.aspx" + location.search,'Print','','');
    }


 function StartSlideShow()
 {

    $("#imgPlayGallery").hide();
    $("#imgPauseGallery").show();
    if (currentPhotoIdx >= photoCount) currentPhotoIdx = 0;
    if (currentPhotoIdx < 0) currentPhotoIdx = photoCount - 1;     
    if(currentPhotoIdx > -1 && currentPhotoIdx <= photoCount - 1 && photoCount > 0 && OnSlideShow)
    {
        $("#MainImage").attr("src", photoArray[currentPhotoIdx].src.replace("?thumb",""));
        currentPhotoIdx++;
       
        setTimeout("StartSlideShow()", 3000);        
    }
    else
    {
        $("#imgPauseGallery").hide();
        $("#imgPlayGallery").show();
        currentPhotoIdx=0;
    }               
 }
 
 function SetCurrentPhoto(src)
 {
    for(i=0; i<photoCount; i++)
    {
        if(src == photoArray[i].src) 
        {
            currentPhotoIdx = i;
            break;
        }
    }
 }
 
 function GotoPhoto(idx)
 {
    OnSlideShow = false;
    SetCurrentPhoto($("#MainImage").attr("src"));
    currentPhotoIdx = currentPhotoIdx + idx;
    if (currentPhotoIdx >= photoCount) currentPhotoIdx = 0;
    if (currentPhotoIdx < 0) currentPhotoIdx = photoCount - 1;
    if(currentPhotoIdx > -1 && currentPhotoIdx <= photoCount - 1 && photoCount > 0)
    {
        $("#MainImage").attr("src", photoArray[currentPhotoIdx].src.replace("?thumb",""));
    }
 }
 function SetShowingTime(siteid,csource,BoardId, MlsNumber, Broker){
    var oImgShowingTime = new Image(10,10);
   
    oImgShowingTime.src = "http://links.showingtime.com/showingalert/images/wbShowingAlert_dtl.gif?SITEID="+ siteid +"&broker=" + Broker  + "&MLSID=" + BoardId + "&listingid=" + MlsNumber + "&source=" + csource + "";
}
