$(document).ready(function () {
    // 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();

});
