window.addEvent('domready', function() {
    setupHomeClients();
});

//a class fro the scrolling items
var HorizontalMarque = new Class({
	Implements: Options,
	options: {
		milli: 20,
		change: 1
	},
	p: '',
	c1: '',
	c2: '',
	pW: 0,
	cW: 0,
	timer: '',
	c1Prop: 0,
	c2Prop: 0,
	change: 1,
	initialize: function(c, options)
	{
		this.setOptions( options );
		this.p = c.getParent();
		this.c1 = c;
		this.c2 = c.clone();
		this.p.adopt(this.c2);
		this.pW = this.p.getSize().x;
		this.cW = this.c1.getSize().x;
		this.change = this.options.change;
		
		//check to make sure it is not 0
		if ( this.change == 0)
		{
			this.change = 1;
		}
		
		if ( this.change > 0 ) //scrolling towards right
		{
			this.c1Prop = 0;
			this.c2Prop = - this.cW;
		}
		else if ( this.change < 0 ) //scrolling towards left
		{
			this.c1Prop = 0;
			this.c2Prop = this.cW;
		}
		
		if ( Browser.ie6 )
		{
			if ( this.options.milli < 100 )
			{
				this.options.milli = 100;	
			}
		}
		
		this.p.setStyles({'position': 'relative', 'overflow': 'hidden'});
		this.c1.setStyles({'position': 'absolute', 'left': this.c1Prop});
		this.c2.setStyles({'position': 'absolute', 'left': this.c2Prop});
	},
	start: function()
	{
		this.timer = this.tick.periodical( this.options.milli, this );
	},
	tick: function()
	{
		this.c1Prop += this.change;
		this.c2Prop += this.change;
		
		if ( this.change > 0 ) //scrolling towards right
		{
			if ( this.c1Prop > this.pW )
			{
				this.c1Prop = this.c2Prop - this.cW;
			}
			if ( this.c2Prop > this.pW )
			{
				this.c2Prop = this.c1Prop - this.cW;
			}
		}
		else if ( this.change < 0 ) //scrolling towards left
		{
			if ( this.c1Prop < - this.cW )
			{
				this.c1Prop = this.c2Prop + this.cW;
			}
			if ( this.c2Prop <  - this.cW )
			{
				this.c2Prop = this.c1Prop + this.cW;
			}
		}
		
		this.c1.setStyle('left', this.c1Prop);
		this.c2.setStyle('left', this.c2Prop);
	},
	pause: function()
	{
		window.clearInterval( this.timer );
	}
});


function setupHomeClients()
{
	var ch, chi;
	ch = document.id('clients_holder');
	chi = ch.getElement('.clients_holder_inner');
	
	chW = ch.getSize().x;
	chiW = chi.getSize().x;
	chiClients = chi.getElements('.client').length;
	
	if ( chiW < chW)
	{
		//to short to scroll, just center
		chi.setStyle('left', (ch.getSize().x - chi.getSize().x) * .5);
	}
	else
	{
		var marque = new HorizontalMarque( chi );
		marque.start();
	}
	
	//color
	ch.getElements('.client').each( function(el, index)
	{
		/*if ( ! Browser.ie5 )
		{*/
			
			
			var col = el.getElement('.color');
			col.setStyles({'display': 'block', 'opacity': 0});
			col.set('morph', {duration: 500, transition: 'sine:out', link: 'cancel'});
			el.addEvents({
				'mouseenter': function() {
					col.morph({'opacity': 1});
					//gra.morph({'opacity': 0});
				},
				'mouseleave': function() {
					col.morph({'opacity': 0});
					//gra.morph({'opacity': 1});
				}
			});
			
			
		//}
	});
}
