
var tempo=40;
var stopSlider=true;
var cranSliderV=5;
var cranSliderH=5;

var contentL= new Array();

function REinitSlider() {

}

function initSliderLayer(i, layer) {

    if (!document.getElementById(layer)) return;
    contentD = document.getElementById(layer).style
    windowHeight=clipValues(contentD,"b");
    contentHeight=document.getElementById(layer).offsetHeight;
    windowWidth=clipValues(contentD,"r");
    contentWidth=document.getElementById(layer).offsetWidth;

  contentD.xpos = parseInt(contentD.left)
  contentD.ypos = parseInt(contentD.top)
  contentD.xtop = parseInt(contentD.left)
  contentD.ytop = parseInt(contentD.top)
  contentD.offsetHeight=contentHeight - windowHeight
  contentD.offsetWidth=contentWidth - windowWidth
  contentL[i]=contentD;
  stopSlider=false;
}

function initSlider() {
  initSliderLayer(1, "contentDiv");
}

function moveDownLayer(i) {
  if (stopSlider) return;
  if (!contentL[i]) return;
  contentD=contentL[i]
  if ((contentD.ypos-contentD.ytop) > -contentD.offsetHeight) {
    moveBy(contentD,0,-cranSliderV)
    clipTo(contentD,clipValues(contentD,"t")+cranSliderV,clipValues(contentD,"r"),clipValues(contentD,"b")+cranSliderV,clipValues(contentD,"l"))
    setTimeout("moveDownLayer("+i+")", tempo)
  }
}

function moveDown() {
  moveDownLayer(1);
}

function moveUpLayer(i) {
  if (stopSlider) return;
  if (!contentL[i]) return;
  contentD=contentL[i]
  if ((contentD.ypos-contentD.ytop) < 0) {
    moveBy(contentD,0,cranSliderV)
    clipTo(contentD,clipValues(contentD,"t")-cranSliderV,clipValues(contentD,"r"),clipValues(contentD,"b")-cranSliderV,clipValues(contentD,"l"))
    setTimeout("moveUpLayer("+i+")", tempo)
  }
}

function moveUp() {
  moveUpLayer(1);
}

function moveLeftLayer(i) {
  if (stopSlider) return;
  if (!contentL[i]) return;
  contentD=contentL[i]
  if ((contentD.xpos-contentD.xtop) > -contentD.offsetWidth) {
    moveBy(contentD,-cranSliderH,0)
    clipTo(contentD,clipValues(contentD,"t"),clipValues(contentD,"r")+cranSliderH,clipValues(contentD,"b"),clipValues(contentD,"l")+cranSliderH)
    setTimeout("moveLeftLayer("+i+")", tempo)
  }
}

function moveRightLayer(i) {
  if (stopSlider) return;
  if (!contentL[i]) return;
  contentD=contentL[i]
  if ((contentD.xpos-contentD.xtop) < 0) {
    moveBy(contentD,cranSliderH,0)
    clipTo(contentD,clipValues(contentD,"t"),clipValues(contentD,"r")-cranSliderH,clipValues(contentD,"b"),clipValues(contentD,"l")-cranSliderH)
    setTimeout("moveRightLayer("+i+")", tempo)
  }
}

function clipValues(obj,which) {
		var clipv = obj.clip.replace(new RegExp("[a-zA-Z,()]", "g"), '').split(' ');
		if (which=="t") return Number(clipv[0])
		if (which=="r") return Number(clipv[1])
		if (which=="b") return Number(clipv[2])
		if (which=="l") return Number(clipv[3])
}

function clipTo(obj,t,r,b,l) {
	obj.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}

function moveBy(obj,x,y) {
	moveTo(obj, obj.xpos+x, obj.ypos+y)
}

function moveTo(obj,x,y) {
    obj.xpos = x
    obj.ypos = y
    obj.left = obj.xpos
    obj.top  = obj.ypos
}