(function(){

var Event = YAHOO.util.Event;
var Dom = YAHOO.util.Dom;
var ani, box, h=0, inv, total, items;
var attributes = {	}
function init(el){
	var i, boxh, ft;

	box = Dom.get(el);
	boxh = box.offsetHeight;
	items = Dom.getElementsByClassName("item", "div", box);
	total = items.length;
	boxh = box.offsetHeight - items[total - 1].offsetHeight;
	if(boxh==0){
		boxh = box.offsetHeight;
	}
	Dom.setStyle("foot", "height", boxh);
	ani = new YAHOO.util.Scroll(el, attributes, 0.2);
	ani.onComplete.subscribe( aniComplete );

}


function aniComplete(g){
	h++;
	if(h == total - 1) {
		h = 0;
	}
}

function start(){
	init("box");
	resume();
	Event.on(box, "mouseover", pause);
	Event.on(box, "mouseout", resume);
}

function pause(){
	clearInterval(inv);
}

function resume(){
	inv = setInterval(change, 2000);
}

function change(){
	var attrib;
	if(h == 0) {
		box.scrollLeft = 0;
		box.scrollTop = 0;
	}
	attrib = {	scroll : { by : [0, items[h].scrollHeight] } 	};
	ani.attributes = attrib;
	ani.animate();
}

Event.onDOMReady(start);
})();
