// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)
// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, up_name, down_name)
{
	this.div_name = div_name;
	this.name = scrollname;
	this.scrollCursor = 0;
	this.speed = 5;
	this.timeoutID = 0;
	this.div_obj = null;
	this.up_name = up_name;
	this.dn_name = down_name;

	if (document.getElementById) {
		div_obj = document.getElementById(this.div_name);
		if (div_obj) {
			this.div_obj = div_obj;
			this.div_obj.style.overflow = 'hidden';
		}
		div_up_obj = document.getElementById(this.up_name);
		div_dn_obj = document.getElementById(this.dn_name);
		if (div_up_obj && div_dn_obj) {
			div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
			div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
			div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
			div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };                
		}
	}

	this.stopScroll = function() { clearTimeout(this.timeoutID); }
	this.scrollUp = function() {
		if (this.div_obj) {
			this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
			this.div_obj.scrollLeft = this.scrollCursor;
			this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
		}
	}
//this.scrollDown = function() {
//        if (this.div_obj) {
//            this.scrollCursor += this.speed;
//            this.div_obj.scrollLeft = this.scrollCursor;
//            this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
//        }
//    }
	this.scrollDown = function() {
		if (this.div_obj) {
			this.scrollCursor += this.speed;
			this.div_obj.scrollLeft = this.scrollCursor;
			if (this.div_obj.scrollLeft == this.scrollCursor) {
				this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
			} else {
				this.scrollCursor = this.div_obj.scrollLeft;
			}
		}
	}       
	this.resetScroll = function() {
		if (this.div_obj) {
			this.div_obj.scrollLeft = 0;
			this.scrollCursor = 0;
		}
	}
}
/* ===================================== */
var Site = {
	start: function(){
		if ($('kwick')) {
			Site.parseKwicks();
		}
	},
	parseKwicks: function(){
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 340]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 110) obj[j] = {'width': [w, 90]};
					}
				});
				fx.start(obj);
			});
			
		});
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				//obj[j] = {'width': [other.getStyle('width').toInt(), 120]};
				obj[j] = {'width': [other.getStyle('width').toInt(), 105]};
			});
			fx.start(obj);
		});
	}
};
window.addEvent('load', Site.start);
