jQuery(document).ready(function() {
	calTool();
	dateSelect();
    subNav();
});
	
function calTool() {
	// add class last to last table-row
	jQuery('#timeline > tr:last-child').addClass('last');
	
	// table-row hover toggle color
	jQuery('#timeline_tbody > tr:not(tr.moreInfo), tbody.cat > tr:not(tr.moreInfo)').hover(function() {
  	jQuery(this).addClass('over').css('cursor', 'pointer');
	}, function() {jQuery(this).removeClass('over');});
		
	// hide more information
	jQuery('#calResults tr.moreInfo').hide();
    
	// click any table row that is not a more info row
	jQuery('#timeline_tbody > tr:not(tr.moreInfo), tbody.cat > tr:not(tr.moreInfo)').click(function() {
	
	// if more info is hidden
	if (jQuery(this).next('#calResults tr.moreInfo').css('display') == 'none')
    {
	jQuery(this).next().show();
    jQuery('table.classSched').show();
	jQuery(this).children().css('borderBottom', 'none');
	
	// if more info is visible
	}
    else if (jQuery(this).next('#timeline_body > tr.moreInfo, tbody.cat > tr.moreInfo').css('display') != 'none')
    {
	jQuery(this).next('#timeline_tbody > tr.moreInfo, tbody.cat > tr.moreInfo').hide();
    jQuery(this).children().css('borderBottom', '#d5d5d5 dotted 1px');
	}
	
	});
	
    
	// swap text for category
	jQuery('#allCatSub a').click(function() {
	var cattext = jQuery(this).text();
	if (cattext == 'show all categories') {
	jQuery('li#catView > a').text('all categories');
	} else {
	jQuery('li#catView > a').text(cattext); }
	});
	
	// swap text for view
    
	jQuery('#viewSub a').click(function() {
	var viewtext = jQuery(this).text();
	if (viewtext == 'category view') {
	jQuery('#timeView').css('backgroundPosition','15px 0');
	} else { 
	jQuery('#timeView').css('backgroundPosition','15px 100%');
	}
	jQuery('#timeView > a').text(viewtext);
	});

}
	
function dateSelect() {
	// calendar date click toggle active
	jQuery('#theCal td').click(function() {
	jQuery('#theCal td').removeClass();
	jQuery(this).addClass('active');
	});
}

function subNav() {
	// onclick view subnav
	jQuery('li#catView, li#timeView').click(function() {
	var subview = jQuery(this).find('div');
	
	if(subview.is(':hidden')) {subview.slideDown('fast');}
	
    else if(subview.is(':visible')) {subview.slideUp('fast');}
    
	});
}
