/* Copyright Soft2Connect 2006 */

/*
 * The standard S2C getElement function
 */
function S2C_GetElement(id){
	if(document.layers) {
		return document.layers[id];
	}
	//gecko(NN6) + IE 5+
	else if(document.getElementById) {
		return document.getElementById(id);
		obj.style.display = display;
	}
	// IE 4
	else if(document.all) {
		return document.all[id];
	}
	return null;
}

function scrollBar() {	
	/*
	 *  Initial Values
	 */
	this.scrollerwidth  	= 700;		// Scrollers width here (in pixels)
	this.scrollerheight 	= 100;		// Scrollers height here
	this.scrollerspeed  	= 1;			// Scrollers speed here (larger is faster 1-10)
	this.scrollercontent = '';		// Scrollers content goes here! Keep all of the message on the same line!
	this.htmlContentHeight	= '';	// Height of the HTML content
	this.actualWidth	= '';			// Width of the HTML content
	this.sliderDelta = 1;				// Delta the slider should move per pixel top moved
	
	this.pauseit=1;
	
	/*
	 *  Initial Constants
	 *  Do not change!
	 */
	this.scrollerspeed=(document.all)? this.scrollerspeed : Math.max(1, this.scrollerspeed-1); //slow speed down by 1 for NS
	//er
	this.copyspeed=this.scrollerspeed;
	this.iedom =	document.all||document.getElementByid;
	
	this.cross_scroller;
	this.cross_scroller2;
	this.ns_scroller;
	this.slider;
	this.pausespeed=(this.pauseit==0)? this.copyspeed: 0;
	this.id = 0;
	
	/*
	 *  Function to pass the variables
	 * Pay attention: overlap when scrollerWthis.idth < actualWthis.idth 
	 */
	this.initScrollArea = function(id, scrollAreaWidth, scrollAreaHeight, contentHeight, contentWidth, initScrollercontent, initScrollerspeed){
		this.id = id;
		this.scrollerwidth		= scrollAreaWidth;
		this.scrollerheight		= scrollAreaHeight;
		this.htmlContentHeight	= contentHeight;
		this.actualWidth			= contentWidth;
		this.scrollercontent		= initScrollercontent; 
		this.scrollerspeed		= initScrollerspeed;
		
		/* Initially the text does not scroll */
		this.copyspeed			= this.pausespeed;				
		/* 
		 * Arrow height  = 2*22 = 44
		 * Slider height 		= 100
		 */
		this.sliderDelta			= (scrollAreaHeight - 44 - 100) / (contentHeight - scrollAreaHeight) ;
	}
	
	/*
	 *  Function to start scroller
	 */
	this.populateScrollArea = function(){	
			this.cross_scroller = S2C_GetElement("scrollArea"+this.id);
			this.cross_scroller.style.top= 0;          			// Start with Text aligned at the top
			this.cross_scroller.style.left= 0;          			// Start with Text aligned at the top
			this.cross_scroller.width = this.actualWidth;
			this.cross_scroller.innerHTML= this.scrollercontent;		// Pass HTML to scrollArea
			
			this.cross_scroller2= S2C_GetElement("scrollArea2"+this.id);
			this.cross_scroller2.style.top= 0; 
			this.cross_scroller2.style.left= this.actualWidth;          			// Start with Text aligned at the top
			this.cross_scroller2.width = this.actualWidth;
			this.cross_scroller2.innerHTML= this.scrollercontent;		// Pass HTML to scrollArea
		
			this.slider	= S2C_GetElement("slider"+this.id);
	}
	
		/*
	 *  Function to start scroller
	 */
	this.populateScrollAreaVWS = function(){	
			this.cross_scroller = S2C_GetElement("scrollArea"+this.id);
			this.cross_scroller.style.top= 0;          			// Start with Text aligned at the top
			this.cross_scroller.style.left= 0;          			// Start with Text aligned at the top
			this.cross_scroller.width = this.actualWidth;
			this.cross_scroller.innerHTML= this.scrollercontent;		// Pass HTML to scrollArea

			this.slider	= S2C_GetElement("slider"+this.id);
	}
	
	/*
	 *	Function to keep scrolling horizontal
	 */
	
	this.scrollScrollAreaHorizontal = function(){		/* First check if the box is not with his right sthis.ide on the left side of the view box */
		if (parseInt(this.cross_scroller.style.left) > (this.actualWidth*(-1))){
			// Not out of the view box. So move one step to the left.
			
			/* PROBLEM IS HE CAN NOT FIND cross_scroller*/
			this.cross_scroller.style.left 	=	parseInt(this.cross_scroller.style.left)-this.copyspeed+"px";
		}
		else {
			// Out of the viewing box. Place after the other box so on actualWidth
			this.cross_scroller.style.left	=	parseInt(this.actualWidth)+"px";
		}
		
		/*
		 * OK The same for the second bar
		 */
		if (parseInt(this.cross_scroller2.style.left) > (this.actualWidth*(-1))){
			this.cross_scroller2.style.left 	=	parseInt(this.cross_scroller2.style.left)-this.copyspeed+"px";
		}
		else {
			this.cross_scroller2.style.left 	=	parseInt(this.actualWidth)+"px";
		}
		
		if(parseInt(this.cross_scroller.style.left) > 0){
			/* now if scrolling to the right */
			this.cross_scroller2.style.left 	=	parseInt(this.cross_scroller.style.left) - this.actualWidth+"px";
		}
		if(parseInt(this.cross_scroller2.style.left) > 0){
			/* now if scrolling to the right */
			this.cross_scroller.style.left 	=	parseInt(this.cross_scroller2.style.left) - this.actualWidth+"px";
		} 
	}
	
	/*
	 *  Function to keep scrolling normal vertical window
	 */
	
	this.scrollScrollArea = function(){
		/* Calculate new position of slider */
		//if(document.getElementByid? document.getElementByid("slider"+this.id) : document.all.slider1 != null){
		if(S2C_GetElement("scrollArea"+this.id) != null) {
				var test = parseInt(this.cross_scroller.style.top) * this.sliderDelta * -1+"px";
		}

		/* calculate new position */
		this.cross_scroller.style.top = parseInt(this.cross_scroller.style.top)-this.copyspeed+"px";
		
		
		
		/* Upper boundary */
		if (parseInt(this.cross_scroller.style.top) < (this.htmlContentHeight*(-1) + this.scrollerheight)){
			this.cross_scroller.style.top = (this.htmlContentHeight*(-1) + this.scrollerheight);
			this.copyspeed=this.pausespeed;
		}
		/* Lower boundary */
		else if (parseInt(this.cross_scroller.style.top) > 0){
			this.cross_scroller.style.top = 0;
			this.copyspeed=this.pausespeed;
		}
		
	}
	
	this.scrollScrollAreaWS = function(){
		/* Calculate new position of slider */
		//if(document.getElementByid? document.getElementByid("slider"+this.id) : document.all.slider1 != null){
		this.slider.style.top = parseInt(this.cross_scroller.style.top) * this.sliderDelta * -1+"px";
		/* calculate new position */
		this.cross_scroller.style.top = parseInt(this.cross_scroller.style.top)-this.copyspeed+"px";
		
		
		
		/* Upper boundary */
		if (parseInt(this.cross_scroller.style.top) < (this.htmlContentHeight*(-1) + this.scrollerheight)){
			this.cross_scroller.style.top = (this.htmlContentHeight*(-1) + this.scrollerheight);
			this.copyspeed=this.pausespeed;
		}
		/* Lower boundary */
		else if (parseInt(this.cross_scroller.style.top) > 0){
			this.cross_scroller.style.top = 0;
			this.copyspeed=this.pausespeed;
		}
		
	}
	
	/*
	 *  Function to write scrollarea to screen
	 */
	this.writeScrollAreaHorizontal = function(scrollArea){
		
		with (document){			
			write('<table width'+this.scrollerwidth+' height='+this.scrollerheight+' >')
			write(	'<tr>')
			write(		'<td class="text" colspan="3" height="10px"></td>')			
			write(	'</tr>')
			write(	'<tr>')
			
			this.scrollerwidth  = this.scrollerwidth - 20; 	//width  of arrow
			write(		'<td valign="top" width="7%">')											  
			write(			'<div align="center"><img src="images/arrow_left.jpg" width="10" alt="" onMouseover="'+scrollArea+'.copyspeed=-1*'+scrollArea+'.scrollerspeed" onMouseout="'+scrollArea+'.copyspeed='+scrollArea+'.pausespeed" /></div>')
			write(		'</td>')
			write(		'<td class="text" width="'+this.scrollerwidth+'px" height="'+this.scrollerheight+'px">')
			write(			'<div style="position:relative;width:'+this.scrollerwidth+'px;height:'+this.scrollerheight+'px;overflow:hidden" >')
			write(			'<div id="scrollArea'+this.id+'"  style="position:absolute;left:0px;top:0px;width:'+ this.actualWidth +'px;text-align:left;"></div>') //background-color:#00ff00;
			write(			'<div id="scrollArea2'+this.id+'" style="position:absolute;left:0px;top:0px;width:'+ this.actualWidth +'px;text-align:left;"></div>') //background-color:#0000ff;
			write(			'</div>')
			write(		'</td>')
			write(		'<td valign="top" width="7%" >')
			write(			'<div align="center"><img src="images/arrow_right.jpg" width="10" alt="" onMouseover="'+scrollArea+'.copyspeed='+scrollArea+'.scrollerspeed" onMouseout="'+scrollArea+'.copyspeed='+scrollArea+'.pausespeed" /></div>')
			write(		'</td>')
			write(	'</tr>')
			write('</table >')
		}
		lefttime=setInterval(scrollArea+'.scrollScrollAreaHorizontal()',20)		// Evaluate function every 20 ms
		
	}
	
	/*
	 *  Function to write scrollarea to screen
	 */
	this.writeSimpleScrollAreaHorizontal = function(scrollArea){
		
		with (document){			
			write('<table width'+this.scrollerwidth+' height='+this.scrollerheight+' >')
			write(	'<tr>')
			write(		'<td class="text" height="10px"></td>')			
			write(	'</tr>')
			write(	'<tr>')
			write(		'<td class="text" width="'+this.scrollerwidth+'px" height="'+this.scrollerheight+'px">')
			write(			'<div style="position:relative;width:'+this.scrollerwidth+'px;height:'+this.scrollerheight+'px;overflow:hidden;background-color:#ffffff;" >')
			write(			'<div id="scrollArea'+this.id+'"  style="position:absolute;left:0px;top:0px;width:'+ this.actualWidth +'px;text-align:left;"></div>') //background-color:#00ff00;
			write(			'<div id="scrollArea2'+this.id+'" style="position:absolute;left:0px;top:0px;width:'+ this.actualWidth +'px;text-align:left;"></div>') //background-color:#0000ff;
			write(			'</div>')
			write(		'</td>')
			write(	'</tr>')
			write('</table >')
		}
		lefttime=setInterval(scrollArea+'.scrollScrollAreaHorizontal()',20)		// Evaluate function every 20 ms
		
	}
	
	/*
	 *  Function to write scrollarea to screen with scroller
	 */
	this.writeScrollAreaWS = function(scrollArea){
		with (document){			
			write('<table width'+this.scrollerwidth+' height='+this.scrollerheight+' >')
			write(	'<tr>')
			this.scrollerwidth  = this.scrollerwidth - 22; 	//width  of arrow
			write(		'<td class="text" rowspan="3" width="'+this.scrollerwidth+'px" height="'+this.scrollerheight+'px" valign=\"center\">')
			write(			'<div style="position:relative;width:'+this.scrollerwidth+'px;height:'+this.scrollerheight+'px;overflow:hidden;" >')
			write(			'<div id="scrollArea'+this.id+'"  style="position:absolute;left:0px;top:0px;width:'+ this.actualWidth +'px;text-align:left;"></div>') //background-color:#00ff00;
			write(			'</div>')
			write(		'</td>')
			write(		'<td valign="top">')
			write(			'<img src="images/arrow_up.jpg" width="22" height="22" alt="" onMouseover="'+scrollArea+'.copyspeed=-1*'+scrollArea+'.scrollerspeed" onMouseout="'+scrollArea+'.copyspeed='+scrollArea+'.pausespeed" />')
			write(		'</td>')
			write(	'</tr>')
	
			
			write(	'<tr>')
			this.sliderBarHeight = this.scrollerheight - 44;
			write(		'<td height="'+this.sliderBarHeight+'" valign="top">')  
			write(			'<div style="position:relative;top:0px;" id="slider'+this.id+'"><img src="images/slider.gif" width="22" height="100" alt="" /></ div>')
			write(		'</td>')
			write(	'</tr>')
			
			write(	'<tr>')
			write(		'<td valign="bottom">')
			write(			'<img src="images/arrow_down.jpg" width="22" height="22" alt="" onMouseover="'+scrollArea+'.copyspeed='+scrollArea+'.scrollerspeed" onMouseout="'+scrollArea+'.copyspeed='+scrollArea+'.pausespeed" />')
			write(		'</td>')
			write(	'</tr>')
			write('</table >')
		}
		lefttime=setInterval(scrollArea+'.scrollScrollAreaWS()',20)		// Evaluate function every 20 ms
	}
	
	this.automateScroll = function(){
		this.copyspeed = this.scrollerspeed;
	}
}