﻿var Scroller = function(frameId,contentId,direction,tempo,w,h){
	                     // default parameters
	                     var thisObj        = this;
	                     this.nXlocation    = 0;
	                     this.nYlocation    = 0;
	                     this.nFrameHeight  = h;
	                     this.nFrameWidth   = w;
	                     this.nTempo        = tempo;
	                     this.strDirection  = direction;
	                     this.scrollerStat  = true;
	                     this.objFrame      = document.getElementById(contentId);
	
	                     // frame parameter
	                     f              = document.getElementById(frameId);
	                     f.style.height = h+'px';
	                     f.style.width  = w+'px';

	                     this.MoveScroller = function(){
		                                        switch(this.strDirection){
		                                           case 'u':	// moving up
				                                      this.nXlocation--;
				                                      this.objFrame.style.top=this.nXlocation+"px";
				                                      break;
			                                       case 'd':	// moving sown
				                                      this.nXlocation++;
				                                      this.objFrame.style.top=this.nXlocation+"px";
				                                      break;
			                                       case 'r':	// moving right
				                                      this.nYlocation++;
				                                      this.objFrame.style.left=this.nYlocation+"px";
				                                      break;
			                                       case 'l':	// moving left
				                                      this.nYlocation--;
				                                      this.objFrame.style.left=this.nYlocation+"px";
				                                      break;
		                                        }
	                                         }

	                     this.CheckScroller = function(){
		                                         switch(this.strDirection){
			                                        case 'u':
				                                       if ((0-this.nXlocation) > this.objFrame.offsetHeight){
				                                          this.nXlocation = this.nFrameHeight;
				                                       }
				                                       break;
			                                        case 'd':
				                                       if (this.nXlocation > this.nFrameHeight){
				                                          this.nXlocation = -this.objFrame.offsetHeight;
				                                       }
				                                       break;
			                                        case 'r':
				                                       if (this.nYlocation > this.nFrameWidth){
				                                          this.nYlocation = -this.objFrame.offsetWidth;
				                                       }
				                                       break;
			                                        case 'l':
				                                       if ((0-this.nYlocation) > this.objFrame.offsetWidth){
				                                          this.nYlocation = this.nFrameWidth;
				                                       }
				                                       break;
		                                         }	
	                                          }
	
	                     this.RunScroll = function(){
		                                     if (this.scrollerStat){
			                                    this.MoveScroller();
			                                    this.CheckScroller();
		                                     }
	                                      }
	
	                     this.StartScroll = function(){
		                                       setInterval(function() { thisObj.RunScroll(); },thisObj.nTempo);
	                                        }
	                     // for stop on mouse over
	                     this.StopScroll = function(){
                                              this.scrollerStat = false;
                                           }

                         this.ContinueScroll = function(){
                                                  this.scrollerStat = true;
                                               }
	
                      }