/* Bild-Funktionen f�r Artikel */

function img_change(name,url,besch) {
  document.images[name].src= "../archiv/medium_"+url;
  document.images[name].alt = url;
  document.images[name].title = besch;
}

function zoom(name) {
  var datei = document.images[name].src;
  var rx = /^(.*\/(large_|medium_|small_)?)(.*)$/;
  if (rx.test(datei)) datei = RegExp.$3;
  var zoom_win = window.open("/templates/zoom.php?img="+datei,"Zoom","location=0,dependent=1,resizable=0,scrollbars=0,status=0,toolbar=0,height=500,width=700");
}

/* Mouseover-Effekte */

function button_mouseout() {
  if (this.img != document.mousedownimage) this.img.src = this.img.outsrc;
}

function button_mouseover() {
  if (this.img != document.mousedownimage) this.img.src = this.img.oversrc;
}

function button_mousedown() {
  if (document.mousedownimage) document.mousedownimage.src = document.mousedownimage.outsrc;
  this.img.src = this.img.downsrc;
  document.mousedownimage = this.img;
}

function button_preload() {
  document.preloaded_images = new Array();
  var res = "";
  var rx = /^(.*\/button-[^\/.]*)(\.[a-z0-9_-]+)$/i;
  for (var i = 0; document.images[i]; i++) {
    if (!rx.test(document.images[i].src)) continue;
    var name = RegExp.$1;
    var ext = RegExp.$2;
    if (!document.preloaded_images[name+"-over"]) {
      document.preloaded_images[name+"-over"] = new Image();
      document.preloaded_images[name+"-over"].src = name+"-over"+ext;
      document.preloaded_images[name+"-down"] = new Image();
      document.preloaded_images[name+"-down"].src = name+"-down"+ext;
    }
    if (!document.images[i].name) {
      document.images[i].img = document.images[i];
      document.images[i].onmouseover = button_mouseover;
      document.images[i].onmouseout = button_mouseout;
      document.images[i].onclick = button_mousedown;
    }
    document.images[i].outsrc = name+ext;
    document.images[i].oversrc = name+"-over"+ext;
    document.images[i].downsrc = name+"-down"+ext;
  }
  var linkrx = /^link-(.*)$/;
  for (var i = 0; document.anchors[i]; i++) {
    if (!linkrx.test(document.anchors[i].name)) continue;
    var imgname = "img-"+RegExp.$1;
    if (document.images[imgname]) {
      document.anchors[i].img = document.images[imgname];
      document.anchors[i].onmouseover = button_mouseover;
      document.anchors[i].onmouseout = button_mouseout;
      document.anchors[i].onclick = button_mousedown;
    }
  }
}
setTimeout("button_preload();",200);

var scroll_elt;
function scrollTimer() {
	var elt1 = scroll_elt.firstChild;
	var elt2 = elt1.nextSibling;
	var pos = elt1.offsetLeft;
	var width = elt1.offsetWidth;
	elt1.style.left = (pos-1)+"px";
	if (-pos > width) elt1.style.left = (pos-1+2*width)+"px";
	if (pos > 0) elt2.style.left = (pos-1-width)+"px";
	else elt2.style.left = (pos-1+width)+"px";
}
function scrollTimerV() {
	var elt1 = scroll_elt.firstChild;
	var elt2 = elt1.nextSibling;
	var pos = elt1.offsetTop;
	var height = elt1.offsetHeight;
	elt1.style.top = (pos-1)+"px";
	if (-pos > height) elt1.style.top = (pos-1+2*height)+"px";
	if (pos > 0) elt2.style.top = (pos-1-height)+"px";
	else elt2.style.top = (pos-1+height)+"px";
}
function scrollSetup(id,vertical) {
	scroll_elt = document.getElementById(id);
	var elt1 = scroll_elt.firstChild;
	var elt2 = elt1.nextSibling;
	var pos = elt1.offsetLeft;
	elt1.style.display = "block";
	elt2.style.display = "block";
	elt1.style.position = "absolute";
	elt2.style.position = "absolute";
	if (vertical) {
		var height = elt1.offsetHeight;
		elt1.style.top = (pos)+"px";
		elt2.style.top = (pos+height)+"px";
		setInterval(scrollTimerV,40);
	} else {
		var width = elt1.offsetWidth;
		elt1.style.left = (pos)+"px";
		elt2.style.left = (pos+width)+"px";
		setInterval(scrollTimer,40);
	}
}

