// JavaScript Document// JavaScript Document

var adChanger = Class.create();
adChanger.prototype = {
	
	elements: [],
	hrefs:[],
	imageID:'ad',
	classname:'fold',
	index:0,
	periodicalEx:null,
	
	initialize: function(elements, hrefs, imageID) {
 		this.elements = elements;
		this.hrefs = hrefs;
		this.imageID = imageID
		
		this.doChange();
		this.startChanging();
		
  	},
	
	startChanging: function () {

		new PeriodicalExecuter(
			
			this.change.bind(this)
		
		, 5);
	},
	
	stopChanging: function(ev) {
		this.periodicalEx.stop();
	},
	
	change: function (pe) {
				
				//$(this.imageID).observe('mouseover', 	function(ev){ if( Event.element(ev).tagName == 'IMG' ) this.stop(); Event.stop(ev); }.bindAsEventListener(pe)  );
				//$(this.imageID).observe('mouseout', 		function(ev){ if( Event.element(ev).tagName == 'IMG' ) this.startChanging.bind(this) ;  }.bindAsEventListener(this)  );
				
				this.doChange();
				
				
				
	},
	
	doChange:function() {
			$(this.imageID).src = this.elements[this.index];
			$(this.imageID).up('a').href = this.hrefs[this.index];
				
			this.index++;
				
			if(this.index == this.elements.length ) this.index=0;
	}
	
}
