$(document).ready( function() {
	
	$('#options').rotate({type: 'animate'});
	
	// TABLE HOVER
	$('table.courses tr').hover( function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	// TABS and HASH TAGS
	$('#tabs a').click( function() {
		var startScroll = $(window).scrollTop();
		var href = $(this).attr('href');
		window.location.hash = href;
		$(window).scrollTop(startScroll);
		
		var link = $(this);
		link.parents('#tabs').find('a').attr('class', 'gray_button_link');
		link.attr('class', 'button_link');
		
		$('#tab_content').children().hide();
		$(href).show();
		
		return false;	
	});
	
	var hash = (window.location.hash != '' && window.location.hash != '#') ? window.location.hash : 0;
	
	if (hash) {
		$('#tab_content').children().hide();
		$(hash).show();
		$('#tabs a[href="'+hash+'"]').attr('class', 'button_link');
		
	} else {
		$('#tab_content').children().hide().eq(0).show();
		$('#tabs a').eq(0).attr('class', 'button_link');
	}
	
	// MINI NAV
	$('#mini_nav a').eq(1).addClass('active');
	
	var wait = function() { return false; }
	var $mininav = $('#mini_nav a');
	
	var clicker = function(e) {
		
		$mininav.unbind('click').bind('click', wait);
		
		// arrows
		var $is_right = $(this).hasClass('right_arrow');
		var $is_left = $(this).hasClass('left_arrow');
		var $mini_nav = $('#mini_nav a');
		var $active_one = $mini_nav.parent().find('.active');
		
		if ($is_right || $is_left) {
			if ($is_right) {
				var $nextActive = ($active_one.next().hasClass('right_arrow')) ?  $mini_nav.eq($mini_nav.length-2) : $active_one.next();
			} else {
				var $nextActive = ($active_one.prev().hasClass('left_arrow')) ? $mini_nav.eq(1) : $active_one.prev();
			}
			
			$(this).siblings().removeClass('active');
			$nextActive.addClass('active');
			var index = $nextActive.index() - 1;
			
		} else { // numbers
			$(this).addClass('active').siblings().removeClass('active');
			var index = $(this).index() - 1;
		}
		
		$('#featured .feature:visible').fadeOut(300, function() {
			$('#featured .feature').eq(index).fadeIn();
			$mininav.unbind('click').bind('click', clicker);
		});
		
		return false;			
	}
	
	$mininav.bind('click', clicker);
	
});
