PAGEADSAPP = function () {
	this.simple = window.XMLHttpRequest ? false : true;
	this.available = document.getElementById && !this.simple;
	this.setupdone = false;
	this.playing = false;
	this.record = 0;
	this.pos = 0;
	this.alpha = 100;
	this.speed = 20;
	this.alphaspeed = 10;
	this.wait = 5000;
	this.control;
	this.alphacontrol;
	this.closingImage = false;
	this.openingImage = false;
	this.changeAd = function(p) {
		if(this.available) {
			if(!this.setupdone) this.setup();
			this.stop();
			if(this.currentpos != p) {
				this.pos = p;
				this.change();
			}
			return false;
		} else {
			return true;
		}
	}
	this.change = function() {
		var button;
		button = this.getItem('pageads_link_' + this.buttonpos);
		this.changeClass(button, '');
		this.buttonpos = this.pos;
		button = this.getItem('pageads_link_' + this.buttonpos);
		this.changeClass(button, 'pageads-current-link');
		if(this.openingImage) {
			clearTimeout(this.alphacontrol);
			this.closeImage();
		} else if(this.closingImage) {
		} else {
			this.closeImage();
		}
	}
	this.closeImage = function() {
		this.closingImage = true;
		this.hideImage();
	}
	this.hideImage = function() {
		if(this.alpha > 0) {
			this.alpha -= this.alphaspeed;
			this.setAlpha(this.holder);
			this.alphacontrol = setTimeout(this.name + '.hideImage();', this.speed);
		} else {
			this.closingImage = false;
			this.openImage();
		}
	}
	this.openImage = function() {
		this.openingImage = true;
		this.currentpos = this.pos;
		this.changeClass(this.holder, 'pageads-imageholder-' + this.pos);
		this.showImage();
	}
	this.showImage = function() {
		if(this.alpha < 100) {
			this.alpha += this.alphaspeed;
			this.setAlpha(this.holder);
			this.alphacontrol = setTimeout(this.name + '.showImage();', this.speed);
		} else {
			this.openingImage = false;
			this.doPlay();
		}
	}
	this.play = function() {
		if(!this.setupdone) this.setup();
		this.playing = true;
		this.doPlay();
	};
	this.stop = function() {
		clearTimeout(this.control);
		this.playing = false;
	};
	this.doPlay = function() {
		if(this.playing) this.control = setTimeout(this.name + '.nextImage();', this.wait);
	};
	this.nextImage = function() {
		this.pos = (this.pos != this.record) ? this.pos+1 : 1;
		this.change();
	};
	this.setup = function() {
		this.buttonpos = this.pos;
		this.currentpos = this.pos;
		this.holder = this.getItem('pageads_imageholder');
		this.setupdone = true;
	};
	this.setAlpha = function(obj) {
		obj.style.opacity = this.alpha/100;
		obj.style.filter = 'alpha(opacity=' + this.alpha + ')';
	}
	this.getItem = function(obj) {
		var obj = (document.getElementById(obj) != undefined) ? document.getElementById(obj) : false;
		if (!obj && !obj.style) obj.style = obj;
		return obj;
	};
	this.changeClass = function(obj, name) {
		obj.className = name;
	};
}
function playPageAds() {
	pageads.play();
}
pageads = new PAGEADSAPP();
pageads.name = "pageads";