var current = 1;
var next = 1;
var delayTimer = 0;

function setFlag(){
	animationFlag = 1;
	setTimeout("animationFlag = 0;", 1000);
}

function readNews(content_id){
	//$("#reader_content").load("/modules/home/content/feature"+content_id+".html");
	$("#reader_content").load("/?m=content&index="+content_id);
	$("#reader:hidden").slideDown(1000);
}


function rotateFeature(){
	if(delayTimer == 0){
		next++;
		if(next>5){
			next = 1;
		}
		if(next == current){
			next++;
		}
		showFeature(next, 700);
	} else {
		delayTimer = 0;
	}	
	setTimeout ("rotateFeature()", 4000);
}

function showFeature(event_id, speed){
	if(current == event_id){
		// readNews(event_id);
	} else {
		$("#feature_"+event_id).addClass("selected_feature");
		$("#feature_"+current).removeClass("selected_feature");
		
		$("#feature_"+current).fadeTo(speed, 0);
		$("#feature_"+event_id).fadeTo(speed, 1);
		
		$("#feature_thumb_"+event_id).addClass('selected_feature_thumb');
		$("#feature_thumb_"+current).removeClass('selected_feature_thumb');
		
		current = event_id;
		delayTimer = 1;
	}
} 

function wait(){
}

$(document).ready(function(){
	if($.browser.msie) {setTimeout('wait()', 100);}
	for(i=1; i<=5; i++){
		$("#feature_thumb_"+i).click(function(){
			showFeature($(this).attr("id").substr(14,1), 700);
		});
		if(i!=1){
			$("#feature_"+i).animate({
				opacity: 0
			}, 0);
			$("#feature_"+i).show();
		}
	}

	$(".feature_thumb a").click(function() {
		readNews($(this).parents(".feature_thumb").attr("id").substr(14,1));
	});
		
	$("#reader_close").click(function(){
		$("#reader").slideUp(1000);	
	});
	
	setTimeout ("rotateFeature()", 6000);
});
