var categoryBoxes = new Array();


function removeAll() {
	for (var i = 0; i < categoryBoxes.length; i++) {
		eval("YAHOO.util.Event.purgeElement('" + categoryBoxes[i].concat('_left') + "');");
		eval("YAHOO.util.Event.purgeElement('" + categoryBoxes[i].concat('_right') + "');");
	}
}

function animLeft(id) {
	var el = document.getElementById(id);
	var elCoords = YAHOO.util.Dom.getRegion(el);
	removeAll();
	var anim = new YAHOO.util.Motion(el,
		{points: {to: [elCoords.left+495, elCoords.top]}},
		0.3,
		YAHOO.util.Easing.easeOut);
	anim.onComplete.subscribe(enableArrows);
	anim.animate();
}

function animRight(id) {
	var el = document.getElementById(id);
	var elCoords = YAHOO.util.Dom.getRegion(el);
	removeAll();
	var anim = new YAHOO.util.Motion(el,
		{points: {to: [elCoords.left-495, elCoords.top]}},
		0.3,
		YAHOO.util.Easing.easeOut);
	anim.onComplete.subscribe(enableArrows);
	anim.animate();
}



function enableArrows() {
	for (var i = 0; i < categoryBoxes.length; i++) {
		var catBox = document.getElementById(categoryBoxes[i]);
		var arrowLeft = document.getElementById(categoryBoxes[i].concat('_left'));
		var arrowRight = document.getElementById(categoryBoxes[i].concat('_right'));
		var parent = catBox.parentNode
		var catBoxCoords = YAHOO.util.Dom.getRegion(catBox);
		var parentCoords = YAHOO.util.Dom.getRegion(parent);
		
		if (catBoxCoords.left < parentCoords.left) {
			arrowLeft.src = arrowLeft.src.substr(0,arrowLeft.src.length-5).concat('1.gif')
			arrowLeft.className = 'on';
			eval("YAHOO.util.Event.on('" + arrowLeft.id + "', 'click', function() {animLeft('" + catBox.id + "');});");
		} else {
			arrowLeft.className = '';
			arrowLeft.src = arrowLeft.src.substr(0,arrowLeft.src.length-5).concat('0.gif')
		}
		if (catBoxCoords.right > parentCoords.right) {
			arrowRight.src = arrowRight.src.substr(0,arrowRight.src.length-5).concat('1.gif')
			arrowRight.className = 'on';
			eval("YAHOO.util.Event.on('" + arrowRight.id + "', 'click', function() {animRight('" + catBox.id + "');});");
		} else {
			arrowRight.className = '';
			arrowRight.src = arrowRight.src.substr(0,arrowRight.src.length-5).concat('0.gif')
		}
	}
}

YAHOO.util.Event.onDOMReady(enableArrows);
