var imrot_atNow = 0;
var imrot_transitionTime = 1000;
var imrot_durationTime = 7000;
var imrot_images = [];

function rotateImages(id, transitionTime, durationTime, images) {
	imrot_transitionTime = transitionTime;
	imrot_durationTime = durationTime;
	imrot_images = images;
	
	var html = "";
	for(var i=0; i<images.length; i++) {
	  var imgi = images.length - i - 1;
	  html += '<div id="fadeSlide'+i+'" style="position:absolute"><a title="'+images[imgi].title+'" href="'+images[imgi].url+'"><img alt="'+images[imgi].title+'" border="0" src="'+images[imgi].img+'" /></a></div>\n';
	}
	$(id).innerHTML = html;


	window.addEvent('load',function() {
		imrot_atNow = images.length-1;
		//imrot_hideAllOthers();
		setTimeout("imrot_nextSlide();", imrot_durationTime);
	});

}



function imrot_hideAllOthers() {
  for(var i=1; i<imrot_images.length; i++) {
    $("fadeSlide"+i).fx = $("fadeSlide"+i).effect('opacity', {duration: 0}).start(0);
  }

}

function imrot_nextSlide() {
  imrot_showImage(imrot_atNow, (imrot_atNow - 1 + imrot_images.length) % imrot_images.length);
  imrot_atNow = (imrot_atNow - 1 + imrot_images.length) % imrot_images.length;
  setTimeout("imrot_nextSlide();", imrot_durationTime);
}


function imrot_showImage(fromId, toId){
//  alert("from " + fromId + " to " + toId);
  tDiv = "fadeSlide"+fromId;
  vDiv = "fadeSlide"+toId;

  if($(tDiv).fx){$(tDiv).fx.stop();}
  if($(vDiv).fx){$(vDiv).fx.stop();}
  $(tDiv).fx = $(tDiv).effect('opacity', {duration: imrot_transitionTime}).start(0);
  $(vDiv).fx = $(vDiv).effect('opacity', {duration: imrot_transitionTime}).start(1);
}

