function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function slider()  {
	
	var listitems = document.getElementsByTagName('LI');
	var panel = document.getElementById('panel2');
	panel.style.width = (listitems.length * 69) + 19 +"px";
	
	var timer = null;
	document.getElementById('panel1').onmouseover = function() {
		trackthemouse();
		timer = setInterval("movePanel()",10);
	}
	document.getElementById('panel1').onmouseout = function() {
		donttrackthemouse();
		clearInterval(timer);
	}

	var links = document.getElementsByTagName('A');
	for (var i=0; i<links.length; i++) {
		if(links[i].getAttribute('id') == "moveLeft") {
			var ref = this;
			links[i].timerleft = null;
			links[i].onmouseover = function() {
				ref.timerleft = setInterval("moveLeft(2)",10);
			}
			links[i].onmouseout = function() {
				clearInterval(ref.timerleft);
			}
		}
		if(links[i].getAttribute('id') == "moveRight") {
			var ref = this;
			links[i].timerright = null;
			links[i].onmouseover = function() {
				ref.timerright = setInterval("moveRight(2)",10);
			}
			links[i].onmouseout = function() {
				clearInterval(ref.timerright);
			}
		}
	}
}
///////////////////////////////
function trackthemouse() {
	document.onmousemove = getMouseXY;
	var IE = document.all?true:false;
	if (!IE) document.captureEvents(Event.MOUSEMOVE);
	function getMouseXY(e) {
		if (IE) {
			tempX = event.clientX + document.body.scrollLeft
		} else {
			tempX = e.pageX
		} 
	if (self.innerWidth) {
		frameWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
	}
	else if (document.body) {
		frameWidth = document.body.clientWidth;
	}
	var windowMiddle = (frameWidth/2);
	if (tempX < 0) {
		tempX = 0;
	}
		mouseX = tempX - windowMiddle;
	}
}

function donttrackthemouse() {
	document.onmousemove = null;
}

function movePanel() {
	var panel = document.getElementById('panel2');
	var distance = mouseX/30;
	if (distance < 0)	{
		distance = -(distance);
	}
	if (mouseX < 0) {
		moveRight(distance);
	}
	// If the mouse moves to the right, the photo will scroll to the left:
	if (mouseX > 0) {
		moveLeft(distance);
	}
}

function moveLeft(distance) {
	var panel1 = document.getElementById('panel1');
	var panel2 = document.getElementById('panel2');
	var panel1width = parseInt(panel1.offsetWidth);
	var panel2width = parseInt(panel2.offsetWidth);
	var panel2X = panel2.offsetLeft;
	var limit = 0 - panel2width + panel1width;
	if(panel2X <= 0 && panel2X > limit) {
		panel2X  = panel2X - distance;
		panel2.style.left = panel2X +"px";
		if(panel2X > limit && panel2X <= limit + distance) {
			panel2X  = limit;
			panel2.style.left = panel2X +"px";
		}
	}
}

function moveRight(distance) {
	var panel2 = document.getElementById('panel2');
	var panel2X = panel2.offsetLeft;
	if(panel2X >= 0 - distance) {
		panel2X  = panel2X + distance;
		panel2.style.left = 0 +"px";
	}
	if(panel2X < 0 ) {
		panel2X  = panel2X + distance;
		panel2.style.left = panel2X +"px";
	}
}

addLoadEvent(slider);
