jQuery.preloadImages = function()
{
	for(var i = 0; i < arguments.length; i++)
	{
		jQuery('<img>').attr('src', arguments[i]);
	}

	return true;
}

$(document).ready(function() {
	if ($('#slideshow ul.slides li').length > 1) slideshow.startup();
});

var slideshow =
{
	currentPosition: 1,
	count: 0,
	fadeTimeout: 3000,
	timeout: 8000,
	timeoutId: null,

	startup: function()
	{
		$('#slideshow ul.slides li:gt(0)').hide();

		this.count = $('#slideshow ul.slides li').length;
		this.timeoutId = setTimeout('slideshow.playNext()', slideshow.timeout);

		this.paging();
	},

	changeInfo: function()
	{
		$('#slideshow dl.info dt').text($('#slideshow ul.slides li:eq(' + (this.currentPosition - 1) + ') dl dt').text());
		$('#slideshow dl.info dd p').html($('#slideshow ul.slides li:eq(' + (this.currentPosition - 1) + ') dl dd p').html());
	},

	paging: function()
	{
		$('#slideshow dl.info').after('<ul class="paging"></ul>');

		for (var x = 1; x <= this.count; ++x)
		{
			$('#slideshow ul.paging').append('<li><a href="#" rel="' + x + '">' + x + '</a></li>');
		}

		$('#slideshow ul.paging li a:eq(0)').addClass('active');
		$('#slideshow ul.paging li a').click(
			function()
			{
				clearTimeout(slideshow.timeoutId);
				slideshow.playSlide(this.rel);

				return false;
			}
		);
	},

	playSlide: function(position) {
		this.currentPosition = position;

		this.transition();

		this.timeoutId = setTimeout('slideshow.playNext()', (slideshow.timeout * 2));
	},

	playNext: function()
	{
		if (this.currentPosition != this.count) {
			this.currentPosition++;
		}
		else
		{
			this.currentPosition = 1;
		}

		this.transition();

		this.timeoutId = setTimeout('slideshow.playNext()', slideshow.timeout);
	},

	transition: function()
	{
		$('#slideshow dl.info').animate(
			{height: 0},
			800,
			function()
			{
				slideshow.changeInfo();
			}
		);
		$('#slideshow ul.slides li').fadeOut(this.fadeTimeout);
		$('#slideshow ul.paging li a').removeClass('active');
		$('#slideshow ul.paging li a:eq(' + (this.currentPosition - 1) + ')').addClass('active');
		$('#slideshow ul.slides li:eq(' + (this.currentPosition - 1) + ')').fadeIn(this.fadeTimeout);
		$('#slideshow dl.info').animate(
			{height: '89px'},
			800
		);
	},

	preload: function() {

	}
};