// var images = new Array('/images/home3/canvas_images/1.jpg', '/images/home3/canvas_images/2.jpg', '/images/home3/canvas_images/3.jpg', '/images/home3/canvas_images/4.jpg', '/images/home3/canvas_images/5.jpg', '/images/home3/canvas_images/6.jpg', '/images/home3/canvas_images/7.jpg', '/images/home3/canvas_images/8.jpg', '/images/home3/canvas_images/9.jpg', '/images/home3/canvas_images/10.jpg');

var container = $('slide-images');
// var current = Math.floor(Math.random()*images.size());
var current = 0;


prepareBottom();

var executer = new PeriodicalExecuter(fadeTop, 4);

function fadeTop()
{
  new Effect.Fade(getTop(container), {afterFinish:swap, duration:1.0});
}

function dropTop()
{
  getTop(container).hide();
  swap();
}

function swap()
{
  container.appendChild(getBottom());
  prepareBottom();
}

function prepareBottom()
{
  bottom = getBottom();
  bottom.show();
  bottom.setStyle({backgroundImage:'url(' + nextImage() + ')'});
}

function nextImage()
{
  if(current >= images.size())
  {
    next = 0;
    current = 1;
  }
  else
  {
    next = current;
    current += 1;
  }
    
  // console.log(next + ' => ' + images[next]);
  return images[next];
}

function getBottom()
{
  return container.getElementsBySelector('.slide')[0];
}

function getTop()
{
  return container.getElementsBySelector('.slide')[1];
}




Event.observe(document, 'keypress', function(e){ 
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);

	if(character=='q')
	{
	  dropTop();
	}
	
});
