﻿

$(document).ready(function () {

    //Slide Auction sections down
    $('.propertyListHeader').click(function (event) {
        $(this).siblings('.recordcontainer').slideUp().end().next().slideToggle();
    });

    
});

function addRecent(item, id, addr, imgurl) {

    if (!checkifexists(id, 'recent')) {
        recents.push(new recent(id, addr, imgurl));

        WebSiteStatistics.PostPropertyPageHit
    }
    else {
        alert('recent exists');
    }
}

function initializeDetailMap(lat, lon) {
    var myOptions = {
        zoom: 14,
        center: new google.maps.LatLng(lat, lon),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        sensor: 'false'
    }

    var map = new google.maps.Map(document.getElementById("map"), myOptions);

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, lon),
        map: map
    });
}

function initializePropertyTabs() {
    $(".pane").stop().fadeOut();

    $(".pane:first").stop().fadeIn(); //Show first tab content

    // When a link is clicked
    $("a.s, a.m").click(function () {

        // switch all tabs off
        $("a.current").removeClass("current");

        // switch this tab on
        $(this).addClass("current");

        // slide all content up
        $(".pane").stop().fadeOut();

        // slide this content up
        var content_show = $(this).attr("title");
        $("#" + content_show).stop().fadeIn();
    });
}

function PickaHorizontal() {
    $("#pikachoose").PikaChoose({ autoPlay: false, transition: [-1] });
    $("#pikachoose").jcarousel({
        initCallback: function (carousel) {
            $(carousel.list).find('img').click(function () {
                var clicked = parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex'));
                var last = ($(this).parents('ul').find('li:last').index() == clicked - 1) ? true : false;
                if (!last) {
                    clicked = (clicked - 2 <= 0) ? 0 : clicked - 2;
                }
                clicked++;
                carousel.scroll(clicked);
            });
        }
    });
}
function PickaVertical() {
    $("#pikachoose").PikaChoose({ carousel: false, autoPlay: false, carouselVertical: true, transition: [-1] });
    var numRows = 2;
    $("#pikachoose").jcarousel({ vertical: true,
        moduleWidth: 275,
        rows: numRows,
        scroll:3,
        visible: 3,
        initCallback: function (carousel) {
            $(carousel.list).find('img').click(function () {
                var clicked = parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex'));
                var last = ($(this).parents('ul').find('li:last').index() == clicked - 1) ? true : false;
                if (!last) {
                    clicked = (clicked - 2 <= 0) ? 0 : clicked - 2;
                }
                clicked++;
                //carousel.scroll(clicked);
            });
        }
    });
}
    var query = "http://localhost:2266/WWMDS.svc/getAdditionalProperties?sKeywords='<%= Search %>'";
    var i = 1;

     function displayResults(results) {
             for (var item in results.d) {
                 $('#holder').append('<li>' +
                '<div class="gradient"><div style="margin:0 auto;text-align:center;width:200px;float:left;">' +
                '<a href="#"><img src="http://www.williamsauction.com/gallery/' + results.d[item].Thumbnail + '" height="100px" style="border:3px ridge #ffffff;position:relative;margin-bottom:5px;" /></a>' +
                '<img style="position:relative;margin-bottom:5px;" src="/Resources/temp/createprofile.png"  />' +
                '<img style="position:relative;margin-bottom:5px;" src="/Resources/temp/createprofile.png"  />' +
                '</div>' +
                '<div Width="100%" Height="100%" >' +
                '<div class="content_title" /><br />' +
                '<div class="content_sale_location" />Relevance: ' + results.d[item].Relevance + '%<br />' +
                '<a href="/property-auctions/' + results.d[item].PropertyID + '">' + results.d[item].Address + '</a><br /><br />' +
                '<div class="content_sale_location">' + results.d[item].Address + '</div><br />' +
                '<div class="content_sale_location">' + LongDate(results.d[item].SellDateTime) + '</div><br /><br />' +
                '<div class="content_copy" />' + results.d[item].Description + '</div>' +
                 //'<img class="open_property" />' +
                '</div>' +
                '</li>');
             }

             if (i <= totalRecords) {
                 i++;
                 GetData(i);
             }
             else {
                 $('#holder').sweetPages({ perPage: 10 });

                 var controls = $('#main .swControls').detach();
                 controls.clone().appendTo('#controlstop');

                 $(".gradient").bind({
                     mouseenter: function () {
                         $(this)
                            .stop(true, true)
                            .animate({ backgroundColor: "#FBFFEA" }, 250)
                            .delay(250)
                            .animate({ height: $(this).outerHeight() + 100 }, 1000)
                         // $('#holder').animate({ height: ($('.swPage').height() + $(this).outerHeight())}, 1000);
                     },
                     mouseleave: function () {
                         $(this)
                            .clearQueue()
                            .stop(true, true)
                            .animate({ backgroundColor: "transparent", height: '100px' }, 1000);
                         //$('#holder').animate({ height: 'auto'}, 1000);
                     }
                 });

                 $(".open_property").click(function () {
                     $(this)
                        .toggleClass('open_property_expanded')
                        .parent().animate({ height: $(this).parent().height() > 100 ? '100px' : '100%' }, 1000, function () { });
                 });
         }
       }

       /*Filter search */

	
	function doSearch(sFilters) {

	    proxy.invoke("GetKWSSearchResults", { 'sArea': area, 'sFilters': sFilters },
            function (result) {
                alert(result.SearchResultWrapper.PropertyWrappers.length);
                $('#holder').empty();
                var i = 0;
                do {
                    $('<li>').append($("#Template10x").tmpl(result.SearchResultWrapper.PropertyWrappers.slice(i, i + i10xPageSize))).appendTo("#holder");

                    i += i10xPageSize;
                } while (i < result.SearchResultWrapper.PropertyWrappers.length);




                //alert(result);
                //alert($('#holder').html());
                updatePropSlider();

                //                $("#Template10x").tmpl(result,
                //                {
                //                    ajaxresult: result,
                //                    position: function (item, retarray) {
                //                        return $.inArray(item, retarray);
                //                    },
                //                    myMethod: function (item, retarray) {
                //                        //alert(($.inArray(item, retarray) % 10) ? true : false);
                //                        return ($.inArray(item, retarray) % 10) ? true : false;
                //                    }
                //                }).appendTo("#holder");

            },
            function (error) {
                alert(error.text);
            }

            );
	    return false;

	}




