var pausecontent=new Array();



function pausescroller(content,clipperContent, divId, divClass, delay){

                       
			this.content=content //message array content
			this.tickerid=divId //ID of ticker div to display information
			this.tickerclass=divClass 
			this.delay=delay //Delay between msg change, in miliseconds.
			this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
			this.hiddendivpointer=1 //index of message array for hidden div
            this.clipperContent  = clipperContent;
            
            
			this.prepareDivs();
			
			   var me ='<div id="'+this.tickerid+'" class="'+this.tickerclass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%;" id="'+this.tickerid+'1">'+this.content[0]+'</div><div class="innerDiv" style=";position: absolute; width: 100%; visibility: hidden" id="'+this.tickerid+'2">'+this.content[1]+'</div></div>';		
			   document.write(me);
			var scrollerinstance=this
            var bbb= document.getElementById("mainTickervIEW");
            
			if (window.addEventListener) //run onload in DOM2 browsers
						window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
						
		    else if (window.attachEvent) //run onload in IE5.5+
			            window.attachEvent("onload", function(){scrollerinstance.initialize();})
			            
			else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
						setTimeout(function(){scrollerinstance.initialize()}, 500)
						
		   
			
      }

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
	
	                       
	
	                      
	        	 
	        	        //prepare content
	                    
	                 
						this.tickerdiv=document.getElementById(this.tickerid)
						this.visiblediv=document.getElementById(this.tickerid+"1") //first
						this.hiddendiv=document.getElementById(this.tickerid+"2")
						
						this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv));
						//10
						
						//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
							    this.visiblediv.style.width 
							 =  this.hiddendiv.style.width
							 =  this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px";
	                            //50  - (10*2)  = 28px
						                        
	                    //reset to be default co0r-dinates        
						this.getinline(this.visiblediv, this.hiddendiv);
						this.hiddendiv.style.visibility="visible"
						
						var scrollerinstance=this;
						
						document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
						document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
						if (window.attachEvent) //Clean up loose references in IE
						window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
						setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animatedown=function(){
var scrollerinstance=this

		if (parseInt(this.hiddendiv.style.left)<(this.visibledivtop+5)){
			
			   //move now animation......
		       this.visiblediv.style.left = parseInt(this.visiblediv.style.left)+30+"px"
		       this.hiddendiv.style.left  = parseInt(this.hiddendiv.style.left)+30+"px"
		       setTimeout(function(){scrollerinstance.animatedown()}, 50)
		}
		else{
					this.getinline(this.hiddendiv, this.visiblediv)
					this.swapdivs()
					setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
		}
}

pausescroller.prototype.animateup=function(){
var scrollerinstance=this

		if (parseInt(this.hiddendiv.style.left)>(this.visibledivtop+5)){
			
			   //move now animation......
		       this.visiblediv.style.left = parseInt(this.visiblediv.style.left)-30+"px"
		       this.hiddendiv.style.left  = parseInt(this.hiddendiv.style.left)-30+"px"
		       setTimeout(function(){scrollerinstance.animateup()}, 50)
		}
		else{
					this.getinline(this.hiddendiv, this.visiblediv)
					this.swapdivs()
					setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
		}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

 pausescroller.prototype.swapdivs=function(){
       var tempcontainer=this.visiblediv
           this.visiblediv=this.hiddendiv
           this.hiddendiv=tempcontainer
}

//work as reset divs to be the default coor-dinates

pausescroller.prototype.getinline=function(div1, div2){
      div1.style.left  = this.visibledivtop+"px";
      
      div2.style.left  = Math.max(div1.parentNode.offsetWidth, div1.offsetWidth)+"px"
      
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
         var scrollerinstance=this
                   if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
                           setTimeout(function(){scrollerinstance.setmessage()}, 100)
                   else{
                              var i=this.hiddendivpointer
                              var ceiling=this.content.length
                                        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
										this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
										this.animateup()
						}
}

pausescroller.getCSSpadding = function(tickerobj){ //get CSS padding value, if any
	
      if (tickerobj.currentStyle){
      	         
           return tickerobj.currentStyle["paddingTop"]
      }
      else if (window.getComputedStyle){ //if DOM2
           return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
           
      }
      else
           return 0
}

 pausescroller.prototype.prepareDivs = function(){
				        	         //get all contents of divs
				        	            var divsContent = document.getElementById(this.clipperContent);
				        	       
				        	            if (!divsContent) return false;
				        	             
				        	                var  ClipperContent       =  getElementsByClassName("TickerClip","div");
				        	                var  ClipperContentLength = ClipperContent.length;
				        	                if (ClipperContentLength <= 0) return false;
				        	               
				        	                else
				        	                {
				        	                	 
				        	                	//add data to containers
				        	                	for (var con=0; con < ClipperContentLength; con++){
				        	                		pausecontent[con] = ClipperContent[con].innerHTML;
				        	                	}
				        	                }
	        	           }
	        	           
	        	           
	function getElementsByClassName(classname,tag) {
					 if(!tag) tag = "*";
					 var anchs =  document.getElementsByTagName(tag);
					 var total_anchs = anchs.length;
					 var regexp = new RegExp('\\b' + classname + '\\b');
					 var class_items = new Array()
					 
					 for(var i=0;i<total_anchs;i++) { //Go thru all the links seaching for the class name
					  var this_item = anchs[i];
					  if(regexp.test(this_item.className)) {
					   class_items.push(this_item);
					  }
					 }
	 			return class_items;
	}