var specials = new Array();
var previous_special_index = 0;
var active_special_index = 0;
var active_background = '';
var auto_index = 1;
var auto_special_rotation = setInterval("autoSelectSpecials()", 12000);

function autoSelectSpecials()
{
	if (auto_index > max_special_key)
	{
		auto_index = 0;
	}
	updateSpecial(auto_index);
	auto_index++;
}

function selectActiveSpecialThumb()
{
	$('#special_thumb_'+previous_special_index).css({
		border: '1px #FFF solid'
	});
	$('#special_thumb_'+active_special_index).css({
		border: '1px #C00 solid'
	});
}

function setActiveSpecialIndex(value)
{
	if (value > max_special_key)
	{
		value = 0;
	}
	previous_special_index = active_special_index;
	active_special_index = value;
	active_background = 'http://download.nextgen.at/images/specials/'+specials[active_special_index]['picture_large'];
}

function specialClickRoutine(key)
{
	clearInterval(auto_special_rotation);
	auto_index = key + 1
	if (auto_index > max_special_key)
	{
		auto_index = 0;
	}
	auto_special_rotation = setInterval("autoSelectSpecials()", 12000);
}

function updateSpecial(index)
{
	setActiveSpecialIndex(index);
	selectActiveSpecialThumb();
	updateSpecialContent();
}

function updateSpecialContent()
{
	// Update the href attribute, so it will not be overwritten with var special_content_html!
	$('#special_pic_url').attr({
		href: specials[active_special_index]['url']
	});
	var special_content_html = $('#special_content').html();
	var new_special_content = '<div id="special_content" style="background:url('+active_background+') no-repeat;">'+special_content_html+'</div>';
	$('#special_content').fadeOut(1000, function(){
		$('#special_content').replaceWith(new_special_content);
	})
}
