var rotate_images_path = 'pics/';
var rotate_images = new Array('img1.jpg', 'img2.jpg');
var rotate_index = 0;
var rotate_timeout_before_change = 6000;
var rotate_timeout_onstart = 6000;
var rotate_object_id = 'rotateobject';

for( var i=0; i<rotate_images.length; i++)
{
	var im = new Image();
	im.src = rotate_images_path + rotate_images[i];
}

/*
function rotate_hide()
{
	var tw = $(rotate_object_id).get('tween', {property: 'opacity', duration: 'long'});
	tw.complete = function() {
		tw.cancel();
	}
	tw.start(0);
}
*/

function xxx()
{
	rotate_index++;
	if (rotate_index >= rotate_images.length)
	{
		rotate_index = 0;
	}

	$(rotate_object_id).src = rotate_images_path + rotate_images[ rotate_index ];
	
	
	var tw = $(rotate_object_id).get('tween', {property: 'opacity', duration: 'long'});
	tw.complete = function() {
		tw.cancel();
		setTimeout('rotate_next();', rotate_timeout_before_change);
	}
	tw.start('1.0');
}

function rotate_show()
{
	var tw = $(rotate_object_id).get('tween', {property: 'opacity', duration: 'long'});
	tw.complete = function() {
		tw.cancel();
		xxx();
	}
	tw.start(0);
}

function rotate_next()
{
	//$(rotate_object_id).src = rotate_images_path + rotate_images[ rotate_index ];
	setTimeout('rotate_show();', 1);
}

window.addEvent('domready', function() {
    setTimeout('rotate_next();', rotate_timeout_onstart);
});