$(document).ready(function() {

    $("ul").each(function() {
        $(this).find("li:first").addClass('li_first');
        $(this).find("li:last").addClass('li_last');
        $(this).find("li:even").addClass('li_even');
        $(this).find("li:odd").addClass('li_odd');
    });
    $("table tr:odd").addClass('odd');
    $("table tr:even").addClass('even');

    /* Create "floating" home link div */
    $('#header').append('<div id="header_home_link"></div>').find('#header_home_link').click(function() { window.location = '/' });

    /* Pointer overlay in internal navigation */
    $('.interior #side_content').append('<div id="category_pointer"></div>');

    /* Link Types */
    $('a[href$=".pdf"]').not('.no_icon').addClass('link_pdf');
    $('a[href$=".doc"]').not('.no_icon').addClass('link_doc');
    $('a[href$=".xcl"]').not('.no_icon').addClass('link_excel');
    $('a[href$=".pp"]').not('.no_icon').addClass('link_powerpoint');
    $('a[href^="http://"]').not('.no_icon').addClass('link_external').attr('target', '_blank');

    /* Plugins */
    $('.inputclear').inputclear();
    $('#initiatives_menu ul').columnize(3);
    //$('#news_feature_home').feature({mode: 'fade'});
    $('#news_feature_home').feature({ mode: 'fade', delay: 8500 });
    $('#interested_initiatives ul').columnize({ columns: 2 });
    $('#interested_initiatives select').select_mod($('#interested_initiatives ul'));

    /* Override the CSS :hover */
    $('#interested_initiatives a').hover(
		function() {
		    $(this).addClass('hover');
		},
		function() {
		    $(this).removeClass('hover');
		}
	);

    /* Newsletter Signup */
    $('.newsletter_signup h2').append('<span class="tir"></span>')
		.hover(
			function() {
			    $(this).addClass('hover');
			},
			function() {
			    $(this).removeClass('hover');
			}
		)
		.toggle(
			function() {
			    $(this).addClass('expanded').parent().animate({
			        height: '278px'
			    }, 'fast');

			},
			function() {
			    $(this).removeClass('expanded').parent().animate({
			        height: '59px'
			    }, 'fast');
			}

		);
    /* Disable text selection */
    $('.disableselect').onSelectStart = function() { return false; };
    $('.disableselect').css('-moz-user-select', 'none').css('-khtml-user-select', 'none').css('user-select', 'none');

    /* Drop down the initiatives menu */
    function show_menu() {
        $('#initiatives_menu').slideDown('fast');
        $('#main_menu li.li_first a').addClass('expanded');
        $('#initiatives_menu a').animate({ opacity: 1 }, 'fast');
    }
    function hide_menu() {
        $('#initiatives_menu').slideUp('fast');
        $('#main_menu li.li_first a').removeClass('expanded');
        $('#initiatives_menu a').animate({ opacity: 0 }, 'fast');
    }
    $('#main_menu li:first a').toggle(
		function() {
		    show_menu();
		},
		function() {
		    hide_menu();
		}
	);
    /* Hide sub menu when anything but a menu item is clicked */
    $("body").bind("click", function(e) {
        var $target = $(e.target);

        // Don't hide the menu if a menu item was clicked & the menu is open
        if (!$target.is('#main_menu li.li_first a, #initiatives_menu, #initiatives_menu a') && $('#main_menu li.li_first a').hasClass('expanded')) {
            $('#main_menu li:first a').click();
        }
    });


    /* Internal Navigation */
    $('.internal_nav > ul > li > a').each(function() {

        if ($(this).parent().is('li:has(ul)')) {

            var drop_button = $('<a href="' + $(this).attr('href') + '" class="internal_dropdown">+</a>');

            drop_button.click(function() {
                var par_obj = $(this).closest('li');
                var list_obj = par_obj.find('ul');

                if (list_obj.is('ul')) {

                    // Slide up all other ULs that are not the one that's being clicked
                    par_obj.parent().find('ul').not(list_obj).slideUp('fast').parent().removeClass('expanded');

                    // Slide up/down the clicked item
                    list_obj.slideToggle('fast');

                    if (par_obj.hasClass('expanded')) {
                        par_obj.removeClass('expanded');
                    } else {
                        par_obj.addClass('expanded');
                    }

                    return false;
                }
            });
        }

        $(this).wrap('<span>');
        $(this).parent().prepend(drop_button);
    });

    /* Override the CSS :hover */
    $('.news_feature_header ul li').hover(
		function() {
		    $(this).addClass('hover');
		},
		function() {
		    $(this).removeClass('hover');
		}

	);


});
