//////////////////////////////////////////////////////////////
//    Script Name: div scroller                            //
//    Version: 0.8                                        //
//    Author: Bracsek  (torokvmit(at)gmail(dot)com)      //
//    Author URI: http://bracsek.extra.hu               //
//    Last update 2008/09/23                           //
//    Copyright(c) 2008 DWEB(R)                       //
//    External lybrarys: --                          //
//    Included lybrarys: all except scroller()      //
/////////////////////////////////////////////////////

// require pictures for scroller
// images/scroll_bg.gif       16px x Ypx
// images/scroll_up_out.gif   16px x 18px
// images/scroll_up_ver.gif   16px x 18px
// images/scroll_down_out.gif 16px x 18px
// images/scroll_down_ver.gif 16px x 18px

//
// scroller ( width, height, content);                        // generating scroller
// scroller_init();                                           // init scroller
// [document.getElementById('scroller_content').innerHTML=''] // replace content after generation
//

var iens6=document.all||document.getElementById
var ns4=document.layers

var scrollspeed =  20 // scrollspeed, lower is faster 

var step=5
var contentobj
var contentheight
var theobj
var theheight
var thename
var thecontainer
var theScroller
var timerup
var timerdown
var timerupname
var timerdownname


function director(incomingScroller,theFunction) {
stopall()
theScroller=incomingScroller
theobj = "contentobj"+theScroller
theheight = "contentheight"+theScroller
if(iens6){
	thename = "content"+theScroller
	theobj=document.getElementById? document.getElementById(thename):document.all.thename
	theheight=theobj.offsetHeight
	if (document.getElementById&&!document.all){
   		step=5
	}
}else if(ns4){
	thename = "nscontent"+theScroller
	thecontainer = "nscontainer"+theScroller
	theobj = eval("document."+thecontainer+".document."+thename)
	theheight=theobj.clip.height
}
	if(theFunction=="sd") {
		timerdown="window.down"+theScroller
		timerdownname="down"+theScroller
		scrolldown()
	}else if(theFunction=="su") {
		timerup="window.up"+theScroller
		timerupname="up"+theScroller
		scrollup()
	}else if(theFunction=="sa") {
		stopall()
	}else if(theFunction=="st") {
		shifttotop()
	}
}

function scrolldown() {
	if(iens6&&parseInt(theobj.style.top)>=(theheight*(-1)+100)){
		theobj.style.top=parseInt(theobj.style.top)-step +"px"
	}else if(ns4&&theobj.top>=(theheight*(-1)+100)){
		theobj.top-=step 
	}
	timerdownname = setTimeout("scrolldown()",scrollspeed)
}


function scrollup() {
	if(iens6&&parseInt(theobj.style.top)<=0){
		theobj.style.top=parseInt(theobj.style.top)+step +"px"
	}else if(ns4&&theobj.top<=0){
		theobj.top+=step
	}
	timerupname = setTimeout("scrollup()",scrollspeed)
}


function stopall() {
	if(timerup){
		clearTimeout(timerupname)
	}
	if(timerdown){
		clearTimeout(timerdownname)
	}
}

function shifttotop(){
	stopall()
	if (iens6) {
		theobj.style.top=0
	}else{
		theobj.top=0
	}
}


function scroller_init() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}


function scroller(width, height, content){
	var scrollerwidth    = width;
	var scrollerheight   = height;

	var t = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\""+scrollerwidth+"\"><tr height=\""+scrollerheight+"\"><td class=\"white10\" valign=\"center\" width=\""+(scrollerwidth - 40)+"\"><table valign=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\""+(scrollerwidth - 40)+"\"><tr height=\""+(scrollerheight - 30)+"\"><td class=\"white10\" valign=\"top\">";

	if (iens6){
		t += "<div id=\"container1\" style=\"width:"+(scrollerwidth - 40)+"px;height:"+(scrollerheight - 0)+"px;position:relative;overflow:hidden;border:0px ridge white\">";
		t += "<div id=\"content1\" style=\"position:relative;width:"+(scrollerwidth - 40)+"px;left:0;top:0\">";
	}

	t += "<ilayer name=\"nscontainer1\" width=\""+(scrollerwidth - 40)+"\" height=\""+(scrollerheight - 6)+"\" clip=\"0,"+(scrollerwidth - 40)+","+(scrollerheight - 6)+",0\"><layer name=\"nscontent1\" width=\""+(scrollerwidth - 40)+"\" height=\""+(scrollerheight - 36)+"\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\""+(scrollerwidth - 40)+"\"><tr height=\""+(scrollerheight - 36)+"\"><td width=\"10\"></td><td class=\"white11\" valign=\"top\"><p align=\"justify\"><div id='scroller_content' >"+content+"</div></p></td><td width=\"10\"></td></tr></table></layer></ilayer>";

	if (iens6){
	  	 t += "</div></div>";
	}

	t += "</td></tr></table></td><td width=\"11\"></td><td background=\"images/scroll_bg.gif\" width=\"16\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"16\"><tr height=\"18\"><td><a href=\"#\" onmouseover=\"Javascript:director(1,'su')\" onmouseout=\"Javascript:stopall()\"><img src=\"images/scroll_up_out.gif\" hsrc=\"images/scroll_up_over.gif\" border=\"0\" width=\"16\" height=\"18\"></a></td></tr><tr height=\""+(scrollerheight - 40)+"\"><td></td></tr><tr height=\"18\"><td><a href=\"#\" onmouseover=\"Javascript:director(1,'sd')\" onmouseout=\"Javascript:stopall()\"><img src=\"images/scroll_down_out.gif\" hsrc=\"images/scroll_down_over.gif\" border=\"0\" width=\"16\" height=\"18\"></a></td></tr></table></td></tr></table>";

	return t;
}