//addthis config
var addthis_config =
{
    services_compact: 'tumblr,blogger,email,stumbleupon,myspace,delicious',
    ui_click: true
};

$(function () {

    /**** Default value in input box ****/
    $('input[rel|=defaultVal]').each(
        function () {
            var input = $(this);
            var defaultVal = input.attr('rel').split('-')[1];
            if (input.val() == '') input.val(defaultVal);
            input
                .focus(function () { if ($(this).val() == defaultVal) $(this).val(''); })
                .blur(function () { if ($(this).val() == '') $(this).val(defaultVal); });
        }
    );
    var cols4 = $('.columns4');
    var cols4height = cols4.height();
    $('.columns4').find('.column').css('height', cols4height);

    /***** Image rollovers *****/
    $('.column')
        .hover(function () {
            $(this).find('.rollover').stop(true).animate({ height: '80px', opacity: 0.9 }, 'slow')
        }, function () {
            $(this).find('.rollover').stop(true).animate({ height: 0, opacity: 1 }, 'slow');
        });
    /**** Sitemap code ****/
    if ($('#sitemap').length > 0) shrinkSitemap();

    /**** Search Options ****/
    //    $('div.formCol2 div.filter input[type=checkbox]').each(function(key, value) {
    //        if (key < 1) {
    //            // 1st box for 'all'
    //            $(value).click(function(e) {
    //                $('div.formCol2 div.filter input[type=checkbox]')
    //                .each(function(key, value) {
    //                    if (key > 0) {
    //                        $(value).attr('checked', false);
    //                    }
    //                });

    //                $(this).attr('checked', $(this).attr('checked'));
    //            });
    //        }
    //        else {
    //            $(value).click(function(e) {
    //                $($('div.formCol2 div.filter input[type=checkbox]')[0]).attr('checked', false);
    //            });
    //        }
    //    });
});


function shrinkSitemap() {
    $('#sitemap>ul>li>ul').hide();
    $('#sitemap>ul>li').each(
        function() {
            if ($(this).find(">ul").attr('class') == 'subSection')
                $('<img src="/images/arrow_right.gif" class="expand" />')
                .toggle(
                    function() {
                        $(this).attr('src', '/images/arrow_down.gif').parent().find(">ul").slideDown();
                        return false;
                    },
                    function() {
                        $(this).attr('src', '/images/arrow_right.gif').parent().find(">ul").slideUp();
                        return false;
                    }
                )
                .prependTo($(this));
            else $('<img class="spacer" src="/images/spacer.gif" />').prependTo($(this));
        }
    );
}
