//jQuery.noConflict();

var paused = false;

 window.addEvent('domready', function() {
	callbackfunc.periodical(7000); // this will call callbackfunc() each 7 sec


	$('mainImage').addEvent('mouseover', function() {
	        paused = true;
	});
	$('mainImage').addEvent('mouseout', function(){
        	paused = false;
	});

	var i = 1;
	$('thumbs').getElements('a').each(function(e){
		e.addEvent('click', function(){
			return callbackfunc(e.id.split('href')[1]);
		});
	i++;
	});

});
function callbackfunc(next)
{ 
	var current;
 	var href;
	current = $('current').value * 1;

	if (next == null)
	{
		if (current == 5) 
		{
			next = 1;	
 		}
		else
		{
			next = current + 1;
		}		
	}
	if (paused == false)
{
	$('current').value = next;

$('mainImage').set('tween',{
                onComplete : function() {

	$('image'+next).getElements('a').each(function(e){
		href = e.href;	
	});

	$('mainImage').getElements('a').each(function(e){
		e.href = href; //change url.
	});
	$('mainImage').getElements('img').each(function(e){
		e.src = 'images/image'+next+'.jpg';
	});
	


		for (count=1;count<=5;count++)
		{
			if (count != next)
			{
				$('img'+count).src = 'images/image'+count+'thumbgray.jpg';
				$('img'+count).removeClass("selected");
			}
			else
			{
				$('img'+count).src = 'images/image'+count+'thumb.jpg';
				$('img'+count).addClass("selected");

			}
		}
	
	setTimeout("$('mainImage').set('tween').tween('opacity', 1)", 500);
}
        }).tween('opacity', 0);
}
return false;
}

