/* Rotating Content */
var nLI = Array();
var nMaxLi = Array();
var Timeout = 0;
var timerId = null;
/* Ready */
$(document).ready(function() {
	/* Rotating Content */	
	$('ul.st_RotatingContent').each(function(){
	
		$('> li:first', this).show();
		return;
	});
	
	$('div.st_RotatingContent ul.st_Tab > li:first').toggleClass('selected');
	
	Timeout = $('div.st_RotatingContent input.st_Timeout').val();
	
	var nIndex = 0;
	$('ul.st_RotatingContent').each(function(){
		nLI[nIndex] = 0;
		nMaxLi[nIndex] = $('> li', this).size() - 1;
		nIndex++;
	});
	
	//nMaxLi = $('ul.st_RotatingContent > li').size();
	
	//alert(nMaxLi[1]);
	
	//nMaxLi--;
	
	if (Timeout > 0)
	{
		timerId = setTimeout(nextItem, Timeout);
	}
	
    $('div.st_RotatingContent ul.st_Tab li.st_Tab a').click(function() {
		var nIndex = $('div.st_RotatingContent ul.st_Tab li.st_Tab').index($(this).parents('div.st_RotatingContent ul.st_Tab li.st_Tab')); 
		// Hide all rotating content items
		$('div.st_RotatingContent ul.st_RotatingContent > li:eq(' + nLI[0] + ')').fadeOut(500);
		$('div.st_RotatingContent ul.st_Tab > li:eq(' + nLI[0] + ')').removeClass('selected');
		// Highlight the selected rotating item
		$('div.st_RotatingContent ul.st_Tab > li:eq(' + nIndex + ')').addClass('selected');
	    $('ul.st_RotatingContent > li:eq(' + nIndex + ')').fadeIn(500);
	    nLI[0] = nIndex;
	    if (timerId != null)
	    {
	    	clearTimeout(timerId);
	    	timerId = setTimeout(nextItem, Timeout);
	    }
    });
});

var nextItem = function() {
	

	//	$('ul.st_RotatingContent > li:eq(' + nLI[i] + ')').fadeOut(1000);
		
		var nIndex = 0;
		$('ul.st_RotatingContent').each(function(){
			$('> li:eq('+nLI[nIndex]+')', this).fadeOut(1000);
			
			$('ul.st_Tab > li').removeClass('selected');

			
		    if (nLI[nIndex] >= nMaxLi[nIndex])
		    {
		        nLI[nIndex] = 0;
		    }
		    else
		    {
		        nLI[nIndex]++;
		    }
		    
		    $('> li:eq('+nLI[nIndex]+')', this).fadeIn(1000);

			$('div.st_RotatingContent ul.st_Tab > li:eq(' + nLI[nIndex] + ')').addClass('selected');
					    
		    //$('ul.st_RotatingContent > li:eq(' + nLI[i] + ')').fadeIn(1000);
			
			//$('div.st_RotatingContent ul.st_Tab > li:eq(' + nLI[i] + ')').addClass('selected');
		    
	    	nIndex++;
		});
		






    timerId = setTimeout(nextItem, Timeout);
    
    
};

