﻿/*	
Site specific tools/functions/variables
*/

//place holder page level setup function - overridden at page level
function setupPage() {
}

//main setup function
function setupMain() {

    (function ($) {

        // === Dynamic font replacement for site content =================================
        Cufon.replace('#navigation a.primary, #navigation a.active, .categorynav li a, .listingstitle h2', {
            fontFamily: 'gmtbold', hover: true, hoverables: { a: true }
        });
        Cufon.replace('.video-title', {
            fontFamily: 'gmtbold', hover: true, hoverables: { a: true }
        });

        // === Remove border and padding from last #systemnav link =======================
        $('#systemnav ul li a:last').css({ 'border-right': '0' });

        // === #searchbox positioning and revealing ======================================
        $('#searchbox').css({ 'top': $('#systemnav').height() + 'px' });
        $('#search-form').css({ 'width': $('#systemnav').width() - 10 + 'px' });
        //$('#search-form .input-box').css({ 'width': $('#systemnav').width() - 58 + 'px' });
        //$('#search-form .submit-image').css({ 'left': $('#search-form .input-box').width() + 10 + 'px' });
        $('#searchtitle').css({
            'width': $('#systemnav #searchlink').parent().width() - 6 + 'px',
            'height': $('#systemnav').height() - 13 + 'px',
            'margin-top': '0' - $('#systemnav').height() + 'px'
        });
        $('#searchbox').css({ 'margin-left': '0px' });
        $('#searchbox').hide();
        $('#searchlink').bind('mouseenter', function () {
            $('#searchbox').show();
        });
        $('#searchbox').bind('mouseleave', function () {
            $('#searchbox').hide();
        });

        // === Open .popout links in a new browser window ================================
        $('a[href^="http://"].popout').attr({ target: '_blank' });

        // === Add toggle functionality to essential containers ==========================
        $('.additional').hide();
        $('.plus-trigger').click(function () {
            $(this).toggleClass('active-toggle');
            $(this).next().slideToggle('slow,');
        });
        $('.name-trigger').click(function () {
            $(this).parent().next().next().slideToggle('slow,');
            $(this).parent().next().toggleClass('active-toggle');
        });
        $('.photo-trigger').click(function () {
            $(this).next().children().next().next().slideToggle('slow,');
            $(this).next().children().next().toggleClass('active-toggle');
        });

        // === Add reveal functionality to a listing's main photo ========================

        // === Add hide functionality to listings selectboxes ============================
        $('.selectbutton').bind('mouseenter', function () {
            $(this).next('.selectbox').show();
            $(this).css('visibility', 'hidden');
        });
        $('.selectbox').bind('mouseleave', function () {
            $(this).prev('.selectbutton').css('visibility', 'visible');
            $(this).hide();
        });

        // === Add hide functionality to feature drop boxes ============================
        $('#navigation .dropdown').bind('mouseenter', function () {
            showDropDown($(this));
        });
        $('#navigation .dropdown').bind('mouseleave', function () {
            hideDropDown($(this));
        });
        $('#navigation .navigationbox').bind('mouseenter', function () {
            showDropDown($(this).prev('.dropdown'));
            Cufon.refresh();
        });
        $('#navigation .navigationbox').bind('mouseleave', function () {
            hideDropDown($(this).prev('.dropdown'));
            Cufon.refresh();
        });

        function showDropDown(which) {
            clearTimeout(which.data('timeout'));
            which.addClass('dropdownover').next('.navigationbox').show();
        }
        function hideDropDown(which) {
            var t = setTimeout(function () {
                which.removeClass('dropdownover').next('.navigationbox').hide();
                Cufon.refresh();
            }, 200);
            which.data('timeout', t);
        }



        // === Remove border-bottom from last .blog .entry ===============================
        $('.blog .entry:last').css({ 'border-bottom': '0' });

        // === Remove border-top from first .bio listing, add border-top to first .img ===
        $('.page .bio:first').css({ 'border-top': '0' });
        $('.page .bio:first img').addClass('full-border');


        /* Add This Open / Close */
        if ($('#btnShareLink').exists()) {
            $('#btnShareLink').bind('click', function () {
                var shareOffset = $('#btnShareLink').offset();
                $('#addthis').css({
                    top: ((shareOffset.top + $('#btnShareLink').parent().height() - 12) + "px"),
                    left: ((shareOffset.left - $('#addthis').width() + $('#btnShareLink').width() + 5) + "px")
                });
                $('#addthis').toggle();
                return false;
            });
            $('#addthisclose').bind('click', function () {
                var shareOffset = $('#btnShareLink').offset();
                $('#addthis').css({
                    top: ((shareOffset.top + $('#btnShareLink').parent().height() - 12) + "px"),
                    left: ((shareOffset.left - $('#addthis').width() + $('#btnShareLink').width() + 5) + "px")
                });
                $('#addthis').toggle();
                return false;
            });
        }



        // === Pre-load key images =======================================================
        var image1 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_box-gradient.jpg');
        var image2 = $('<img />').attr('src', Vars.data.baseURL + 'images/home/bg_neighbourhoods.jpg');
        var image3 = $('<img />').attr('src', Vars.data.baseURL + 'images/home/bg_lifestyle-homes.jpg');
        var image4 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_listing-additional-top.png');
        var image5 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_listing-additional-middle.png');
        var image6 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_listing-additional-bottom.png');
        var image7 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_selectbox.png');
        var image8 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_selectbox-top.png');
        var image9 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_selectbox-bottom.png');
        var image10 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_selectbox-indicator.png');
        var image11 = $('<img />').attr('src', Vars.data.baseURL + 'images/global/bg_selectbox-arrow.png');

    })(jQuery);

}

function AjaxSignOut() {

    $.ajax({
        type: "POST",
        url: Vars.data.baseURL + "Account/Login.aspx/Logout",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () {
            $.showInfo('Signing Out', 'One moment please...');
        },
        success: function (response) {
            window.location.href = Vars.data.baseURL;
            return;
        }
    });
    return false;
}


