$(document).ready(function(){

    //Moble Sniffing
    if ( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPod/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/Aspen/i))
        {
            $('body').addClass('hide_dock hide_dock_banner');
    }
    
    $('a.youtube').youtubin({
        swfWidth : '406',
        swfHeight : '304'
    });

    if($('.social_container').length) {
        $('.social_container').fixedFloat();
    }

    if ($('body').is('.thanks_a_million')) {

        $('a.video').youtubin({
            swfWidth : 640,
            swfHeight : 385
        });

        var myOpen = function(hash) {
            hash.o.fadeIn('4000', function(){
                hash.w.fadeIn('2000');
            });
        };

        var myClose = function(hash) {
            hash.w.fadeOut('1400');
            hash.o.fadeOut('1400');
        };

        $('#gilbert_letter').jqm({
            trigger:'a.gilbert_letter_trigger',
            toTop:true,
            overlay:60,
            onShow: myOpen,
            onHide: myClose
        });
        $('#client_video').jqm({
            trigger:'a.client_video_trigger',
            toTop:true,
            overlay:60,
            onShow: myOpen,
            onHide: myClose
        });
        $('#tv_video').jqm({
            trigger:'a.tv_video_trigger',
            toTop:true,
            overlay:60,
            onShow: myOpen,
            onHide: myClose
        });

        if ( window.location.href.match(/dan-gilbert-letter/ig) ) {
            $('#gilbert_letter').jqmShow();
        } else if ( window.location.href.match(/million-closed-loans/ig)) {
            $('#client_video').jqmShow();
        } else if ( window.location.href.match(/thanks-a-million-advertisement/ig)) {
            $('#tv_video').jqmShow();
        }
    }

    // Schedule a call modal trigger
    if ($('.callBackModalTrigger').length ) {
        $('.callBackModalTrigger').triggerModal();
    }

    $('a').openNewWindow();
    //$('input[type=text]').numberFormat();
    $('.close_popup').closePopup();
    $('form.clear_inputs input').clearInputs();
    //$('.arrangement_a form#referral').qlvalidate();

    // QTip Tooltip using Title for content
    if($('.tooltip').length ) {
        $('.tooltip').displayTooltip('tooltip');
    }

    // QTip Tooltip using AJAX for content
    if($('.tooltip_ajax').length ) {
        $('.tooltip_ajax').displayTooltip('tooltip_ajax');
    }

    // Layout Footer
    if($('div.copyright_container ul#navigation_partner li').length ) {
        $('div.copyright_container ul#navigation_partner li:not(:last)').append(' | ');
    }

    // Global Lead Form
    if ( $('.global_lf').length ) {
        $().globalLeadForm();
    }

    // Toggle JD Powers disclaimer container
    if ( $('.jdp_disclaimer').length ) {
        $().toggleTriggerJDPDisclaimer();
    }

    // Toggle assumptions container
    if ( $('.jq_assumptions').length ) {
        $().toggleTriggerAssumptions();
    }

    // Scroll to and toggle assumptions container
    if ( $('.jq_scrollToAssumptions').length ) {
        $().scrollToAssumptions();
    }
});
