var effect_duration = 500;
var effect_rotation;
var effect_rotation_interval = '5000'; // Setting a 5 second interval for automate move and fed effects

function make_it_visible(tDiv){
	document.getElementById(tDiv).style.visibility = 'hidden';
}

function show(whichOne){
	var which_img = $('which_img')
	
	if(whichOne == which_img.value){ return false;}
	var vDiv = "div"+whichOne;
	var tDiv = "div"+which_img.value
	var oldLi = "slideLi"+which_img.value
	var newLi = "slideLi"+whichOne;
	which_img.value = whichOne;
	var image2fed = $(vDiv);
	var img2fedFx = new Fx.Style(image2fed, 'opacity', {
			wait: false,
			duration: effect_duration + 200,
			transition: Fx.Transitions.Quart.easeInOut
		});

	img2fedFx.start(0, 1);
	image2fed.style.visibility = 'visible';
	$(oldLi).style.background = "none";
	$(newLi).style.background = "url(images/slider-li-hover.png)";
	
	var image2vanish = $(tDiv);
	var img2vanishFx = new Fx.Style(image2vanish, 'opacity', {
			wait: false,
			duration: effect_duration + 200,
			transition: Fx.Transitions.Quart.easeInOut
		});
	
	img2vanishFx.start(1, 0);	
}

function move_down(top_end, image2show, auto_move){
	var target = $('target');
	var box = $('slider');
	var fx = new Fx.Styles(target, {duration: effect_duration, wait: true});
	
	var transition = 'Cubic';
	var ease = 'easeIn';
	fx.options.transition = Fx.Transitions[transition][ease];
	transition = 'Fx.Transitions.' + transition + '.' + ease;

if(auto_move != 1){
		fx.start({
			'left': top_end
		});
		
		show(image2show);
		
		clearInterval(effect_rotation);
		effect_rotation = setInterval('move_down(241, 2, 1)', effect_rotation_interval);
	}
	else{
		var which_img = $('which_img');
		
		if(which_img.value == 1){
			fx.start({
				'left': 241
			});
			show(2);
			which_img.value = 2;
		}
		else if(which_img.value == 2){
			fx.start({
				'left': 441
			});
			show(3);
			which_img.value = 3;
		}
		else if(which_img.value == 3){
			fx.start({
				'left': 641 
			});
			show(4);
			which_img.value = 4;
		}
		else if(which_img.value == 4){
			fx.start({
				'left': 31
			});
			show(1);
			which_img.value = 1;
		}
		 
	}
}


function start_auto_moving(){
	effect_rotation = setInterval('move_down(241, 2, 1)', effect_rotation_interval);
}

window.addEvent('domready', function(){

		start_auto_moving();
	 
});
