




Effect.Wait=Class.create();
Object.extend(Object.extend(Effect.Wait.prototype,Effect.Base.prototype),{
initialize:function(element){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
var options=Object.extend({},arguments[1]||{});
this.start(options);
}
});


if(typeof(AC)=="undefined")AC={};


AC.CrossfadeQueue=Class.create();
AC.CrossfadeQueue.prototype={
index:0,queue:null,container:null,scope:null,safetyDiv:null,delay:6.0,
fadeInTime:0.5,fadeOutTime:0.5,
defaultQueueName:"defaultXFadeQueue",
currentNode:null,
stopped:false,
initialize:function(nodes,container,delay,queueName,fadeInTime,fadeOutTime){
this.container=$(container);
this.scope=container;
this.queue=$A(nodes);

if(delay)this.delay=delay;
if(queueName)this.defaultQueueName=queueName;
if(fadeInTime)this.fadeInTime=fadeInTime;
if(fadeOutTime)this.fadeOutTime=fadeOutTime;



if(typeof(this.queue[0])=="string"){
this.container.innerHTML="";
}else{
for(var i=0;i<this.queue.length;i++){
this.queue[i].parentNode.removeChild(this.queue[i]);
}
}

this.next();

},

pauseTimeStamp:null,
pause:function(){
document.getElementById('play_pause_button').src = '/images/template/slide-play.gif';
document.getElementById('play_pause_link').href = 'javascript:slideshow.play();';
this.pauseTimeStamp=new Date().getTime();
var queue=Effect.Queues.get(this.defaultQueueName);


if(queue.interval)clearInterval(queue.interval);
Element.setOpacity(this.currentNode,1.0);
},

stop:function(){
this.stopped=true;
this.pause();
},

nextclick:function(){
this.stopped=true;
this.pause();
this.next();
},

prevclick:function(){
this.stopped=true;
this.pause();
this.prev();
},

changeslide:function(num){
//alert(num + ' ' + this.index);
this.stopped=true;
this.pause();
	if(num != this.index){
		if(num > this.index){
			move = num - this.index;
			for(x=0;x<move;x++){
				this.next();
			}
		}else if(num < this.index){
			move = this.index - num;
			for(x=0;x<move;x++){
				this.prev();
			}
		}
	}
},

play:function(){
this.stopped=false;
document.getElementById('play_pause_button').src = '/images/template/slide-pause.gif';
document.getElementById('play_pause_link').href = 'javascript:slideshow.stop();';
this.resume();
},

resume:function(){

if(this.stopped){
return;
}

var queue=Effect.Queues.get(this.defaultQueueName);


var delay=new Date().getTime()-this.pauseTimeStamp;
queue.each(function(e){
e.startOn+=delay;
e.finishOn+=delay;
});
queue.interval=setInterval(queue.loop.bind(queue),40);
},

remove:function(element){
Element.setStyle(element,{zIndex:'0'});
Element.remove(element);
},

next:function(){
if(this.index>this.queue.length-1){
document.getElementById('slide' + (this.index)).className = 'num';
this.index=0;
}

if(this.index != 0){
	document.getElementById('slide' + (this.index)).className = 'num';
}

document.getElementById('slide' + (this.index + 1)).className = 'num selected';
						
if(this.currentNode){

Element.setStyle(this.currentNode,{zIndex:'2'});

new Effect.Opacity(this.currentNode,{duration:this.fadeOutTime,
transition:Effect.Transitions.linear,
from:1.0,to:0.0,
afterFinish:this.remove.bind(this,this.currentNode)
});
}

this.currentNode=this.createNode();

new Effect.Wait(this.currentNode,{duration:this.delay,
queue:{position:'end',scope:this.defaultQueueName},
afterFinish:this.next.bind(this)
});

this.index++;
},

prev:function(){
if(this.index==1){
document.getElementById('slide' + (this.index)).className = 'num';
this.index=this.queue.length+1;
}

if(this.index != 1){
	document.getElementById('slide' + (this.index)).className = 'num';
}

document.getElementById('slide' + (this.index-1)).className = 'num selected';

if(this.currentNode){

Element.setStyle(this.currentNode,{zIndex:'2'});

new Effect.Opacity(this.currentNode,{duration:this.fadeOutTime,
transition:Effect.Transitions.linear,
from:1.0,to:0.0,
afterFinish:this.remove.bind(this,this.currentNode)
});
}

this.currentNode=this.createNode2();

new Effect.Wait(this.currentNode,{duration:this.delay,
queue:{position:'end',scope:this.defaultQueueName},
afterFinish:this.prev.bind(this)
});

this.index--;
},

createNode:function(){
var node=this.queue[this.index];

if(typeof(node)=='string'){
node=document.createElement('div');
node.innerHTML=this.queue[this.index];
}

Element.setOpacity(node,1.0);
Element.setStyle(node,{position:'absolute'});
Element.addClassName(node,'ACCrossfadeQueueElement');

node.mouseover=this.pause.bind(this);
node.mouseout=this.resume.bind(this);

this.container.appendChild(node);

return node;
},

createNode2:function(){
if(this.index==0){
	var node=this.queue[this.queue.length];
}else{
	var node=this.queue[this.index-2];
}
if(typeof(node)=='string'){
node=document.createElement('div');
if(this.index==0){
	node.innerHTML=this.queue[this.queue.length];
}else{
	node.innerHTML=this.queue[this.index-2];
}
}

Element.setOpacity(node,1.0);
Element.setStyle(node,{position:'absolute'});
Element.addClassName(node,'ACCrossfadeQueueElement');

node.mouseover=this.pause.bind(this);
node.mouseout=this.resume.bind(this);

this.container.appendChild(node);

return node;
}
}



function InitCrossFade(){
if(arguments.length>0){
var nodes=$A(InitCrossFade.arguments);
var objectReference=nodes.shift();
var holdTime=(typeof(nodes[nodes.length-1])=="number")?nodes.pop():Math.floor(Math.random()*5)+3;

new AC.CrossfadeQueue(nodes,objectReference,holdTime);
}
}
