BannerSelector = Class.create();
BannerSelector.prototype = {
	Interval: null, intervalSec: 2, intervalIndex: 0, isInterval: false,
	base: {
		_root: null, id: null, element: null, link: null,
		attach: function(_id){
			this.element = $(_id);
			if( this.element ) this.id = _id;
			else this.element = null;
		},
		click: function(){
			document.location.href = this.link;
		},
		attachEvent: function(){
			Event.observe(this.element, 'click', this.click.bind(this));
		}
	},
	banners: {
		index: 0, _root: null,
		attachClassName: function(_button, _class, _url){
			if( _class && _url ){
				this[this.index] = {};
				this[this.index]['button'] = _button;
				this[this.index]['attachtype'] = 'class';
				this[this.index]['className'] = _class;
				this[this.index]['url'] = _url;
				Event.observe(_button, 'mouseover', this.change.bind(this, this.index));
				this.index++;

				if( this.index == 1 ) this.change(0);
			}
		},
		change: function(_no){
			if( typeof _no=='number' && _no<this.index && this._root.base.element ){
				this._root.base.element.className = this[_no].className;
				this._root.base.link = this[_no].url;
				for( var i=0, button=null, src=''; i<this.index; i++ ){
					button = $(this[i].button);
					if( button ){
						src = button.src.toString();
						if( i==_no ){
							button.src = src.indexOf('ro.gif')<0 ? src.replace('.gif', 'ro.gif') : src;
						} else {
							button.src = src.indexOf('ro.gif')<0 ? src : src.replace('ro.gif', '.gif');
						}
					}
				}
				this._root.intervalIndex = _no;
				return true;
			} return false;
		},
		click: function(_no){
			if( this.change(_no) ) document.location.href = this[_no].url;
		}
	},
	initialize: function(_baseId){
		this.base._root = this;
		this.banners._root = this;
		if(_baseId) this.base.attach(_baseId);
	},
	setInterval: function(){
		this.intervalIndex++;
		this.intervalIndex = this.banners.index > this.intervalIndex ? this.intervalIndex : 0;
		this.banners.change( this.intervalIndex );
	},
	stopInterval: function(_index){
		clearInterval( this.Interval );
		this.Interval = null;
		this.isInterval = false;
		/*Event.observe( this.banners[_index].button, 'mouseout', this.Loop.bind(this) );*/
	},
	Loop_Start: function(_sec){
		if( !this.isInterval ){
			if( typeof _sec=='number' ) this.intervalSec = _sec;
			this.Interval = setInterval( this.setInterval.bind(this), this.intervalSec * 1000 );
			this.isInterval = true;
		}
	},
	Loop: function(_sec){
		this.Loop_Start(_sec);
		for( var i=0; i<this.banners.index; i++ ){
			Event.observe( this.banners[i].button, 'mouseover', this.stopInterval.bind(this, i) );
		}
	}
};