var s, w, tbw, tmout, rv;

window.onload = function() {
	activate;
	createButtons();
	w = findWidth();
	if (document.getElementById('t') == null) {
		var mohammed = document.createElement('ul');
		mohammed.setAttribute('id','t');
		document.body.appendChild(mohammed);
		mohammed.style.display = 'none';
	}
	else { tbw = document.getElementById('t').offsetWidth; }
	if (w < tbw) { document.getElementById('tn').style.display = "block"; }
	if (rv < 7 && rv > 4) {
		document.getElementById('t').style.position="absolute";
		document.getElementById('tn').style.position="absolute";
		document.getElementById('h').style.position="absolute";
		document.getElementById('n').style.position="absolute";
		document.getElementById('t').style.setExpression("top", "0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'");
		document.getElementById('t').style.setExpression("left", "0+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px'");
		document.getElementById('tn').style.setExpression("top", "183+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'");
		document.getElementById('tn').style.setExpression("right", "13+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px'");
		document.getElementById('h').style.setExpression("top", "180+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'");
		document.getElementById('h').style.setExpression("left", "520+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px'");
		document.getElementById('n').style.setExpression("top", "(documentElement.clientHeight-this.clientHeight)+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'");
		document.getElementById('n').style.setExpression("left", "520+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px'");
		document.documentElement.style.overflowX = "hidden";
		if (document.body.getAttribute('className') == 'gal') {
			document.getElementById('h').style.setExpression("top", "0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'");
		}
	}
	document.getElementById('tnl').onmouseover = goRight;
	document.getElementById('tnl').onmouseout = stopRight;
	document.getElementById('tnr').onmouseover = goLeft;
	document.getElementById('tnr').onmouseout = stopLeft;
}

function createButtons() {
	var vbox = document.createElement('div');
	var btn1 = document.createElement('span');
	var btn2 = document.createElement('span');
	var btn1txt = document.createTextNode('←');
	var btn2txt = document.createTextNode('→');
	vbox.setAttribute('id','tn');
	btn1.setAttribute('id','tnl');
	btn2.setAttribute('id','tnr');
	vbox.appendChild(btn1);
	vbox.appendChild(btn2);
	vbox.insertBefore(btn1,btn2);
	btn1.appendChild(btn1txt);
	btn2.appendChild(btn2txt);
	document.body.appendChild(vbox);
	document.body.insertBefore(vbox,document.getElementById('n'));
}

window.onresize = function () {
	window.clearTimeout(tmout);
	tmout = window.setTimeout('resetThumbBar()', 50);
}

function resetThumbBar() {
	w = findWidth();
	var l = document.getElementById('t').offsetLeft;
	if (w < tbw) { 
		if (w > (tbw + l)) { l = document.getElementById('t').style.left = (w - tbw) + "px"; }
		document.getElementById('tn').style.display = "block"; 
	} else {
		document.getElementById('t').style.left = "0px";
		document.getElementById('tn').style.display = "none";
	}
}

function goLeft() {
	if (w < tbw) { s = setInterval('scrollLeft()', 50); }
}

function stopLeft() {
	clearInterval(s);
}

function goRight() { 
	if (w < tbw) { s = setInterval('scrollRight()', 50); }
}

function stopRight() {
	clearInterval(s);
}

function scrollLeft() { 
	var l = l = document.getElementById('t').offsetLeft;
	if ((w - tbw) < l) { 
		l = l - 3;
		document.getElementById('t').style.left = l + "px";
	}
}

function scrollRight() {
	var l = l = document.getElementById('t').offsetLeft;
	if (l < 0) { 
		l = l + 3;
		document.getElementById('t').style.left = l + "px";
	}
}

function findWidth() {
	var res, doit, sw;
	if (window.innerWidth) {
		res = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		res = document.documentElement.clientWidth;
	} else {
		res = document.body.clientWidth;
	}
	doit = checkVersion();
	if (rv < 6) {
		if (window.innerHeight < getDocHeight()) { sw = findScrollWidth(); }
		else { sw = 0; }
	}
	else { sw = findScrollWidth(); }
	if (doit) { res = res - sw; }
	return res;
}

function getDocHeight() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}

function findScrollWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100%';
	scr.style.height = '50px';
	scr.style.overflow = 'hidden';
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';
	scr.appendChild(inn);
	document.body.appendChild(scr);
	wNoScroll = inn.offsetWidth;
	scr.style.overflow = 'auto';
	wScroll = inn.offsetWidth;
	document.body.removeChild(document.body.lastChild);
	return (wNoScroll - wScroll);
}

function checkVersion() {
	rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); }
	}
	var doit = 0;
	if (rv < 7) { doit = 1; }
	return doit;
}

var activate = document.documentElement.setAttribute('id','switch');
