﻿$(document).ready(function() {

    /*----CUFON APPLICATION TO HEADERS--------*/
    Cufon.replace('.cufon');

    /*---- JQuery Scrollable - initialise DIV -----*/
    $("div.scrollable").scrollable({ size: 3, prev: 'a#leftscroll', next: 'a#rightscroll' });

    /* SET FORM FOCUS ENTER SUBMIT OF FOCUSED INPUT  */
    var focussed_form;
    $('input').focus(focus_form);
    $('input').blur(unfocus_form);
    /*$('textarea').focus(focus_form);
    $('textarea').blur(unfocus_form);*/
    $('select').focus(focus_form);
    $('select').blur(unfocus_form);
    $('a.btn').focus(focus_form);
    $('a.btn').blur(unfocus_form);

    $(document).keypress(function(e) {
        if (e.keyCode == 13) {
            submit_form();
        }
    });

    $('a.preventDefault').click(function(e) {
        e.preventDefault();
    });

    $('a.btn.forinput').click(function(e) {
        e.preventDefault();
        $(this).closest('form').trigger('submit');
    });

    function focus_form() {
        focussed_form = $(this).closest('form');
    }

    function unfocus_form() {
        focussed_form = null;
    }

    function submit_form() {
        $(focussed_form).trigger('submit');
    }

    /*---- JQuery Custom Selects -----*/
    $('#typeofbusinessdd').SelectCustomizer();
    $('#investmentfilterdd').SelectCustomizer();
    $('#agentfilterdd').SelectCustomizer();
    $('#pricerangedd').SelectCustomizer();
    $('#locationdd').SelectCustomizer();
    $('#investmenttypedd').SelectCustomizer();
    $('#tenuredd').SelectCustomizer();
    $('#yielddd').SelectCustomizer();

    /*---- We have javascript so hide the nojavascript basic submit
    buttons and bring in the pretty ones (given big left margin in CSS) ----*/

    $('input.nojavascriptsubmit').hide();
    $('a.btn.forinput').css('left', 0);

    /* Show Agent's Profile if hovered over */

    $('a.view-agent-profile').hover(
        function() {
            $(this).parent().parent().find("div.contact-profile").fadeIn();
        },
        function() {
            $(this).parent().parent().find("div.contact-profile").fadeOut();
        }
    );

    /* Image gallery effects on Investment Details page */

    $("img.small-image").hover
        (
            function() {
                var imgHref = $(this).attr('src');  //get the src of the thumbnail
                imgHref = imgHref.replace('_small', '');
                $('img.big-image').attr('src', imgHref);  //give new image a src attribute
            },
            function() {
                var imgHref = $(this).attr('src');  //get the src of the thumbnail
                imgHref = imgHref.replace('_small', '');
                imgHref = imgHref.replace('_B', '_A');
                imgHref = imgHref.replace('_C', '_A');
                imgHref = imgHref.replace('_D', '_A');
                imgHref = imgHref.replace('_E', '_A');
                imgHref = imgHref.replace('_F', '_A');

                $('img.big-image').attr('src', imgHref);  //give new image a src attribute
            }
        );

    $('#fRegister #aoi').focus(function() { if (this.value == this.defaultValue) { this.value = ""; } });
    $('#fRegister #requirements').focus(function() { if (this.value == this.defaultValue) { this.value = ""; } });
    $('#fRegister #other').focus(function() { if (this.value == this.defaultValue) { this.value = ""; } });
    $('#secure-username').focus(function() { if (this.value == this.defaultValue) { this.value = ""; $('#secure-password-text').css("top", "-10000px"); } });

});



