var scrollarea_height;
var down_mouse_over;
var up_mouse_over;

function init_scrolling() {
	var my_scrollarea;
	
	my_scrollarea = document.getElementById("scrollarea");
	my_scrollarea.style.left = 5 + "px";
	my_scrollarea.style.top = 0 + "px";
	my_scrollarea.style.index = 1;
	scrollarea_height = my_scrollarea.offsetHeight;
	
	if (scrollarea_height > scrollarea_max) {
		document.getElementById('scroll_up').style.display = 'inline';
		document.getElementById('scroll_down').style.display = 'inline';
	}
}

function do_up() {
	var my_scrollarea;
	var x;
	
	if(up_mouse_over == true) {
		my_scrollarea = document.getElementById("scrollarea");
		x = parseInt(my_scrollarea.style.top);
		if(x < 0) {
			my_scrollarea.style.top = (x + 5) + "px";
		}
		setTimeout("do_up();", 5);
	}
}

function start_up() {
	up_mouse_over = true;
	do_up();
}

function stop_up() {
	up_mouse_over = false;
}

function do_down() {
	var my_scrollarea;
	var x;

	if(down_mouse_over == true) {
		my_scrollarea = document.getElementById("scrollarea");
		x = parseInt(my_scrollarea.style.top);
		
		if(-x < scrollarea_height - scrollarea_max)
		{
			my_scrollarea.style.top = (x - 5) + "px";
		}

		setTimeout("do_down();", 5);
	}
}

function start_down() {
	down_mouse_over = true;
	do_down();
}

function stop_down() {
	down_mouse_over = false;
}

function external_init() {
	var a;
	var f;
	var node;

	if(!document.getElementsByTagName) return;

	a = document.getElementsByTagName("a");

	for(i = 0; i < a.length; i++) {
		if(!a[i].getAttribute("href") ||
		   a[i].getAttribute("rel") != "external") continue;

		a[i].target = "_blank";
	}

	f = document.getElementsByTagName("form");

	for(i = 0; i < f.length; i++) {
		if(f[i].className != "external") continue;

		f[i].target = "_blank";
	}
}

function init_all() {
	external_init();

	if (scrollarea_max > 0) {
		init_scrolling();
	}
}

var openpopupWindow = null;
function openpopup (mypage,myname,w,h,pos,infocus,scrolling){
	if (openpopupWindow) {
		openpopupWindow.close();
	}
	if(pos=='random'){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=='center'){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	} else if((pos!='center' && pos!='random') || pos==null){
		LeftPosition=100;TopPosition=100;
	}
	settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=' + scrolling + ',resizable=no,dependent=no';
	openpopupWindow=window.open('',myname,settings);
	if(infocus=='front'){
		openpopupWindow.focus();
		openpopupWindow.location=mypage;
	}
	return false;
}
