SCROLL = function(obj, attr) {
  var interval;
  var timeout;
  var auto_interval;
  var auto_direction = -1;
  var offset = {'top': obj.offsetTop || 0 }
  
  if (interval) {
      clearInterval(interval);
  }
  if (timeout) {
      clearTimeout(timeout);
  }
  if (auto_interval) {
      clearInterval(auto_interval);
  }
  
  this.start = function(amount) {
    /* Default setzen */
	if (amount < 0) {
		auto_direction = -1;
	}
	if (amount > 0) {
		auto_direction = 1;
	}
    attr.top = attr.top || 0;
    attr.width = attr.width || "auto";
    attr.height = attr.height || "auto";
    interval = setInterval( function() { move(amount); }, attr.time );
  }

  this.stop = function() {
      clearInterval(interval);
      clearTimeout(timeout);
      clearInterval(auto_interval);
  }

  this.auto_start = function() {
    /* Default setzen */
	timeout = setTimeout(function() { auto_go(); }, attr.auto_timeout);
  }

  function auto_go() {
    /* Default setzen */
    attr.top = attr.top || 0;
    attr.width = attr.width || "auto";
    attr.height = attr.height || "auto";
	auto_interval =  setInterval( function() { move(attr.auto_amount * auto_direction); }, attr.auto_time);
  }

  function move(amount) {
    /* Werte aktualisieren */
    attr.top += amount;
    attr.height += amount;
    offset.top -= amount;

    /* Grenze ueberschritten? */
	if ( attr.top < 0 || attr.height > attr.clip_height) {
      attr.top -= amount;
      attr.height -= amount;
      offset.top += amount;
	  auto_direction = -1 * auto_direction;
      return;
    }
	
    /* Object bewegen */
    obj.style.clip = "rect(" + attr.top + "px " + attr.width + "px " + attr.height + "px 0)";
    obj.style.top = offset.top + "px";
  }
}

DIASHOW = function (obj,attr) {
	var div_top;
	var div_down;
	var div_count = attr.start_img;
	var fadeinopacity;
	var fadeoutopacity;
	
	this.start = function(start_delay) {
		div_interval =  setInterval( function() { setdiv(1); }, start_delay);
	}
		
	this.stop = function() {
    	if (typeof div_interval != 'undefined') {
			clearInterval(div_interval);		  
		}
	}
		
	this.next = function() {
		setdiv(1);
	}
	
	this.prev = function() {
		setdiv(-1);
	}
	
	
	this.swap = function(imgnumber) {
		if (imgnumber == div_count) {
			return;
		}
		div_top = attr.div_id + div_count;
		div_down = attr.div_id + imgnumber;
		div_count = imgnumber;

		fadeinopacity = 0;
		fadeoutopacity = 1;
		
		div_fade =  setInterval( function() { fadediv(); }, attr.fade_delay);
	}
	
	function setdiv(direction) {
		div_top = attr.div_id + div_count;
		div_count += 1;
		if (div_count > attr.divs) {
			div_count = 1;
		}
		div_down = attr.div_id + div_count;

		fadeinopacity = 0;
		fadeoutopacity = 1;
		
		div_fade =  setInterval( function() { fadediv(); }, attr.fade_delay);
	}
	
	
	function fadediv() {
		fadeinopacity += 0.1;
		fadeoutopacity -= 0.1;
		//alert(fadeopacity);
		if (fadeinopacity > 1) {
			if (typeof div_interval != 'undefined') {
				clearInterval(div_fade);		  
				document.getElementById(div_top).style.filter = "alpha(opacity=0)";
				document.getElementById(div_top).style.opacity = 0;
			}
			return;
		}
		document.getElementById(div_top).style.filter = "alpha(opacity=" + (fadeoutopacity * 100) + ")";
		document.getElementById(div_top).style.opacity = fadeoutopacity;
		document.getElementById(div_down).style.filter = "alpha(opacity=" + (fadeinopacity * 100) + ")";
		document.getElementById(div_down).style.opacity = fadeinopacity;

	}
}




