//////////////////////////////////////
//
// slideshow modified by Guy Grafius 
// copyright photoGRAFIUS studios
//
//////////////////////////////////////
timeoutID=0;
goStop="go";
prevMe="no";
mySlideshowStateON='<a href=\"javascript:slideShowOff();\" class=\"slideshowNav\">slideshow stop</a>';
mySlideshowStateOFF='<a href=\"javascript:slideShowOn();\" class=\"slideshowNav\">slideshow start</a>';

myNextSlide='<a href="javascript:nextSlide();" class=\"slideshowNav\">&gt;</a>';
myPrevSlide='<a href="javascript:prevSlide();" class=\"slideshowNav\">&lt;</a>';

mySlideshowState=mySlideshowStateON;

function nextSlide(){
	window.clearTimeout(timeoutID);
	myThis.tick();
}

function prevSlide(){
	prevMe="yes";
	window.clearTimeout(timeoutID);
	myThis.tick();
}

function slideShowOff(){
	goStop="stop";
	window.clearTimeout(timeoutID);
	mySlideshowState=mySlideshowStateOFF;
	document.getElementById('slideShow').innerHTML = mySlideshowState+"&nbsp;&nbsp; " + myPrevSlide + " &bull; " + slideNum + "&nbsp;of&nbsp;" + slideCount + " &bull; "+ myNextSlide;

}

function slideShowOn(){
	goStop="go"; 
	window.clearTimeout(timeoutID);
	timeoutID=window.setTimeout(ttb, tob);
	mySlideshowState=mySlideshowStateON;
	document.getElementById('slideShow').innerHTML = mySlideshowState+"&nbsp;&nbsp; " + myPrevSlide + " &bull; " + slideNum + "&nbsp;of&nbsp;" + slideCount + " &bull; " + myNextSlide;
}

var AwardsShow = Class.create();
AwardsShow.prototype = {
initialize: function(element, options) {
myThis=this;
this.element = $(element);
this.options = Object.extend({className: 'newsquote', duration: 15}, options);
this.quotes = document.getElementsByClassName(this.options.className, this.element);
document.getElementById('slideShow').innerHTML = mySlideshowState+"&nbsp;&nbsp; " + myPrevSlide + " &bull; 1&nbsp;of&nbsp;" + this.quotes.length + " &bull; " + myNextSlide;
this.prepareQuotes();
this.registerCallback();
},
prepareQuotes: function() {
this.currentQuote = this.quotes.first();
this.element.style.position = 'relative';
this.element.style.height = this.quotes.max(function(quote) {
var visible = Element.visible(quote), height;
Element.setStyle(quote, {position: 'absolute', width: '100%', left: '0px'});
if (!visible) Element.show(quote);
height = Element.getHeight(quote);
if (!visible) Element.hide(quote);
return height;
}).toString() + 'px';
},


nextQuote: function() {

slideNum=(((this.quotes.indexOf(this.currentQuote) + 1) % this.quotes.length)+1);
slideCount=this.quotes.length;

document.getElementById('slideShow').innerHTML = mySlideshowState+"&nbsp;&nbsp; " + myPrevSlide + " &bull; " + (((this.quotes.indexOf(this.currentQuote) + 1) % this.quotes.length)+1) + "&nbsp;of&nbsp;" + this.quotes.length + " &bull; " + myNextSlide;

return this.quotes[(this.quotes.indexOf(this.currentQuote) + 1) % this.quotes.length];
},
prevQuote: function() {

slideNum=(((this.quotes.indexOf(this.currentQuote) - 1) % this.quotes.length)+1);

slideCount=this.quotes.length;

if(slideNum < 1){
	slideNum=slideCount;
}

document.getElementById('slideShow').innerHTML = mySlideshowState+"&nbsp;&nbsp; " + myPrevSlide + " &bull; " + slideNum + "&nbsp;of&nbsp;" + slideCount + " &bull; " + myNextSlide;


return this.quotes[slideNum - 1];

},
registerCallback: function() {

ttb=this.tick.bind(this);
tob=this.options.duration * 1000;
window.clearTimeout(timeoutID);
timeoutID=window.setTimeout(ttb, tob);
},
tick: function() {
window.clearTimeout(timeoutID);
	if(prevMe=="yes"){
		prevMe="no";
		var currentQuote = this.currentQuote, nextQuote = this.prevQuote();
	}else{
		var currentQuote = this.currentQuote, nextQuote = this.nextQuote();
	}
new Effect.Parallel([
new Effect.Fade(currentQuote, {sync: true}),
new Effect.Appear(nextQuote, {sync: true})
], {
duration: 1,
afterFinish: (function(effect) {
this.currentQuote = nextQuote;

if(goStop!="stop"){
	this.registerCallback();
}

}).bind(this)
})
}
}
Event.observe(window, 'load', function() {
new AwardsShow('news-show');
})

