var browser = navigator.userAgent;

var box_slide_browser_add = (browser.indexOf('Gecko') > 0 ? 30 : 0);
var box_speed = 2;
var box_position = 0;
var box_scroller_add = 0;
var box_slidepos = 0;

var box_margines = 245;
var box_all = 350; // Wysokość widocznej części tekstu.
var box_scroll_all = 51; // Wysokość scrollera.
var box_top = -18; // Ujemna wartość wysokości strzałki do góry.
var box_up_down_height = 20; // Wysokość obu strzałek góra / dół.
var box_bottom = box_scroll_all - box_top;
var box_height = box_all;


var box_u = false;
var box_d = false;
var box_grafika = 0;

var box_slide_size = 18;
var box_slide_lowest = box_scroll_all - (box_slide_size * 2) - box_up_down_height;

var divScrollId;



function box_up() {
	if(box_press) box_press = false;
	box_position = box_position + box_speed;
	if (box_position >= 0) {
		box_position = 0;
		box_u = false;
	}
	document.getElementById(divScrollId).style.top=box_position + "px";
	if (box_u == true) {
		setTimeout('box_up()', 10);
		box_slidepos = box_slidepos - box_scroller_add;
		if (box_slidepos < box_top)
			box_slidepos = box_top;
		if (box_slidepos >= box_scroll_all - box_slide_size)
			box_slidepos = box_scroll_all - box_slide_size;
		if(box_u) document.getElementById("scroller").style.top=Math.round(box_slidepos) + 'px';
		if(box_position == 0)
			document.getElementById("scroller").style.top=Math.round(box_top) + 'px';
	}
}

function box_down() {
	if(box_press) box_press = false;
	if (document.getElementById(divScrollId).scrollHeight < box_all)
		return false;
	box_position = box_position - box_speed;
	if (box_position < document.getElementById(divScrollId).scrollHeight * -1 + box_all) {
		box_position = document.getElementById(divScrollId).scrollHeight * -1 + box_all;
		box_d = false;
	}
	document.getElementById(divScrollId).style.top=box_position + "px";
	if(box_d == true) {
		setTimeout('box_down()', 10);
		box_slidepos = box_slidepos + box_scroller_add;
		if (box_slidepos < box_top)
			box_slidepos = box_top;
		if (box_slidepos >= box_slide_lowest)
			box_slidepos = box_slide_lowest;
		if(box_d) document.getElementById("scroller").style.top=Math.round(box_slidepos) + 'px';
		if(box_position == document.getElementById(divScrollId).scrollHeight * -1 + box_all)
			document.getElementById("scroller").style.top=Math.round(box_bottom) + 'px';
	}
}

function box_start_slider() {
	var a = arguments;
	divScrollId = a[0];
	var tresc = document.getElementById(divScrollId);
	if((tresc == null)|| (tresc.scrollHeight < box_all)) { //  || (tresc.scrollHeight < box_all)
		document.getElementById("scroll").style.visibility = "hidden";
		document.getElementById("scroll").style.width = "0px";
		document.getElementById("scroll").style.height = "0px";
		document.getElementById("scroller").style.visibility = "hidden";
		document.getElementById("scroller").style.width = "0px";
		document.getElementById("scroller").style.height = "0px";
		document.getElementById("scrollup").style.visibility = "hidden";
		document.getElementById("scrollup").style.width = "0px";
		document.getElementById("scrollup").style.height = "0px";
		document.getElementById("scrolldown").style.visibility = "hidden";
		document.getElementById("scrolldown").style.width = "0px";
		document.getElementById("scrolldown").style.height = "0px";
		return false;
	} else {
		tresc.style.top = 0;
		box_position = 0;
		var news = tresc.scrollHeight;
		box_scroller_add = ((box_scroll_all - box_up_down_height - box_slide_size) / ((news - box_all) / box_speed));
		box_slidepos = box_top;
		document.getElementById("scroller").style.top=Math.round(box_slidepos) + 'px';
	}
}

var box_press;

function box_move(e) {
	if (!e)
		var e = window.event;
	if (box_press == true) {
		box_slidepos = e.clientY - box_margines + box_slide_browser_add;
		if (box_slidepos < box_top)
			box_slidepos = box_top;
		else if (box_slidepos > box_slide_lowest)
			box_slidepos = box_slide_lowest;
		box_position = -Math.round(((box_slidepos - box_top) / box_scroller_add) * box_speed);
		if (box_position >= 0)
			box_position = 0;
		else if (box_position < document.getElementById(divScrollId).scrollHeight * -1 + box_all)
			box_position = document.getElementById(divScrollId).scrollHeight * -1 + box_all;
		document.getElementById(divScrollId).style.top=box_position + "px";
		document.getElementById("scroller").style.top=box_slidepos + "px";
	}
}

function box_press_down() {
	box_press = true;
}

function box_press_up() {
	box_press = false;
}

