
/*
 * -----------------------------------------------------
 * + Javascript für Slidebox
 * + Webdesign: http://www.cre8ives.de
 * + Cre8ives.de, Lutterbach - Wollgarten GbR
 * -----------------------------------------------------
 */

/*
 * obj_name:    Id vom Div, dass zu schieben ist
 * swait:       Sekunden zwischen den Durchläufen (5)
 * speed:       Millisekunden pro Pixel während des Durchlaufens (70)
 * restart_top: Falls komplett durchlaufen, neue Restarthöhe in Pixel (200)
 *
 * direction:   0=no_slide, 1=up, 2=down 
 */

/*
 * init (onload)
 */ 

direction = 0;

function init_slidebox(obj_name,swait,speed,restart_top) {
	
	// start looping the slide funktion
	if(document.getElementById(obj_name))
	{
		obj = document.getElementById(obj_name);
		obj.style.top = "0px";
		obj.style.visibility = "visible";
		setTimeout("slide('"+obj_name+"',"+swait+","+speed+","+restart_top+")",500);
	}
}

 /*
  * slide every pixel
  */ 

function slide(obj_name,swait,speed,restart_top){
	
  obj = document.getElementById(obj_name);

  if(direction == 0)
  {
  	// no slide, only loop the function
  	setTimeout("slide('"+obj_name+"',"+swait+","+speed+","+restart_top+")",500);
  }
  		
	if(direction == 1)
	{
		// direction is up
		if(parseInt(obj.style.top) == 1) 
		{ 
			// wait while moving up on position 1px
			obj.style.top = parseInt(obj.style.top) -1  + "px";
			setTimeout("slide('"+obj_name+"',"+swait+","+speed+","+restart_top+")",swait*1000);
		}
		else 
		{ 
			if(parseInt(obj.style.top) > -obj.offsetHeight)
		  {
				// move up
				obj.style.top = parseInt(obj.style.top) -2  + "px";
			} 
			else 
			{
				// reset to restart_top
				obj.style.top = restart_top+"px";
			}

	    setTimeout("slide('"+obj_name+"',"+swait+","+speed+","+restart_top+")",speed);
	  }
	}
	
  if(direction == 2)
  {
  	// direction is 'down'
			if(parseInt(obj.style.top) < restart_top)
		  {
				// move up
				obj.style.top = parseInt(obj.style.top) +2  +"px";
			} 
			else 
			{
				// reset to restart_top
				obj.style.top = -(obj.offsetHeight + 1) +"px";
			}

	    setTimeout("slide('"+obj_name+"',"+swait+","+speed+","+restart_top+")",speed);
  }
  
}






