Rotator = new Class({

 options : {
 fade : 1500,
 timer : 3000
 },

 initialize: function(options){
 var self = this;

//this.idx = 1;
 this.idx = 0;
 this.setOptions(this.options, options);

 this.topImg = $(this.options.topImg);
 this.images = this.options.images;
 this.images.unshift(this.topImg.src);
 
 this.topLink = $(this.options.topLink);
 this.links = this.options.links;
 this.links.unshift(this.topLink.href);
 
 this.topLinkImg = $(this.options.topLinkImg);
 this.x_cord = this.options.x_cord;
 this.x_cord.unshift(this.topLinkImg.style.left);
 this.y_cord = this.options.y_cord;
 this.y_cord.unshift(this.topLinkImg.style.top);
 
 new Asset.images(this.images, {
 onComplete : function(){
 self.loaded();
 }
 });



 },


changeIndex : function(index){
	 this.idx = index;
	 this.botImg.setProperty('src',this.images[this.idx]);
	 this.topLink.href = this.links[this.idx];
    this.topLinkImg.setStyles({'left': this.x_cord[this.idx]});
    this.topLinkImg.setStyles({'top': this.y_cord[this.idx]});
 },
 
 loaded : function(){
 var self = this;
 
 this.botImg = new Element('img').setProperties({'id':'background_rotation_image','src' : this.images[this.idx]})
 .injectInside('main_image');
 this.fx = new Fx.Style(this.options.topImg, 'opacity', {duration:this.options.fade, onComplete: this.wait.bind(this) });
 
 this.fade();
 
 },

 fade : function(){
 this.botImg.setProperty('src',this.images[this.idx]);
 this.fx.start(1,0);
 this.topLink.href = this.links[this.idx];
 this.topLinkImg.setStyles({'left': this.x_cord[this.idx]});
 this.topLinkImg.setStyles({'top': this.y_cord[this.idx]});
 
 
 },

 wait : function(){
 this.topImg.src = this.images[this.idx];
 this.topImg.setStyles({'opacity': 1, 'visibility' : 'visible'});
 //this.options.timer = 10000;
 this.changeImage();
 this.wait.bind(self);
 this.waitID = this.fade.delay(this.options.timer,this);
 
 
 },


 changeImage : function(){
 this.idx = ( this.idx == this.images.length-1 ) ? 0 : ++this.idx;
 
 }
 
 
});

Rotator.implement( new Options );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Rotator2 = new Class({

 options : {
 fade : 5000,
 timer : 5000
 },

 initialize: function(options){
 var self = this;

//this.idx = 1;
 this.idx = 0;
 this.setOptions(this.options, options);

 //this.topLinkImg = $(this.options.topLinkImg);
 //this.topLink = $(this.options.topLink);
this.botImgLink =$(this.options.botImgLink);

 //this.links = this.options.links;
 //this.links.unshift(this.topLink.href);
 
 this.images = this.options.images;
 this.images.unshift(this.topLinkImg.src);
 
 this.y_cord = this.options.y_cord;
 this.y_cord.unshift(this.topLinkImg.style.top);

 new Asset.images(this.images, {
 onComplete : function(){
 self.loaded();
 }
 });

 },

 loaded : function(){
 var self = this;
 //this.botImgLink = new Element('img').setProperties({'id':'background_text_image','src' : this.images[this.idx]}).injectInside('action_image');
 
 this.fx = new Fx.Style(this.options.topLinkImg, 'opacity', {duration:this.options.fade, onComplete: this.wait.bind(this) });
  this.fx2 = new Fx.Style(this.options.botImgLink, 'opacity', {duration:this.options.fade});
  
 this.fade();
 },

 fade : function(){
	 
	
	
	
 this.botImgLink.setProperty('src',this.images[this.idx]);
 this.fx2.start(0,1);
 this.fx.start(1,0);
 
 
 //this.topLink.href = this.links[this.idx];
 this.botImgLink.setStyles({'top': this.y_cord[this.idx]});

 },

 wait : function(){
	  
 this.topLinkImg.src = this.images[this.idx];
 //this.topLinkImg.setStyles({'opacity': 1, 'visibility' : 'visible'});
 
 this.topLinkImg.setStyles({'opacity': 1, 'visibility' : 'visible', 'top': this.y_cord[this.idx]});

 this.changeImage();
 this.wait.bind(self);
 this.waitID = this.fade.delay(this.options.timer,this);
 },


 changeImage : function(){
 this.idx = ( this.idx == this.images.length-1 ) ? 0 : ++this.idx;
 
 }
					 
});

Rotator2.implement( new Options );
