/* Powerspeak site effects by White Whale Web Services */
/* Requires jQuery 1.4+ */

$(function() { // on DOM ready
	var tabs = $('#navbar>ul>li').each(function() { // with each tab
			$(this).children('a').append('<span class="tab_left"/><span class="tab_right"/>'); // add the tab curved corners
		});
	//tabs.eq(0).find('.tab_left').remove(); // remove the left edge of the left tab
	//tabs.eq(-1).find('.tab_right').remove(); // and the right edge of the right tab
	// Zebra striping
	var gray = false,
		content = $('#body');
	content.find('h1,h2,h3').each(function() {
		if($(this).parents('table').length) return false; // if this is inside a table, abort
		if($(this).class == "zebra") $(this).nextUntil('h1,h2,h3').andSelf().wrapAll('<div class="zebra'+(gray ? ' gray' : '')+'"/>');
		gray = !gray;
	});
	if(content.children('.zebra').length) { content.css('padding',0); }
	// Course dropdowns
	$('.dropdown').hover(function() {
		$(this).children('ul').show();
	},function() {
		$(this).children('ul').hide();
	}).find('a').click(function() {
		$(this).siblings('ul').toggle();
		return false;
	});
	tabs.hover(function() { // add tab hover
			$(this).addClass('hover');
		},function() {
			$(this).removeClass('hover');
		});
		
	// Homepage feature:
	if($('body').is('#homepage')) {
		
		var controls = $('#feature_controls'),
			features = $('#feature_slider .feature'),
			strip = $('#feature_strip');
		strip.width(strip.children().length*850);
		features.each(function(index) {
			$('<a href="#"></a>').click(function() {
				$(this).addClass('active').siblings().removeClass('active');
				strip.animate({left:-(index*850)});
				return false;
			}).appendTo(controls);
		});
		controls.children('a').eq(0).addClass('active');
	} else {
		var tab = tabs.find('a[href='+window.location.pathname.split('/').slice(0,2).join('/')+'/]').parent().addClass('hover');
		if(tab.length) $('#content').css('margin-top',20);
	}
});
