﻿$(document).ready(function() {

    // Clear textboxes on focus
    $('.autoclear').autoClear();

	
	// section navigation accordion
	/*	if($('#secondaryContent .accordion .pane').length > 0) {
		$('#secondaryContent .accordion').accordion({
			header: 'h3.trigger',
			autoHeight: false,
			active: false,
			alwaysOpen: false,
			collapsible: true,
			navigation: true
		});
	}*/
	
	// add .current class to current page links in menus
	$('#secondaryContent ul a, #sidebar ul a').each(function(){
		if(this.href.toLowerCase() == location.href.toLowerCase()){
			$(this).addClass('current');	
		}
	});
	
	
	// adjust padding for paragraphs in an agenda definition list
	if ($('dl.agenda').length) {
	$('#mainContent dl.agenda dd').each(function(){
		//var $this = $(this);
		$(this).find('p:last').css('margin-bottom','0');							 
		});
	}
	
	
	// alternate row colors for properly formatted tables
	$('#mainContent thead + tbody tr:odd td').addClass('odd');
	
	
	// highlight navigation tab for current section
	var page = window.location.href;
	//alert(page.indexOf('subcommittees-working-groups'));
	if ((page.indexOf('/coop/') != -1) || (page.indexOf('/dmcc/') != -1)
	||(page.indexOf('/epi/') != -1) || (page.indexOf('/exercise-drill/') != -1)
	|| (page.indexOf('/ffr/') != -1) || (page.indexOf('/hazards-assessment/') != -1)
	|| (page.indexOf('/scapa/') != -1) || (page.indexOf('/subcommittees-working-groups/') != -1) || (page.indexOf('/training/') != -1) && (page.indexOf('/training-products/') == -1)
	|| (page.indexOf('techwg') != -1)) {
		$('ul#tabs a:eq(0)').addClass('active');
	}
		if (page.indexOf('/membership-directory/') != -1){
		$('ul#tabs a:eq(1)').addClass('active');
	}
		if (page.indexOf('/annual-meeting/') != -1){
		$('ul#tabs a:eq(2)').addClass('active');
	}
			if (page.indexOf('/training-products/') != -1){
		$('ul#tabs a:eq(3)').addClass('active');
	}
});


// Clears the default text when an input receives
// focus and reinstates it if it is left blank
(function($) {

    $.fn.autoClear = function() {	
        return this.each(function() {
            $(this).focus(function() {
                if( this.value == this.defaultValue ) {
                    this.value = "";
                }
            })
            .blur(function() {
                if( !this.value.length ) {
                    this.value = this.defaultValue;
                }
            });
        });
    };

})(jQuery);

