//Absolute URL syntax. Uncomment below line if you wish to use an absolute reference:
var rotator_url="http://"+window.location.hostname+"/lib/banners/banner.php"

var banner_ajax = Class.create({
	initialize: function(a) {
		this.ban = a;
		this.par = 'ban_' + this.ban;
		this.time = 0;
		this.delay = 10000;
		this.mo = false;
		
		this.tt = null;
		
		this.get();
	},
	
	get: function() {
		this.options = {
			parameters: "ban_group=" + this.ban + "&bustcache=" + new Date().getTime(),
			method: 'GET',
			onCreate: function() {
				if(!$(this.par)) {
					document.write('<div id="ban_'+this.ban+'" class="ban_'+this.ban+'" >Initializing banner...</div>');
				}
			}.bind(this),
			onSuccess: function(r) {
				$(this.par).innerHTML = r.responseText;
				
				if($(this.par).style.display == 'none') {
					new Effect.Appear(this.par, { duration: 0.2, afterFinish: function() { this.rotate(); }.bind(this)});
				} else { 
					this.rotate();
				}
				
				$(this.par).observe('mouseover', function() { this.mo = true; }.bind(this));
				$(this.par).observe('mouseout', function() { this.mo = false; }.bind(this));
			}.bind(this)
		}
		
		new Ajax.Request("/lib/banners/banner.php", this.options);
	},
	
	rotate: function() {
		if(this.mo) {
			setTimeout(function(){ this.rotate(); }.bind(this), this.delay);
		} else {
			setTimeout(function() {
				new Effect.Fade(this.par, {duration: 0.2, afterFinish: function() {
					this.get();
				}.bind(this)});
			}.bind(this), this.delay);
		}
	}
});
