var home = {
	// the width of each box
	itemWidth : 0,
	seconds: 10,
	intervalID:0,
	numBoxes:0,
	boxActual:0,
	

	start : function() 
	{
		home.setup();
		
		//home.doScroll(0);					
	},
	
	behaviour : function() {
	},
	
	setup : function() 
	{
		// grab the elements of the widget
		var panel = $('scrollPanel');
		var items = $$('div.issues');
		// determine the width of the boxes
		home.itemWidth = items.first().getWidth();
		home.numBoxes = items.length;
		
		// loop through and make the scroll panel width match the total number of boxes
		var newWidth = 0;
		items.each(function(b){
			b.setStyle({ float : 'left' });
			newWidth += home.itemWidth;
		});
		
		panel.setStyle({ width: newWidth + 'px' });

		home.doScroll(0);				
		
	},
	// Function to run the slide effect and alter the links
	doScroll : function(iter) 
	{
		clearInterval(home.intervalID);
		
		home.boxActual = iter;
		
		home.intervalID = setInterval(function() { 
			if (home.boxActual >= (home.numBoxes-1)) {
				home.doScroll(0) 
			} else {
				home.doScroll(home.boxActual+1) 
			}
		},home.seconds*1000);
		
		
		var scrollPos = iter * home.itemWidth;
		
		new Effect.ScrollHorizontal('scrollBox', { 'to': scrollPos });
	
		$$('#buttons li a').each(function(el, i){
			if(i == iter){
				el.addClassName('on');
			} else {
				el.removeClassName('on');
			}
		});
	}



}

document.observe('dom:loaded', home.start);


Effect.ScrollHorizontal = Class.create();
Object.extend(Object.extend(Effect.ScrollHorizontal.prototype, Effect.Base.prototype), 
{
    initialize: function(element)
    {
        if(typeof element == "string"){
            this.element = $(element);
            if(!this.element){ throw(Effect._elementDoesNotExistError); }
        }
        var options = Object.extend({
            from: this.element.scrollLeft || 0,
            to:   this.element.offsetWidth
        }, arguments[1] || {});
        this.start(options);
    },
    update: function(position){
        this.element.scrollLeft = position;
    }
});