
var homePage = {
    loadFeatures: function() {
        homePage._currentlySelected = 0;
        $("#featured .featProperties li").each(function(i) {
            $(this).bind('click', i, homePage.selectFeatureListing);

        });
        $("#featured .featProperties li a").removeAttr('href');
        $("#featured .featImg").css('background-color', 'black');
        homePage.initAutoPlay();
        $("#featured").hover(homePage.pauseAutoPlay, homePage.initAutoPlay);

    },
    initAutoPlay: function() {
        if (typeof homePage._autoPlayInterval != 'undefined' && homePage._autoPlayInterval != 0)
        clearInterval(homePage._autoPlayInterval);
        homePage._autoPlayMax = $("#featured .featProperties li").length;
        if (homePage._autoPlayMax <= 1)
        return;
        homePage._autoPlayInterval = setInterval("homePage.autoPlay()", 5000);

    },
    pauseAutoPlay: function() {
        clearInterval(homePage._autoPlayInterval);
        homePage._autoPlayInterval = 0;

    },
    autoPlay: function() {
        var next = homePage._currentlySelected + 1;
        if (next >= homePage._autoPlayMax)
        next = 0;
        homePage.selectFeatureListing({
            data: next

        });

    },
    animateLeft: function(current, next) {
        var width =465;
        var duration = 400;
        var $current;
        var $next;
        $("#featured .featImg a").each(function(i) {
            if (i == current) {
                $current = $(this);

            } else if (i == next) {
                $next = $(this);

            }

        });
        $next.css("left", width + "px");
        $next.animate({
            "left": "0px"

        },
        duration, "swing");
        $current.animate({
            "left": -width + "px"

        },
        duration, "swing");

    },
    selectFeatureListing: function(eventObject) {
        var id = eventObject.data;
        if (homePage._currentlySelected === id)
        return;
        $("#featured .featProperties li").each(function(i) {
            $(this).toggleClass('selectedFeature', i == id);

        });
        homePage.animateLeft(homePage._currentlySelected, id);
        homePage._currentlySelected = id;

    }

};


if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
