window.addEvent('domready',function(){

	var easyScroller = new Class({
		options: {
			container: 'carousel-container',
			linksSelector: 'a.links',
			relSelector: 'banner',
			activeClass: 'active',
			durationScroll: 900,
			runAuto: true,
			autoScroll: 7500,
			autoTimer: null,
			runTimer: null,
			nextItem : 0,
			curEl : null,
			curItem : 1,
			scrollList: null,
			scroll: null,
			linkEvent: null
		},
		unsetActive: function(){
		},
		doAuto: function(el){
			var opts = this.options;

			opts.linkEvent.fireEvent('unset',this);

			$('banner'+opts.curItem).removeClass('active');
			$('link'+opts.curItem).removeClass('active');

			if (opts.curItem >= opts.scrollList.length) {

				opts.nextItem = 1;
			} else {
				opts.nextItem = opts.curItem + 1;
			}

			opts.scroll.toElement($('banner'+opts.nextItem));

			$('banner'+opts.nextItem).addClass('active');
			$('link'+opts.nextItem).addClass('active');

			opts.curItem = opts.nextItem;
		},
		initialize: function(container,options){
			//this.container = $('bannerinner');
			this.setOptions(options);
			this.options.scrollList = new Array();
			var opts = this.options;

			var scroll = new Fx.Scroll(this.options.container, {
				wait: false,
				duration: this.options.durationScroll,
				//transition: Fx.Transitions.Elastic.easeOut
				transition: Fx.Transitions.Quad.easeInOut
			});
			this.options.scroll = scroll;

			$$(this.options.linksSelector).each(function(el,index){
				opts.scrollList.push(el.rel);
				if (index==0) {
					$(el.rel).addClass('active');
					el.addClass('active');
				}
				//console.log(index);
				opts.linkEvent = el.addEvents({
					'click': function(e){
						el.fireEvent('unset',this);
						clearTimeout(opts.autoTimer);

						var evnt = new Event(e).stop();

						var rExp = new RegExp("[0-9]+$",'i');
						var result = rExp.exec(this.id);
						opts.curItem = parseInt(result[0]);

						$(this.rel).addClass('active');
						this.addClass('active');
						scroll.toElement(this.rel);

						opts.runTimer();
					},
					'unset': function(e) {
						$$('a.links').each(function(el){
							el.removeClass('active');
						});

						$$('.banneritem').each(function(el){
							el.removeClass('active');
						});

					}
				});
			});

			if (opts.runAuto) {
				opts.runTimer = function() {
					opts.autoTimer = this.doAuto.periodical(opts.autoScroll,this);
				}.bind(this);
				opts.runTimer();
			}
		}
	});
	easyScroller.implement(new Options, new Events);
	var myscroll = new easyScroller('carousel-container',{container:'carousel-container',linksSelector: 'a.links',relSelector: 'banner',activeClass: 'active',durationScroll: 900,runAuto: true,autoScroll:7500});

});
