var scroll_target = "content";

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}
addEvent(window,'load', function() {
	if (document.getElementById('up')) return;
	var content = document.getElementById(scroll_target);
	var maxHeight = parseInt(getStyle(content,"height"));
	var bottom = content.offsetHeight + content.offsetTop;
	content.style.overflow= 'visible';
	content.style.height= 'auto';
	if (content.offsetHeight > maxHeight) {
		content.move = {
			HTMLobj:null,
			originalHeight:null,
			maxHeight:null,
			scrolled:0,
			interval:null,
			init: function(target,maxHeight) {
				this.HTMLobj = target;
				this.originalHeight = maxHeight;
				this.maxHeight = target.offsetHeight - this.originalHeight;
				this.originalTop = parseInt(getStyle(content,'top')) ? parseInt(getStyle(content,'top')) : (parseInt(content.offsetTop) ? parseInt(content.offsetTop) : 0);
				target.style.overflow = 'hidden';
				this.to(0);
			},
			to: function(position) {
				if (position  > this.maxHeight) position = this.maxHeight;
				else if (position < 0) position = 0;
				this.HTMLobj.style.height = (this.originalHeight + position) + "px";
				this.HTMLobj.style.top = (this.originalTop - position) + "px";
				this.HTMLobj.style.clip = 'rect('+ position +'px, ' + this.HTMLobj.offsetWidth + 'px, '+ (position + this.originalHeight) +'px, 0)';
				this.scrolled = position;
			},
			by: function(speed) {
				this.to(this.scrolled + speed);
			},
			
			start:function(speed) {
				if (this.interval != null) this.stop();
				this.interval = setInterval("document.getElementById('" + this.HTMLobj.id + "').move.by(" + speed + ");",10);
			},
			
			stop: function() {
				clearInterval(this.interval);
				this.interval = null;
			}
		}

		var div = document.createElement('div');
		div.id = 'private_scroller';
		div.style.position = 'absolute';
		div.style.top = bottom - 31 + 'px';
		div.style.left = '20px';
		
		var up = document.createElement('img');
		up.src = "http://www.laurenanderson.net/assets/images/common/up.gif";
		up.id = up.value = up.name = 'up';
		up.onmousedown = function() {document.getElementById(scroll_target).move.start(-10);};
		div.appendChild(up);
		
		var down = document.createElement('img');
		down.src = "http://www.laurenanderson.net/assets/images/common/down.gif";
		down.id = down.value = down.name = 'down';
		down.onmousedown = function() {document.getElementById(scroll_target).move.start(10);};
		div.appendChild(down);
		
		var stop = function() {document.getElementById(scroll_target).move.stop();};
		addEvent(down,'mouseup',stop);
		addEvent(up,'mouseup',stop);
		addEvent(down,'mouseout',stop);
		addEvent(up,'mouseout',stop);
		addEvent(down,'onkeyup',stop);
		addEvent(up,'onkeyup',stop);
		
		up.onkeydown = down.onkeydown = function(e) {
			if (!e) e = window.event;
			if (e.keyCode == 13 || e.keyCode == 32) this.onmousedown();
		}

		document.getElementById('wrapper').appendChild(div);
		
		content.move.init(content,maxHeight - 40);
	} else {
		content.style.height = maxHeight + 'px';
	}
	if (window.loader) loader();
});


function getStyle(x,CSSstyleProp,IEstyleProp)
{
	if (!IEstyleProp) IEstyleProp = CSSstyleProp;
	if (x.currentStyle)
		var y = x.currentStyle[IEstyleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(CSSstyleProp);
	if (y == undefined) return '';
	return y;
}