var ImageSwapper = new Class(
{
	initialize: function()
	{
		this.initNewsItemSwapper();
	},

	initNewsItemSwapper: function()
	{
		if($chk($('boxNewsDeskContent')))
		{
			var newsSwapIndex = new Element('span');
			newsSwapIndex.setStyles({'display':'none'});
			newsSwapIndex.id = 'newsSwapIndex';
			newsSwapIndex.setText("0");
			newsSwapIndex.injectInside($('boxNewsDeskContent'));
			
			maxItems = 2;
			if($chk($('newsdesk_box_count')))
			{
				maxItems = $('newsdesk_box_count').value - 1;
			}
			
			var swapNews = function()
			{
				var newsBoxItems = $$('div.newsboxitem');
				
				var newsSwapIndex = $('newsSwapIndex').getText();
				newsSwapIndex = parseInt(newsSwapIndex)
				
				if($chk(newsBoxItems[newsSwapIndex]))
				{
					newsBoxItems[newsSwapIndex].setStyles({'display':'block', 'opacity':'1'});
					
					var fx = newsBoxItems[newsSwapIndex].effects({duration: 1000, transition: Fx.Transitions.Quart.easeInOut});
					fx.start({
						'opacity': 0
					}).chain(function()
					{
						newsBoxItems[newsSwapIndex].setStyles({'display':'none', 'opacity':'0'});
						
						newsSwapIndex++;
						if(newsSwapIndex > maxItems)
						{
							newsSwapIndex = 0;
						}
						
						$('newsSwapIndex').setText(newsSwapIndex);
						
						newsBoxItems[newsSwapIndex].setStyles({'display':'block', 'opacity':'0'});
						var fx = newsBoxItems[newsSwapIndex].effects({duration: 1000, transition: Fx.Transitions.Quart.easeInOut});
						fx.start({
							'opacity': 1
						});
					});
				}
			}
			
			swapNews.periodical(10000, this);
		}
	}
});

window.addEvent('domready', function()
{
	var imageSwapper = new ImageSwapper();
});