$(document).ready(function(){
	$('#Top .Right img').mouseover(function(){
		SetNewItem($(this));
		UnsetInterval();
	});
	$('#Top').hover(function(){UnsetInterval();}, function(){SetInterval()});
	ChangeItemData();
	SetInterval();
	
	$('ul.Pages li').hover(function(){
		$(this).children('div.Advanced').removeClass('Hidden');
	}, function(){
		$(this).children('div.Advanced').addClass('Hidden');
	});
	
	$('#Navigation ul li').hover(function(){
		$(this).children('ul').removeClass('Hidden');
	}, function(){
		$(this).children('ul').addClass('Hidden');
	});
});

var IntervalID = 0;

function SetInterval()
{
	if (IntervalID == 0)
	{
		IntervalID = window.setInterval('ChangeItemData()', 3000);
	}
}

function UnsetInterval()
{
	window.clearInterval(IntervalID);
	IntervalID = 0;
}

function ChangeItemData()
{
	var actual_index = false;
	var new_index = false;
	
	$('#Top .Right img').each(function(index){
		if (new_index != true)
		{
			if (actual_index != false)
			{
				SetNewItem($(this));
				new_index = true;
			}
			else if ($(this).is('.Active'))
			{
				actual_index = true;
			}
		}
	});
	
	if (new_index == false)
	{
		SetNewItem($('#Top .Right img:first'));
	}
}

function SetNewItem(img)
{
	UnsetAllItems();
	img.addClass('Active');
	
	$('#Top .Left .Image a.Name').html(img.next().children('.Name').html());
	$('#Top .Left .Image div a img').attr('src', img.next().children('.Image').html());
	$('#Top .Left .Image .Anotation').html(img.next().children('.Description').html());
	$('#Top .Left .Image .Company').html(img.next().children('.Company').html());
	$('#Top .Left .Image a').attr('href', img.next().children('.Url').html());
}

function UnsetOldItem(img)
{
	img.removeClass('Active');
}

function UnsetAllItems()
{
	$('#Top .Right img').each(function(index){
		UnsetOldItem($(this));
	});
}
