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
	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';
	
	
	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 = $('box');
	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({
			'top': top_end,
			'right': 0
		});
		
		show(image2show);
		
		clearInterval(effect_rotation);
		effect_rotation = setInterval('move_down(72, 2, 1)', effect_rotation_interval);
	}
	else{
		var which_img = $('which_img');
		
		if(which_img.value == 1){
			fx.start({
				'top': 71,
				'right': 0
			});
			show(2);
			which_img.value = 2;
		}
		else if(which_img.value == 2){
			fx.start({
				'top': 120,
				'right': 0
			});
			show(3);
			which_img.value = 3;
		}
		else if(which_img.value == 3){
			fx.start({
				'top': 169,
				'right': 0
			});
			show(4);
			which_img.value = 4;
		}
		else if(which_img.value == 4){
			fx.start({
				'top': 218,
				'right': 0
			});
			show(5);
			which_img.value = 5;
		}
		else if(which_img.value == 5){
			fx.start({
				'top': 23,
				'right': 0
			});
			show(1);
			which_img.value = 1;
		}
	}
}


function start_auto_moving(){
	effect_rotation = setInterval('move_down(72, 2, 1)', effect_rotation_interval);
}

window.addEvent('domready', function(){
	start_auto_moving();
	var mySlide = new Fx.Slide('log_tog');
	mySlide.hide();
	
	$('toggle').addEvent('click', function(e){
		e = new Event(e);
		mySlide.toggle();
		e.stop();
	});	
});
