// $Id: rotate_news.js,v 1.1 2011-12-20 21:22:21 xim Exp $

var oStyle = $('<style type="text/css">.news_module ul { display: none; }</style>');
$("head").append(oStyle);

$(document).ready(function(){

    var iNumArticles = 3;
    var iDuration = 30000;

    var aLists = [];
    var oLists = $('<div class="news_module_lists" />');
    oLists.css("position", "relative");

    var iHeight = 0 ;

    $(".news_module").append($(oLists));
    $(".news_module ul li").each(function(index) {
	if (((index + iNumArticles) % iNumArticles) == 0) { 
	    oList = $('<ul style="visibility: hidden; background-color: #fff;" />');
	    oLists.append(oList);
	}
	oList.append($(this));
	iHeight = oList.height() > iHeight ? oList.height() : iHeight;
    });

    oLists.height(iHeight);

    oLists.find("ul").css({
	"display"    : "none", 
	"visibility" : "visible", 
	"position"   : "absolute"
    });
    
    rotate();

    function rotate() {
	oLists.find("ul:first-child").fadeIn();
	if (oLists.find("ul").size() < 2) return;
	oLists.find("ul:first-child").animate(
	    {"opacity": 1}, iDuration,
	    function() {
		oLists.append($(this).fadeOut());
		rotate();
	    }
	);	
    }

});


