function ImageRotate(elementName,fadeDelay,imageDelay) {
	this.d = null;
	this.imgs = new Array()
	this.zInterval = null
	this.current = 0
	this.pause=false;
	this.t1 = null;
	this.t2 = null;
	this.t3 = null;
	
	this.element = elementName;
	
	this.fadeDelay = fadeDelay?fadeDelay:125;
	this.imageDelay = imageDelay?imageDelay:3000;
	
	this.ondisplay = null;
}
ImageRotate.prototype.init = function() {
	ImageRotate.addEvent(window,"load",start);
}

ImageRotate.prototype.start = function(autostart) {
	var obj = this;
	
	this.d = document;

	if (!this.d.getElementById || !this.d.createElement) return;
	
	if (!this.d.getElementById(this.element)) return;
	
	this.imgs = $$('#flash_display .image_display');

	if(this.imgs.length>0){
	    for(var i=1;i < this.imgs.length;i++)  {
			this.imgs[i].xOpacity = 0;
			this.imgs[i].style.opacity = 0;
			this.imgs[i].style.MozOpacity = 0;
			this.imgs[i].style.filter = "alpha(opacity=0)";
			this.imgs[i].style.display = "none";
		}
		
		this.imgs[0].xOpacity = 1;
		this.imgs[0].style.opacity = 1;
		this.imgs[0].style.MozOpacity = 1;
		this.imgs[0].style.filter = "alpha(opacity=100)";
		this.imgs[0].style.display = "block";
		
		if (autostart)
		    this.t1 = setTimeout(function () {obj.fade(obj);},1000);
		
		if (obj.ondisplay) {
			obj.ondisplay(0);
		}
	}
}

ImageRotate.prototype.play = function() {
	if (this.pause) {
		this.pause = false;
		
		this.fade(this);
	}
	
	return false;
}

ImageRotate.prototype.stop = function() {
	this.pause = true;
	
	return false;
}

ImageRotate.prototype.displayImage = function(index) {
	var obj = this;
	
	obj.pause = true;
	clearTimeout(obj.t1);
	clearTimeout(obj.t2);
	
	for(i=0;i<obj.imgs.length;i++) 
	{
	    obj.imgs[i].xOpacity = 0;
		obj.imgs[i].style.opacity = 0;
		obj.imgs[i].style.MozOpacity = 0;
		obj.imgs[i].style.filter = "alpha(opacity=0)";
    	obj.imgs[i].style.display = "none";
	}
	
	obj.current = index;
    obj.imgs[obj.current].xOpacity = 100;
	obj.imgs[obj.current].style.opacity = 100;
	obj.imgs[obj.current].style.MozOpacity = 100;
	obj.imgs[obj.current].style.filter = "alpha(opacity=100)";
	obj.imgs[obj.current].style.display = "block";
	
	if (obj.ondisplay) {
		obj.ondisplay(obj.current);
	}
	
	return false;
}

ImageRotate.prototype.fadeIn = function(obj) {
}

ImageRotate.prototype.fade = function(obj) {
	var cOpacity = obj.imgs[obj.current].xOpacity?obj.imgs[obj.current].xOpacity:.99;
	var nIndex = obj.imgs[obj.current + 1]?obj.current + 1:0;
	var nOpacity = obj.imgs[nIndex].xOpacity;
		
	cOpacity -= .1; 
	nOpacity += .05;
	
	obj.imgs[nIndex].style.display = "block";
	
	if (cOpacity > 0)
		obj.imgs[obj.current].xOpacity = cOpacity;
	obj.imgs[nIndex].xOpacity = nOpacity;
	
	ImageRotate.setOpacity(obj.imgs[obj.current]); 
	ImageRotate.setOpacity(obj.imgs[nIndex]);
	
	if(nOpacity >= 1) {
		obj.imgs[obj.current].style.display = "none";
		obj.current = nIndex;
		
		if (!obj.pause)
			obj.t2 = setTimeout(function () {obj.fade(obj);},obj.imageDelay);
		
		if (obj.ondisplay) {
			obj.ondisplay(nIndex);
		}
	} else {
		obj.t2 = setTimeout(function () {obj.fade(obj);},obj.fadeDelay);
	}
}

ImageRotate.setOpacity = function (obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

ImageRotate.addEvent = function (obj, name, handler) {
	// Browser check
	if (Calendar.isMSIE)
		if (!Calendar.isMAC) {
			obj.attachEvent("on" + name, handler);
		} else {
			switch (name) {
				case 'load':obj.onload = handler;break;
				case 'focus':obj.onfocus = handler;break;
				case 'blur':obj.onblur = handler;break;
				case 'resize':obj.onresize = handler;break;
			}
		}
	else
		obj.addEventListener(name, handler, false);
};

//Navigation
Fx.Properties = Fx.Styles.extend({	
	increase: function(){for (	var p in this.now) this.element[p] = this.now[p];	}	
});

Fx.FlyingScroller = Fx.Properties.extend({
	initialize: function(el, options){
		this.parent(el, options);
		this.options = Object.extend(this.options || {}, Object.extend({
			paddingLeft: 0,
			paddingTop: 0
		}, options || {}));
		
		this.goTo(0,0);
	},
	toElement: function(el, paddingLeft, paddingTop){
		var selectedEl = el;
		this.goTo(el.offsetLeft - (paddingLeft || this.options.paddingLeft || 0), el.offsetTop - (paddingTop || this.options.paddingTop || 0));
	},
	goTo: function(x, y){
		this.start({
			'scrollLeft': [this.element.scrollLeft, x],
			'scrollTop': [this.element.scrollTop, y]
		})
	}
});

window.addEvent('load', function(){
	init();
});
	
var navigation = null;

function init() {
	navigation = new Fx.FlyingScroller($('display_images'), {
							transition: Fx.Transitions.quadInOut,
							duration: 1000,
							paddingLeft: 0,
							paddingTop: 0
						});
						
	var linkuri = $$('a');
	for (m=0; m<linkuri.length; m++)
	{
		if(linkuri[m].getAttribute('rel')=='gallery')
		{
			linkuri[m].onclick = function () {
											navigation.clearTimer().toElement($(this.className)); 
	
											return false;  
									}
		}
	}
	
	navigation.clearTimer().toElement($('page1')); 
}
