var NewsSlideShow = new Class({
	options: {
//		container: $('containerNewsSlide'),
		slides: [],
		currentIndex: 0
	},
	initialize: function(options) {
		this.setOptions(options) ;
		this.slides = [] ;
		this.effects = [] ;
		this.texts = [] ;
		//this.options.container = options.container ;
		this.options.container.descr = new Element('a', {'id':'descr'}).inject(this.options.container) ;
		this.options.container.scrollDiv = new Element('div').addClass("scrollDiv").inject(this.options.container) ;
		this.options.container.scrollDiv.table = new Element('table', {border:0, cellPadding:0,cellSpacing:0}).inject(this.options.container.scrollDiv) ;
		this.options.container.scrollDiv.table.body = new Element('tBody').inject(this.options.container.scrollDiv.table) ;
		this.options.container.scrollDiv.table.body.tr = new Element('tr').inject(this.options.container.scrollDiv.table.body) ;
		
		this.options.container.descr.setOpacity(.8).setStyles({
				'top': this.options.container.descr.parentNode.getCoordinates().top + this.options.container.descr.parentNode.getCoordinates().height-this.options.container.descr.getCoordinates().height,
				'width': this.options.container.scrollDiv.getCoordinates().width 
		})
		this.fxScroll = new Fx.Scroll(this.options.container.scrollDiv, {duration: 1000, transition: Fx.Transitions.Sine.easeOut}) ;
	},
	addSlide: function(slide, text) {
		this.options.container.descr.setHTML("&nbsp;&nbsp;" + this.texts[0]) ;
		this.slides.include(slide) ;
		this.effects[this.slides.indexOf(slide)] = new Fx.Style(slide, 'opacity') ;
		this.texts[this.slides.indexOf(slide)] = text ;
	},
	cycleForward: function(event) {

		var currentIndex = this.options.currentIndex = this.options.currentIndex + 1 ;
		
		var img = this.options.container.getElements('img')[currentIndex] ;
		if (!img) {
			var currentIndex = this.options.currentIndex = 0 ;
			var img = this.options.container.getElements('img')[currentIndex] ;
		}
		this.fxScroll.scrollTo((img.parentNode.parentNode.cellIndex*695)-(5*currentIndex), 0) ;
		
		new Fx.Style(this.options.container.descr, 'opacity', {duration: 800}).start(0) ;
		this.fxScroll.start(0, 0).chain(function(){
			this.options.container.descr.setHTML("&nbsp;&nbsp;" + this.texts[currentIndex]).setProperty('href', img.parentNode.getProperty('href')) ;
			new Fx.Style(this.options.container.descr, 'opacity', {duration: 300}).start(.8) ;
		}.bind(this)) ;
	},
	addImg: function(url, text) {
		var td = new Element('td').inject(this.options.container.scrollDiv.table.body.tr) ;
		var lnk = new Element('a').setProperties({'href': url, 'title': text}).inject(td)
		var img = new Element('img', {
						src: url,
						border: 0,
						styles: {
							display1: 'none',
							left: (this.slides.length * 695)
						},
						events: {
							//click: this.cycleForward.bind(this) 
						}
		}).inject(lnk) ;
		this.addSlide(img, text) ;
	}
}) ;
NewsSlideShow.implement(new Options, new Events);


/*
<style type="text/css">
#containerNewsSlide { border: 1px solid #154978 ; height: 170px ;  }
#containerNewsSlide .scrollDiv { overflow: hidden ; width: 591px ; height: 170px ; }
#containerNewsSlide #descr { background-color: #154978 ; color: #FFFFFF ; font-size: 12px ; text-decoration: none ; position: absolute ; padding-top: 8px ; padding-bottom: 8px ; }
</style>
<div id="containerNewsSlide"></div>
*/

/*
window.addEvent('load', function() {
		var nss = new NewsSlideShow() ;
		for (var innc = 0 ; innc <= 4 ; innc++) {
			nss.addImg("images/slide-" + innc + ".jpg", "Thanks Valerio - this certainly put me in the right direction. " + innc + "" + innc + "" + innc + "" + innc) ;
		}
		nss.cycleForward.bind(nss).periodical(4000) ;
}) ;
*/
