﻿    var YelpLoaded = new Array();

    $(document).ready(function() {
        //Hide after document ready to fix the map issue
        setTimeout('$("#MapBox").hide()', 200);
        
        $("#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);
        });



    });

    function HideMap() {
        $("#MapBox").hide()
    }

    function LoadWalkScore(lat, lon, address) {
        address = escape(address);
        $.ajax({
            url: "/Services/WalkScoreRequest.aspx",
            type: 'POST',
            data: 'lat=' + lat + '&lon=' + lon + '&address=' + address,
            success: function(html) {
                sWalkScore = JSON.parse(html);
                var walkscore = sWalkScore.walkscore;
                var description = sWalkScore.description;
                var updated = sWalkScore.updated;
                var logo_url = sWalkScore.logo_url;
                var more_info_icon = sWalkScore.more_info_icon;
                var more_info_link = sWalkScore.more_info_link;
                var ws_link = sWalkScore.ws_link;

                var ws_html = '<a target="_blank" href="' + ws_link + '"><img src="' + logo_url + '" /><span class="walkscore-scoretext">' + walkscore + '</span></a>';
                ws_html += '<span id="ws_info"><a href="http://www.walkscore.com/how-it-works.shtml" target="_blank"><img src="http://www.walkscore.com/images/api-more-info.gif" width="13" height="13"" /></a></span>';
                $("#WalkScoreResults").html(ws_html);
            },
            error: function() { alert("error"); }
        }
        );
    }

    function LoadYelp(Category) {
        // There's limitation on Yelp's service per day, so it's better to minimize the number of requests.
        $("#YelpBox table").hide();
        $("#YelpTable" + Category).show();
        if ($.inArray(Category, YelpLoaded) == -1) {
            $("#YelpTable" + Category).html("<tr><td colspan='10'><img src='/img/loadingAnimation.gif'/></td></tr>");
            $.ajax({
                url: "/Services/YelpRequest.aspx",
                type: "POST",
                data: "Cat=" + Category + "&City=" + sCity + "&State=" + sState,
                success: function(html) {
                    sYelpFood = JSON.parse(html);
                    $("#YelpTable" + Category).empty();
                    YelpLoaded.push(Category);
                    if (sYelpFood.businesses.length > 0) {
                        for (iShopping = 0; iShopping < sYelpFood.businesses.length; iShopping++) {

                            $("#YelpTable" + Category).html($("#YelpTable" + Category).html() + "<tr><td width='250'><a href='" + sYelpFood.businesses[iShopping].url + "' target='_blank'>" + sYelpFood.businesses[iShopping].name + "</a></td><td> " + RoundNumber(sYelpFood.businesses[iShopping].distance, 2) + " mi. distance&nbsp;&nbsp;</td><td align='right'><img src='" + sYelpFood.businesses[iShopping].rating_img_url_small + "' />(" + sYelpFood.businesses[iShopping].review_count + ")</td></tr>");
                        }
                    } else {
                        $("#YelpTable" + Category).html("<tr><td>Data not available</td></tr>");
                    }
                }
            });
        }
    }


    function SwitchTab(objID) {
        $("ul.tabs li").removeClass("active");
        $("ul.tabbedNav li").removeClass("ui-state-active");
        $("#" + objID + "Tab").addClass("active ui-state-active");
        $("div.listingDetails div.boxContent, div.tabbedContent").hide();
        $("div#" + objID + "Box").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()
    {
    history.go(-1);
  
//        queryString = ReplaceQueryString(location.search, "PropertyIdx", "");
//        queryString = ReplaceQueryString(queryString, "PropertyItem", "");
//        queryString = ReplaceQueryString(queryString, "PropertyDetail", "").replace("&PropertyDetail=", "");
//           
//        location.replace("PropertyResults.aspx" + queryString);
    }
    
    function GoRefineSearch() {
       var tab = getQuerystring("SearchPageName", "PropertySearchChicago.aspx");
       var BackToResultString = window.location.href;
       BackToResultString = BackToResultString.replace(/propertydetail.aspx/i,tab);
       window.location = BackToResultString;
    }

    function Propertyprint(id) {
    var url=document.getElementById(id).value;
    window.open("/PropertyPrint.aspx?" + url,'Print','','');
//        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",""));
    }
 }*/
