﻿var as = [];
var curr_index = 0;
var duration = 1500;
var stop_duration = 5000;
var _max_height = 0;

function initPage()
{

	var _news = document.getElementById('last-news');
	
	if(_news)
	{	
		_news.style.position = "relative";
		_max_height = 0;
		var _as = _news.getElementsByTagName('ul');
		var cnt = 0;
		var total_cnt = 0;

		for(i = 0; i < _as.length; i++)
		{
			if(_as[i].parentNode.id == "last-news")
			{
				total_cnt++;
			}
		}		
		for(i = 0; i < _as.length; i++)
		{
			if(_as[i].parentNode.id == "last-news")
			{

				as[cnt] = _as[i];
				as[cnt]._index = cnt;
				as[cnt]._height = as[cnt].offsetHeight;
				
				as[cnt].style.position = "absolute";
				as[cnt].style.left = "0px";				
				
				if(as[cnt].offsetHeight > _max_height) _max_height = as[cnt].offsetHeight;
				
				if(cnt == total_cnt-1)
				{
					as[cnt].style.top = "0px";
				}
				else
				{
					as[cnt].style.top = - as[cnt]._height + "px";
				}

				cnt++;				
			}
		}


		_news.style.height = _max_height + "px";
		_news.style.overflow = "hidden";
		_news.style.visibility = "visible";

		curr_index = as.length - 1;
		_switch();
	}
	
}


function _switch()
{
	var as_cnt = as.length;
	if(as_cnt > 1)
	{
			var _opacity1 = new fx.Styles( as[curr_index], {duration: duration,
				
				onStart: function(){},
				onComplete: function()
				{
					setTimeout('_remove()',duration + stop_duration);	
				}	
				
				});

		
			_opacity1.custom({'top': [-1*as[curr_index]._height,0]});	
	}
}


function _remove()
{
	var as_cnt = as.length;
	if(as_cnt > 1)
	{
			var _opacity1 = new fx.Styles( as[curr_index], {duration: duration,
				
				onStart: function(){},
				onComplete: function(){}	
				
				});
		
			_opacity1.custom({'top': [0,_max_height]});
	}

	var next_index = curr_index + 1;
	if(next_index == as_cnt) next_index = 0;
	curr_index = next_index;
	
	setTimeout('_switch()',duration);		
}


if (window.attachEvent){
	window.attachEvent("onload", initPage);
	}
else if (window.addEventListener){
	window.addEventListener("load", initPage, false);
	}