// --------------------------------------------------------------------------------
//
//	timura.js
//  (c) 2009 timura Holzmanufaktur
//
// --------------------------------------------------------------------------------


var PageSwap = Class.create();
PageSwap.prototype = {
	contentArray: [],
	animation_active: false,
	page_count: 1,
	current_page: 1,

	initialize: function() {
		var num = 0;
		this.contentArray = $$('div[class^=content]');
		while (this.contentArray[num]) {
			if (num>0) { this.contentArray[num].hide(); }
			num++;
		}
		this.page_count = num;
		
		document.observe('click', (function(event){
			var target = event.findElement('div[class^=pageswap]');
			if (target) {
				event.stop();
				this.swap(target);
			}
		}).bind(this));
	},

	swap: function(objectLink) {
		if (objectLink.hasClassName('up')) {
			if (this.current_page > 1) {
				if ((!this.animation_active) && this.contentArray[(this.current_page-1)] && this.contentArray[(this.current_page-2)]) {
					this.animation_active = true;
					new Effect.Fade(this.contentArray[(this.current_page-1)], { 
							duration: 0.75, from: 1.0, to: 0.0, queue: 'end', delay: 0.0 
						});
					new Effect.Appear(this.contentArray[(this.current_page-2)], { 
							duration: 0.75, from: 0.0, to: 1.0, queue: 'end', delay: 0.75 
						});
					this.current_page = this.current_page-1;
					(function(){
						this.animation_active = false;
					}).bind(this).delay(1.6);
				}
			}
		} else if (objectLink.hasClassName('down')) {
			if (this.current_page < this.page_count) {
				if ((!this.animation_active) && this.contentArray[this.current_page] && this.contentArray[(this.current_page-1)]) {
					this.animation_active = true;
					new Effect.Fade(this.contentArray[(this.current_page-1)], { 
							duration: 0.75, from: 1.0, to: 0.0, queue: 'end', delay: 0.0 
						});
					new Effect.Appear(this.contentArray[(this.current_page)], { 
							duration: 0.75, from: 0.0, to: 1.0, queue: 'end', delay: 0.75 
						});
					this.current_page = this.current_page+1;
					(function(){
						this.animation_active = false;
					}).bind(this).delay(1.6);
				}
			}
		}
	}
}
document.observe('dom:loaded', function () { var myPageSwap = new PageSwap(); });
