//**************************************
// Ticker Object
// COPYRIGHT ADVANTYS 1999
//**************************************

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()


if (!is.min) ad=-1
else ad=5
function GetCurrentADB()
{
return ad;
}

//Object constructor
//******************
function Ticker(top,left,width,height,speed,step,startpos,content,color,bgpic,position,visibility)
{
		//Private properties
		//******************
		this.ns4 = (document.layers)? true:false
		this.ie4 = (document.all)? true:false
		this.content=content;
		this.w=width;
		this.h=height;
		this.manualscroll=false; 
		this.x_click=0;			// stored mouse X cursor position in manualscroll()
		this.delta=0;			//store the difference betxeen x_click and the mouse x coordinates while the mousebutton 1 is down
		this.firstpass=0;		//store the fisrt passage in manualscroll()
		this.scrollindex=startpos; // index du scrolling
		this.l = left;
		this.t = top;

		//visibility is set to true by default is not passed as argument
		//**************************************************************
		if (visibility!=null) this.visibility = visibility;
		else this.visibility = true;

		//position is set to true by default is not passed as argument
		//************************************************************
		if (position!=null) this.position = position;
		else this.position = 'absolute';

		//color is set to '' by default is not passed as argument
		//*******************************************************
		if (color==null) this.color=''
		else this.color = color;

		//bgpic is set to '' by default is not passed as argument
		//*******************************************************
		if (bgpic==null) this.bgpic=''
		else this.bgpic = bgpic;
		this.changeDirection=false;
		this.objname = "AdvTicker"+(Ticker.count++)

		//Public properties
		//*****************
		this.speed=speed;		//scrolling speed
		this.step=step;			//scrolling step

		//Public Methods
		//**************
		this.hide=Ticker_hide;
		this.show=Ticker_show;
		this.moveTo=Ticker_move;
		this.resize=Ticker_resize;
		this.changeColor=Ticker_changeColor;
		this.write=Ticker_writeContent;
		this.onchangedirection=null;

		//Private Methods
		//***************
        this.autoScroll=Ticker_autoScroll;	
		this.build=Ticker_build;
		this.activate=Ticker_activate
		this.writeTicker=Ticker_write

		//Calling some core methods
		//*************************
		this.build();
		this.writeTicker();
		this.activate();
		//activate the scrolling
		//*********************
		this.autoScroll();

}
Ticker.count = 0


//Set the scroll for manuel (mouse) move
//**************************************
function Ticker_startManualScroll()
{
	this.parent.manualscroll = true
}



//Set the scroll for autmatic move
//********************************
function Ticker_stopManualScroll()
{
		this.parent.manualscroll = false
		this.parent.firstpass = 0
}


//Get the mouse pointer coordinates if the manual mode is set on
//**************************************************************
function Ticker_manualScroll(e)
{
		if (this.parent.manualscroll == true)
		{
			var x = (this.parent.ns4)? e.screenX:event.screenX
			if (this.parent.firstpass==0)
			{
				this.parent.x_click = x;
				this.parent.firstpass=1;
			}
			else
			{
				var buf=this.parent.delta
				this.parent.delta = this.parent.x_click-x
				if ((buf>=0 &&this.parent.delta <0 ) ||  (buf<0 &&this.parent.delta >=0 )) this.parent.changeDirection=true;
				this.parent.x_click = x
				this.parent.scrollindex=this.parent.scrollindex-this.parent.delta;
			}
			if (this.parent.changeDirection) 
			{
				this.parent.changeDirection=false;
				if (this.parent.onchangedirection !=null) this.parent.onchangedirection();
			}
		}
		if (this.parent.ns4){
		routeEvent(e);
		 }
}

//Scrolling function
//******************
function Ticker_autoScroll()
{
	//get the lenght on the child layer in order to re init the scroll when needed
	//****************************************************************************
	if (this.delta>=0) 
	{
	//Scroll from right to left
	//*************************
		this.scrollindex-=this.step;
		if (this.scrollindex < -this.rootlayer.childlayer.w) this.scrollindex=this.w;
	}
	else	
	{
	//Scroll from left to right 
	//*************************
		this.scrollindex+=this.step;
		if (this.scrollindex > this.w) this.scrollindex=-this.rootlayer.childlayer.w;
	}
	//Assign the next X coordinate to the object
	//*****************************************
	this.rootlayer.childlayer.css.left=this.scrollindex;
	this.rootlayer.childlayer.l=this.scrollindex;


	//Internet Explorer does not allow clipping in the rootlayer when the position is set to relative
	// The tip consist in clipping the childlayer to simulate de rootlayer automatic clip
	//************************************************************************************************
	if (this.ie4 && this.position=='relative')
		if (this.rootlayer.childlayer.css.pixelLeft>=0) this.rootlayer.childlayer.css.clip='rect(0  '+(this.w-this.rootlayer.childlayer.offsetLeft)+'  '+this.h+' 0)'
		else this.rootlayer.childlayer.css.clip='rect(0  '+(this.w+Math.abs(this.rootlayer.childlayer.css.pixelLeft))+'  '+this.h+' '+Math.abs(this.rootlayer.childlayer.css.pixelLeft)+')'

	//Use the speed attribute to call itself
	//**************************************
	timerID = setTimeout(this.obj+".autoScroll()",this.speed);
}

//Bodytext builder
//****************
function Ticker_build()
{
	if (this.ns4) 
	{
		//Netscape only
		//*************
		if (this.position=="absolute") 
		{
			var str= '<LAYER  ID="'+this.objname+'"'
			str+= ' POSITION=absolute LEFT='+this.l+' TOP='+this.t +' CLIP="0,0,'+this.w+','+this.h+'"'
			str+= ' HEIGHT='+this.h+'  WIDTH='+this.w+'  BGCOLOR="'+this.color+'" BACKGROUND="'+this.bgpic+'">\n'
			str+= '<LAYER ID="'+this.objname+'child" POSITION=relative HEIGHT='+this.h+' WIDTH='+this.w+'  BGCOLOR="'+this.color+'" BACKGROUND="'+this.bgpic+'">\n'
			str +=this.content+'</LAYER></LAYER>\n'
		}
		else
		{
			var str= '<ILAYER ID=ilayer><LAYER  ID="'+this.objname+'"'
			str+= ' POSITION=absolute LEFT='+this.l+' TOP='+this.t+' CLIP="0,0,'+this.w+','+this.h+'"'
			str+= ' HEIGHT='+this.h+'  WIDTH='+this.w+'  BGCOLOR="'+this.color+'"  BACKGROUND="'+this.bgpic+'">\n'
			str+= '<LAYER ID="'+this.objname+'child" POSITION=relative HEIGHT='+this.h+' WIDTH='+this.w+'  BGCOLOR="'+this.color+'"  BACKGROUND="'+this.bgpic+'">\n'
			str +=this.content+'</LAYER></LAYER></ILAYER>\n'
		}
	}	
	else	
	{
		//Internet Explorer only
		//**********************
		if (this.position=="absolute") 
		{

			var str= '<DIV  ID="'+this.objname+'" STYLE="position:absolute;top:'+this.t+';left:'+this.l+';width:'+this.w+';height:'+this.h+';clip:rect(0,'+this.w+','+this.h+',0);background-color:'+this.color+';background-image:URL('+this.bgpic+');">\n'
			str+= '<DIV ID="'+this.objname+'child" STYLE="position:absolute;top:0;left:0;width:'+this.w+'px;height:'+this.h+';background-color:'+this.color+';background-image:URL('+this.bgpic+');">\n'
			str +=this.content+'</DIV></DIV>\n'
		}
		else
		{

			var str= '<DIV  ID="'+this.objname+'" '
			str+= 'STYLE="position:relative;top:'+this.t+';left:'+this.l+';width:'+this.w+';height:'+this.h+';background-color:'+this.color+';background-image:URL('+this.bgpic+');">\n'
			str+= '<DIV ID="'+this.objname+'child" STYLE="position:absolute;width:'+this.w+'px;height:'+this.h+'px;background-color:'+this.color+';background-image:URL('+this.bgpic+');">\n'
			str +=this.content+'</DIV></DIV>\n'
		}
	}
	this.tickertext=str;
}


//write the DHTML code corresponding to the object
//************************************************
function Ticker_write()
{
	document.write(this.tickertext);
}

//re-write into the ticker
//************************
function Ticker_writeContent(content) 
{
  if (this.ns4) 
  {
   this.rootlayer.childlayer.document.open()
   this.rootlayer.childlayer.document.write(content)
   this.rootlayer.childlayer.document.close()
  }
  else 
  {
    var str = "document.all." + this.objname + "child.innerHTML = '" + content + "'";
    eval(str);
  }
}

//move the ticker
//***************
function Ticker_move(x, y) 
{

  if (this.ns4) this.rootlayer.moveTo(x, y);
  else 
  {
	this.rootlayer.css.left = x;
    this.rootlayer.css.top  = y;
  }
  this.l=x;
  this.t=y;
}


//resize the ticker
//*****************
function Ticker_resize(w, h) 
{
  if (this.ns4) 
  {
	this.rootlayer.resizeTo(w, h);
  }
  else 
  {
	this.rootlayer.css.width = w;
	this.rootlayer.css.height  = h;
	this.rootlayer.css.clip  = "rect(0px "+w+"px "+h+"px 0px)"
  }
  this.w=w;
  this.h=h;
}

//hide the ticker
//***************
function Ticker_hide() 
{
  if (this.ns4) this.rootlayer.css.visibility = "hide";
  else this.rootlayer.css.visibility = "hidden";
}

//show the ticker
//***************
function Ticker_show()
{
  if (this.ns4)  this.rootlayer.css.visibility = "show";
  else this.rootlayer.css.visibility = "visible";
}

//change the background color
//***************************
function Ticker_changeColor(color)
{
  if (this.ns4)  
  {
	this.rootlayer.css.bgColor = color;
	this.rootlayer.childlayer.css.bgColor= color;
  }
  else 
  {
	this.rootlayer.css.backgroundColor = color;
	this.rootlayer.childlayer.css.backgroundColor = color;
  }
}


//initialize the object, set all events, and make the object come alive
//*********************************************************************
function Ticker_activate()
{
		childobjname=this.objname+'child';
		if (this.ns4) childobjname='document.'+this.objname+'.document.'+childobjname
		ns4prefix =(this.ns4 && this.position=='relative') ? 'document.ilayer.' :''
		this.rootlayer=(this.ns4) ? eval(ns4prefix+'document.'+this.objname):eval(this.objname)
		this.rootlayer.css=(this.ns4) ? eval(ns4prefix+'document.'+this.objname):eval(this.objname+'.style')
		this.rootlayer.childlayer=eval(ns4prefix+childobjname)
		this.rootlayer.childlayer.css=(this.ns4) ? eval(ns4prefix+childobjname):eval(childobjname+'.style')
		this.rootlayer.parent = this

		if (this.ns4) 
		{
			this.l = this.rootlayer.css.left;
			this.t = this.rootlayer.css.top;
			this.rootlayer.childlayer.w=this.rootlayer.childlayer.css.clip.right 
			this.rootlayer.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE | Event.MOUSEOUT)
		}	
		else
		{
			this.l = parseInt(this.rootlayer.css.left);
			this.t = parseInt(this.rootlayer.css.top);
			this.rootlayer.childlayer.w=parseInt(this.rootlayer.childlayer.offsetWidth)
		}	
		this.rootlayer.childlayer.l = this.scrollindex;
		// events capture
		//****************
		this.rootlayer.onmousedown = Ticker_startManualScroll
		this.rootlayer.onmouseup = Ticker_stopManualScroll
		this.rootlayer.onmouseout = Ticker_stopManualScroll
		this.rootlayer.onmousemove = Ticker_manualScroll

		//Needed by setTimeOut function : the parameter is a text string not a pointer
		//******************************************************************************
		this.obj= this.objname+"layer"
		eval(this.obj + "=this");

		//check the visibility set by user and do the action
		//**************************************************
		if (!this.visibility) this.hide();

}
//**************************************
// end of Ticker Object
//**************************************

