/*-----------------------------------------------------------------------------
Web Site: Sequence Homes

$CreatedDate: 2009-08-12 $
$CreatedBy: annag $

$Revision: 95 $
$LastChangedDate: 2009-10-27 15:14:53 +0500 (Вт, 27 окт 2009) $
$LastChangedBy: mariar $
-----------------------------------------------------------------------------*/

function featured_properties_initCallback(carousel, state) {
    if (featured_properties_itemList.length < 4) {
        carousel.buttonNext.hide();
        carousel.buttonPrev.hide();
        carousel.options.size = featured_properties_itemList.length;
        carousel.options.wrap = 'none';
    }

    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function featured_properties_getItemHTML(item) {
    return '<div class="property-item"><div class="item-inner"><div class="item-title"><strong>' + item.tagLine + '</strong></div><div class="item-image"><div class="img-shadow w155 png-bg"><div class="shadow-inner png-bg"><div class="shadow-inner2 png-bg"><a onclick="_gaq.push([\'_trackEvent\', \'Property Search\', \'Featured property carousel click\']);" href="' + item.url + '"><img src="' + item.imageUrl + '" width="155px" height="116px" /><strong class="info ' + item.marker.toLowerCase() + ' png-bg">' + item.marker + '</strong></a></div></div></div></div><div class="item-summary">' + item.streetName + ', <br />' + item.town + '</div><div class="item-price"><strong class="price">' + item.price + '</strong><div class="clearall"></div></div></div></div>';
};

function featured_properties_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, featured_properties_itemList.length);
    carousel.add(i, featured_properties_getItemHTML(featured_properties_itemList[idx - 1]));
};

function featured_properties_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

function singleCarousal_initCallback(carousel, state) {
    if (carousel.options.size < 2) {
        carousel.buttonNext.hide();
        carousel.buttonPrev.hide();
    }

    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


jQuery(document).ready(function() {

    /* =Hidden elements
    ---------------------------------------- */

    $('.quick-links').hide();
    $('.advanced-search').hide();

    /* =Drop Down
    ---------------------------------------- */
    jQuery(".content .primary-nav ul li").bind("mouseover", function() {
        jQuery(this).find("div").show();
    });
    jQuery(".content .primary-nav ul li").bind("mouseout", function() {
        jQuery(this).find("div").hide();
    });

});

	function GetParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            if (results == null)
                return "";
            else
                return results[1];
        }
        
function trim(str)
{
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}


// AEmmott 2012 02 03
// Converts a textbox into an autocomplete textbox, which returns a list of
// geographies - towns, cities, postcodes.
function geographyAutoComplete(autocompleteTextBoxId, rentOrBuy, count) {
    $("#" + autocompleteTextBoxId  +"").autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "/SequenceWS.asmx/GetGeographyLookupList",
                data: "{'prefixText':'" + request.term + "','count':" + count  + ",'contextKey':'" + rentOrBuy + "'}",
                dataType: "json",
                async: true,
                success: function (data) {
                    response(data.d);
                },
                error: function (result) {
                    alert("Due to unexpected errors we were unable to load data");
                }
            });
        },
        minLength: 2
    });
}
