//Initiate Lazy loading of Jquery plugins
$.lazy({'name':'catsys','src':'/Content/javascripts/jquery.catsys.js','cache':'true'});
$.lazy({'name':'defaultValue','src':'/Content/javascripts/jquery.defaultvalue.source.js','cache':'true'});
$.lazy({'name':'valid8','src':'/Content/javascripts/jquery.valid8.js','cache':'true'});
$.lazy({'name':'elastic','src':'/Content/javascripts/jquery.elastic.js','cache':'true'});
$.lazy({'name':'showPassword','src':'/Content/javascripts/jquery.showpassword.js','cache':'true'});
$.lazy({'name':'accordion','src':'/Content/javascripts/jquery.accordion.js','cache':'true'});
$.lazy({'name':'facebox','src':'/Content/facebox/facebox.js','dependencies': {'css': ['/Content/facebox/facebox.css']},'cache':'false'});
$.lazy({'name':'flash','src':'/Content/javascripts/jquery.swfobject.js','cache':'true'});
$.lazy({'name':'scrollTo','src':'/Content/javascripts/jquery.scrollTo-min.js','cache':'true'});

$(document).ready(function() {
    //Initiate Cufon
    Cufon.replace('.grid_12>h1, .site-ID, .popup h1, .article h1, .futura-bold', { fontFamily: 'Futura PT Bold' });
    Cufon.replace('.search-wrapper label, .tag-line, .m1a h1, .m1b h1, .m1c h1, .m2a h1, .m2b h1, .x-form h1', { fontFamily: 'CoopForged' });

    //Initiate ScrollTo
    $('a[href^=#]').bind('click', function(event) {
        event.preventDefault();
        $.scrollTo($(this).attr('href'), 'fast');
    });


    //Initiate Accordion
    if ($('.accordion').length) {
        $('.accordion').accordion();
    }

    //Initiate Defaultvalue
    /* Rel is not accepted according to w3c, Moved this to masterpage
    if($('input[defaultvalue]').length){
    $('input[defaultvalue]').defaultValue();
    } */

    // Submit on enter
    $('input.text').live('keypress', function(e) {
        if (e.keyCode == '13') {
            e.preventDefault();
            $(this).parents('*').each(function(i, parent) {
                var $el = $(parent).find('input[type=submit]:first');
                if ($el.length > 0) {
                    $el.trigger('click');
                    return false;
                }
            });
        }
    });

    //Toggle
    $('.toggle-container').hover(
        function(event) {
            $(this).children('.mouseover-container').show();
            $(this).children('.mouseout-container').hide();
        },
        function(event) {
            $(this).children('.mouseover-container').hide();
            $(this).children('.mouseout-container').show();
        }        
     );
});