var LogoScrollerOO = new Class ({
	Implements: [Options, Events],
	options: {
		logos_list : 'network_logos_scroll',
		singleLogoWidth : 150
	},
	initialize : function (options) {
		this.setOptions(options);
		this.logoList = $(this.options.logos_list).getFirst('ul');

		logo_count = $(this.options.logos_list).getFirst('ul').getChildren('li').length;
		total_width = logo_count*-this.options.singleLogoWidth;

		this.slideFx = new Fx.Tween(this.logoList, {property:'margin-left'});

		this.periodicTimer = this.movePeriodic.periodical(2500, this);


		$('scroll_right').addEvent('click', this.moveRight.bind(this));
		$('scroll_left').addEvent('click', this.moveLeft.bind(this));
	},
	moveRight : function () {
		this.moveBar('right');
	},
	moveLeft : function () {
		this.moveBar('left');
	},
	movePeriodic : function () {
		this.moveBar('auto');
	},
	moveBar : function (direction){

		margin_left = parseInt(this.logoList.getStyle('margin-left'))
		if(direction == "left"){
			new_margin = parseInt(margin_left+750);
		}else if(direction == "right"){
			new_margin = parseInt(margin_left-750);
		}else{
			new_margin = parseInt(margin_left-150);
		}
		total_width = parseInt(total_width);
		scroll_width = new_margin

		if(direction=='auto'){

			if(total_width<scroll_width && scroll_width<0){
				this.slideFx.start(new_margin)
			}else{
				this.slideFx.start(0)
			}
		}else{
			$clear(this.periodicTimer);
			if(total_width<scroll_width && scroll_width<0){
				this.slideFx.start(new_margin)
			}else if(total_width>=scroll_width){
				this.slideFx.start(total_width+750);
			}else{
				this.slideFx.start(0)
			}
			this.periodicTimer = this.movePeriodic.periodical(2500, this);
		}
	}
})
