﻿(function($) {

    $(document).ready(function() {
        // Apply a link to a listing
        ApplyLinkToElement("#listings li");
        
        // Apply a link to the listion options page (Listings.aspx)
        ApplyLinkToElement(".listing-option");
        
        ApplyAjaxLinkToElement(".enquiry-link");

        // This method will apply a clickable link to any given selector.
        function ApplyLinkToElement(selector) {
            // Adds a link css attribute
            $(selector).addClass("link");

            $(selector).each(function() {
                $(this).click(function() {
                    // Grab the hyperlink in the listing, and forwad the window to that location
                    var listingHyperlink = $(this).find("a").attr("href");
                    window.location = listingHyperlink;

                    // Stops the click from doing anything else.
                    return false;
                });
            });
        }

        function ApplyAjaxLinkToElement(selector) {
            $(selector).each(function() {
                $(this).click(function() {
                    // Grab the hyperlink in the listing, and forwad the window to that location
                    var contactHyperlink = $(this).attr("href");

                    $("#contact-form-ajax-container").load("Contact.aspx #contact-form");

                    // Stops the click from doing anything else.
                    return false;
                });
            });
        }

        $(".colorbox").colorbox({ width: "80%", height: "80%", iframe: true, opacity: 0.8, transition: "fade", scrolling: false });
    });

})(jQuery)

