$('html').addClass('js');

$(document).ready(function () {
    // Detect mobile devices
    if ($(window).width() <= 480) {
        $('body').addClass('mobile');
    };
    
    // Change nav for mobiles
    $('.mobile #nav .compact').hide();
    $('.mobile #nav h2').click(function () {
        $(this).siblings('ul').slideToggle();
    });
    
    // Award info page: expandable Unit info
    $('#award #award-unit-list li a:first-child').click(function () {
        $(this).siblings('ul').slideToggle();
        return false;
    });
    
    // Search box
    $('#search-box').focus(function () {
        if ($(this).val() == 'SEARCH (type here and hit enter)') {
            $(this).toggleClass('active').val('')
        };
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).toggleClass('active').val('SEARCH (type here and hit enter)');
        };
    }).parents('div')
    .siblings('input:submit').css('display','none');

    
    // Flash (glow) effect
    $('#secondary-content a.glow img').hover(
        function () {
            $(this).fadeTo(100, 0.5);
            $(this).fadeTo(500, 1);
        },
        function (){}
    );

    // Forms submission / errors
    $('.success').css('display', 'none');
    $('.success').fadeIn(5000);
    $('.errors').css('display', 'none');
    $('.errors').fadeIn(3000);

    // jQuery Date Picker
    if ( $('.jquery-datepicker').length )
        $('.jquery-datepicker').datepicker({
            dateFormat: 'yy-mm-dd'
        });
    
    // Same as above but with a pickable "Year".
    if ( $('.jquery-datepicker-year').length )
        $('.jquery-datepicker-year').datepicker({
            dateFormat: 'yy-mm-dd',
            changeYear: true
        });

    
    // Same as above but with a pickable "Year", and default date of 25yrs ago
    dateObjToday = new Date();
    
    var dateObj1980 = new Date();
    dateObj1980.setFullYear(1980,0,1);
    
    var dateObj1900 = new Date();
    dateObj1900.setFullYear(1900,0,1);
    
    if ( $('.jquery-datepicker-dob').length )
        $('.jquery-datepicker-dob').datepicker({
            dateFormat: 'yy-mm-dd',
            changeYear: true,
            yearRange: '-100:+100',
            minDate: dateObj1900,
            maxDate: dateObjToday,
            defaultDate: dateObj1980
        });


    // Scroll smoothly to anchors
    // http://flesler.blogspot.com/2007/10/jqueryscrollto.html
    // http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
    $.localScroll.hash();
        
    $.localScroll({
        hash: true,
        easing:'easeInQuart'
    });
    
    // Expandable Textareas (ala facebook)
    $('textarea').elastic();
    
    // Helper text for Get Satisfaction dialog box
//    var iframe_width = $('#fdbk_iframe').width() + 'px';
    $('#fdbk_iframe')
        .before("<p>Log in with Facebook, Twitter, Google or Windows Live! <em class='quiet'>No need for a new account.</em></p>")
        .prev('p')
        .css('position', 'absolute')
        .css('left', '18px')
        .css('width', $('#fdbk_iframe').css('width'))
        .css('color', '#fff799')
        .css('text-shadow', '0px 0px 5px #fff')
        .css('font', '14px "Helvetica Neue", Arial, sans-serif')
        .css('text-align', 'center')
        .css('background-color', 'rgba(0,0,0,0.5)')
        .css('padding', '3px')
        .css('border-radius', '5px');

});

