jQuery(document).ready( function($) {
	var clicked = false;
	$(".scroll li:odd").addClass("even");
	$(".scroll li:gt(0)").hide();
	$(".slider-nav li a").live("click", function() {
		if (!clicked) {
			//Get current active
			var active_a = $(".slider-nav li a.active");
			var current_num = active_a.html();
			var last_li = $(".slider-nav li").length-3;
			//If clicked a number
			if($(this).hasClass("num")) {
				current_num = $(this).html();
			}
			else {
				clicked = true;
				//If clicked previous
				if($(this).parent().hasClass("prev")) {
					current_num--;
					if(current_num == 0) current_num = last_li;
				}
				//If clicked next
				else {
					current_num++;
					if(current_num > last_li) current_num = 1;
				}
			}
			active_a.removeClass("active");
			//Add active class to newly focused element, fade out old articles, fade in active
			$(".slider-nav li:eq(" + current_num + ") a").addClass("active");
			$(".scroll li:visible").fadeOut(300, function() {
				var starting_index = current_num - 1;
				var fadeEl = $(".scroll li:eq(" + starting_index + ")");
				fadeEl.fadeIn(function() {
					clicked = false;
				});
			});
		}
		
	});
	var items_num = Math.round($(".scroll li").length);
	if(items_num > 1) {
		for(var i=1; i<=items_num; i++) {
			if(i == 1) {
				var a_class = ' active';
			}
			else {
				var a_class = '';
			}
			$(".slider-nav li.next").before('<li><a href="javascript:;" class="num' + a_class + '">' + i + '</a></li>');
		}
	}
	else {
		$(".slider-nav").hide();
	}
//	var slider_container_width = $("#slider").width();
//	var slider_width = $(".slider-nav").width();
//	var slider_nav_margin_left = parseInt(slider_container_width - slider_width)/2;
//	$(".slider-nav").css("margin-left", slider_nav_margin_left + 0 + "px");
	
//	function next_slide(hovered) {
//		//If not hovering, advance to next slide
//		if(hovered == 0) $(".slider-nav li.next a").click();									
//		
//		setTimeout(function() {
//			//See if currently hovering over announcements box
//			$("#slider li").hover(
//				function(){
//					$(this).addClass("hovered");
//				},
//				function(){
//					$(this).removeClass("hovered");
//				}
//			);
//			
//			var hovering = $("#slider li").is(".hovered");
//			
//			next_slide(hovering);
//		}, 6000);
//	}
//	
//	next_slide(1);
});
