var startBlogs = 0;
var sBlog = 0;
var crrBlog = 0;
var blogInterval;


 $(function(){
	$('#blogs li:first').show();
	autorunBlogs();

	var li = $("li", "#blogs");
	sBlog = li.size() - 1; // Get size of ul
	
	$('#navblogs .btnext').click(function(){
		clearInterval(blogInterval);

		if (startBlogs < sBlog) {
			goSecBlogs(startBlogs+1);
		}
		
		autorunBlogs();
		return false;
	});
	$('#navblogs .btprev').click(function() {
		clearInterval(blogInterval);
		
	 	if(startBlogs > 0){
			goSecBlogs(startBlogs-1);
		}
		autorunBlogs();
		return false;
	});
	
});
function btstatusBlogs(){
	if(startBlogs == 0){
	    $('#navblogs .btprev').css({ 'background-position': 'center bottom', cursor: 'normal' });
	    $('#navblogs .btnext').css({ 'background-position': 'center top', cursor: 'pointer', cursor: 'hand' });
	}else if(startBlogs == 4){
	$('#navblogs .btnext').css({ 'background-position': 'center bottom', cursor: 'normal' });
	}else{
	$('#navblogs .btnext').css({ 'background-position': 'center top', cursor: 'pointer', cursor: 'hand' });
	$('#navblogs .btprev').css({ 'background-position': 'center top', cursor: 'pointer', cursor: 'hand' });
	}
}
function goSecBlogs(i){

    resetBlog();
	$('#blogs li').each(function(e){ //e :that is index of li
		if(e == i){
			hsec = $(this).children('div').children('span.hsect').html() + " ("+ (i+1) +" of "+ (sBlog+1) +")";
			$('#sechead').html(hsec);
			$(this).fadeIn('fast');
			startBlogs = i;
			crrBlog = i;
		}
	});
	btstatusBlogs();
}
function resetBlog(){
	$('#blogs li').each(function(e){ //e :that is index of li
	if (e == crrBlog) {
			$(this).hide();
		}
	});
}
function autorunBlogs(){
	blogInterval = setInterval('intirunBlogs()', 7500);
}
function intirunBlogs(){
	startBlogs += 1;
	if(startBlogs >= 5) startBlogs = 0;
	goSecBlogs(startBlogs);
}