/*
===============================
DotControl copyright 2010
===============================
*/

$(function () {
	LogoRotator();
});


function LogoRotator() {
	// Image rotator script
	// place images in list items
	$('div.LogoRotator div.remove').remove();
	var ImageRotatorContentItems = "";
	$('div.LogoRotator img').each(function () {
		ImageRotatorContentItems += '<td> <a href="' + $(this).parent('a').attr("href") + '"><img src="' + $(this).attr("src") + '" title="' + $(this).attr("alt") + '" alt="' + $(this).attr("alt") + '" /></a></td>';
	});
	// place images (list items) in list
	var ImageRotatorContent = '<table cellspacing=0 cellpadding=0 valign=center><tr> ' + ImageRotatorContentItems + ' </tr></table>';
	// place images in list back into div
	$('div.LogoRotator').html(ImageRotatorContent);
	// give first li an extra class
	$('div.LogoRotator tr td:first').addClass("show");
	//Set the opacity of all images to 0
	$('div.LogoRotator tr td').css({ opacity: 0.0, display : 'none' });
	//Get the first image and display it (gets set to full opacity)
	$('div.LogoRotator tr td:first').css({ opacity: 1.0, display : 'table-cell' });
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()', 6000);
}

function rotate() {
	//Get the first image
	var current = ($('div.LogoRotator tr td.show') ? $('div.LogoRotator tr td.show') : $('div#rotator tr td:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.LogoRotator tr td:first') : current.next()) : $('div.LogoRotator tr td:first'));
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000).css({ display : 'table-cell' });
	//Hide the current image
	current.animate({ opacity: 0.0}, 1000)
	.removeClass('show').css({ display : 'none' });

};

