dojo.require("dojox.fx.easing");
 
var MarqueeWholeHorizontal = function(blockId,duration){
	this.blockId = blockId;
	this.duration = duration;
	this.startValue;
	this.endValue;
	
	
	this.combine = null; 
	this.combineObj = null; 
	this.mouseAreaOverObj = null;
	this.mouseAreaOutObj = null;
	
	
    this._doAnim = function() {
	    this.combine = dojo.animateProperty({
	      node: dojo.byId(this.blockId + "_content_value"),
	      easing: dojox.fx.easing["linear"],
	      duration: this.duration,
	      properties: {
	        left: { start: this.startValue, end: this.endValue, unit:"px" }
	      }
	    });

	    this.combineObj = dojo.connect(this.combine, "onEnd" , this, function(){
	    	dojo.byId(this.blockId + "_content_value").style.left = this.startValue+"px";
	    	this._doAnim();
	    	
	    });
	    this.combine.play();
	}
	this.start = function(){
	
	
		this.startValue = dojo.byId(this.blockId + "_content_panel").offsetWidth;
		this.endValue = 0 - dojo.byId(this.blockId + "_content_value").offsetWidth;
		
	  	dojo.byId(this.blockId + "_content_value").style.left = this.startValue+"px";
	  	this._doAnim();
	  	
	  	var objThis = this;
	  	this.mouseAreaOverObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseover" , objThis,function(event){
	    	objThis._pause();
	    });
	    this.mouseAreaOutObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseout" , objThis,function(event){
	    	objThis._play();
	    });
	}
	this._pause = function(){
	  	if(this.combine && this.combine.status() == "playing"){
      		this.combine.pause();
		}
	}
	this._play = function(){
	  	if(this.combine && this.combine.status() == "paused"){
	      this.combine.play();
	    }
	}
	this.stop = function(){
		
	  	dojo.disconnect(this.mouseAreaOverObj);
	  	dojo.disconnect(this.mouseAreaOutObj);
	  	this.combine.stop();
	  	dojo.disconnect(this.combineObj);
	  	dojo.byId(this.blockId + "_content_value").style.left = "0px";
	}
}


var MarqueeWholeVertical = function(blockId,duration){
	this.blockId = blockId;
	this.duration = duration;
	this.startValue;
	this.endValue;
	
	
	this.combine = null; 
	this.combineObj = null; 
	this.mouseAreaOverObj = null;
	this.mouseAreaOutObj = null;
	
	
    this._doAnim = function() {
	    this.combine = dojo.animateProperty({
	      node: dojo.byId(this.blockId + "_content_value"),
	      easing: dojox.fx.easing["linear"],
	      duration: this.duration,
	      properties: {
	        top: { start: this.startValue, end: this.endValue, unit:"px" }
	      }
	    });

	    this.combineObj = dojo.connect(this.combine, "onEnd" , this, function(){
	    	dojo.byId(this.blockId + "_content_value").style.top = this.startValue+"px";
	    	this._doAnim();
	    	
	    });
	    this.combine.play();
	}
	this.start = function(){
	
	
		this.startValue = dojo.byId(this.blockId + "_content_panel").offsetHeight;
		this.endValue = 0 - dojo.byId(this.blockId + "_content_value").offsetHeight;
		
	  	dojo.byId(this.blockId + "_content_value").style.top = this.startValue+"px";
	  	this._doAnim();
	  	
	  	var objThis = this;
	  	this.mouseAreaOverObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseover" , objThis,function(event){
	    	objThis._pause();
	    });
	    this.mouseAreaOutObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseout" , objThis,function(event){
	    	objThis._play();
	    });
	}
	this._pause = function(){
	  	if(this.combine && this.combine.status() == "playing"){
      		this.combine.pause();
		}
	}
	this._play = function(){
	  	if(this.combine && this.combine.status() == "paused"){
	      this.combine.play();
	    }
	}
	this.stop = function(){
		
	  	dojo.disconnect(this.mouseAreaOverObj);
	  	dojo.disconnect(this.mouseAreaOutObj);
	  	this.combine.stop();
	  	dojo.disconnect(this.combineObj);
	  	dojo.byId(this.blockId + "_content_value").style.top = "0px";
	}
}

var MarqueeOneHorizontal = function(blockId,duration){
	this.blockId = blockId;
	this.duration = duration;
	this.startValue;
	this.endValue;
	
	this.tabDisIndex = 0;
	
	
	this.combine = null; 
	this.combineObj = null; 
	this.mouseAreaOverObj = null;
	this.mouseAreaOutObj = null;
	
	
    this._doAnim = function() {
    
    	var tableObj = $(this.blockId + "_content_table");
	    for(var i=0;i<tableObj.rows.length;i++)
	    	if(i == this.tabDisIndex)
	    		tableObj.rows[i].style.display = "";
	    	else
	    		tableObj.rows[i].style.display = "none";
	    if(this.tabDisIndex == tableObj.rows.length-1)
	    	this.tabDisIndex = 0;
	    else
	    	this.tabDisIndex++;
	    	
	    var combine1 = dojo.animateProperty({
	      node: dojo.byId(this.blockId + "_content_value"),
	      easing: dojox.fx.easing["linear"],
	      duration: this.duration,
	      properties: {
	        left: { start: this.startValue, end: this.endValue, unit:"px" }
	      }
	    });
	    var combine2 = dojo.fadeIn({node: this.blockId + "_content_value",duration: 2000});
	    var combine3 = dojo.fadeOut({node: this.blockId + "_content_value",duration: 1000});
	    
	    
	    this.combine = dojo.fx.chain([combine1,combine2, combine3]);

	    this.combineObj = dojo.connect(this.combine, "onEnd" , this, function(){
	    	dojo.byId(this.blockId + "_content_value").style.left = this.startValue+"px";
	    	dojo.fadeIn({node: this.blockId + "_content_value",duration: 1}).play();
	    	this._doAnim();
	    	
	    });
	    this.combine.play();
	}
	this.start = function(){
	
	
		this.startValue = dojo.byId(this.blockId + "_content_panel").offsetWidth;
		this.endValue = 0;
		
	  	dojo.byId(this.blockId + "_content_value").style.left = this.startValue+"px";
	  	this._doAnim();
	  	/*
	  	this.mouseAreaOverObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseover" , null,function(event){
	    	this._pause();
	    });
	    this.mouseAreaOutObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseout" , null,function(event){
	    	this._play();
	    });
	    */
	}
	this._pause = function(){
	  	if(this.combine && this.combine.status() == "playing"){
      		this.combine.pause();
		}
	}
	this._play = function(){
	  	if(this.combine && this.combine.status() == "paused"){
	      this.combine.play();
	    }
	}
	this.stop = function(){
		
	  	dojo.disconnect(this.mouseAreaOverObj);
	  	dojo.disconnect(this.mouseAreaOutObj);
	  	this.combine.stop();
	  	dojo.disconnect(this.combineObj);
	  	dojo.byId(this.blockId + "_content_value").style.left = "0px";
	}
}

var MarqueeOneVertical = function(blockId,duration){
	this.blockId = blockId;
	this.duration = duration;
	this.startValue;
	this.endValue;
	
	this.tabDisIndex = 0;
	
	
	this.combine = null; 
	this.combineObj = null; 
	this.mouseAreaOverObj = null;
	this.mouseAreaOutObj = null;
	
	
    this._doAnim = function() {
    
    	var tableObj = $(this.blockId + "_content_table");
	    for(var i=0;i<tableObj.rows.length;i++)
	    	if(i == this.tabDisIndex)
	    		tableObj.rows[i].style.display = "";
	    	else
	    		tableObj.rows[i].style.display = "none";
	    if(this.tabDisIndex == tableObj.rows.length-1)
	    	this.tabDisIndex = 0;
	    else
	    	this.tabDisIndex++;
	    	
	    var combine1 = dojo.animateProperty({
	      node: dojo.byId(this.blockId + "_content_value"),
	      easing: dojox.fx.easing["linear"],
	      duration: this.duration,
	      properties: {
	        top: { start: this.startValue, end: this.endValue, unit:"px" }
	      }
	    });
	    var combine2 = dojo.fadeIn({node: this.blockId + "_content_value",duration: 2000});
	    var combine3 = dojo.fadeOut({node: this.blockId + "_content_value",duration: 1000});
	    
	    
	    this.combine = dojo.fx.chain([combine1,combine2, combine3]);

	    this.combineObj = dojo.connect(this.combine, "onEnd" , this, function(){
	    	
	    	dojo.byId(this.blockId + "_content_value").style.top = this.startValue+"px";
	    	dojo.fadeIn({node: this.blockId + "_content_value",duration: 1}).play();
	    	
	    	this._doAnim();
	    	
	    });
	    this.combine.play();
	}
	this.start = function(){
	
	
		this.startValue = dojo.byId(this.blockId + "_content_panel").offsetHeight;
		this.endValue = 0;
		
	  	dojo.byId(this.blockId + "_content_value").style.top = this.startValue+"px";
	  	this._doAnim();
	  	
	  	/*
	  	this.mouseAreaOverObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseover" , null,function(event){
	    	this._pause();
	    });
	    this.mouseAreaOutObj = dojo.connect(dojo.byId(this.blockId + "_content_panel"), "mouseout" , null,function(event){
	    	this._play();
	    });
	    */
	}
	this._pause = function(){
	  	if(this.combine && this.combine.status() == "playing"){
      		this.combine.pause();
		}
	}
	this._play = function(){
	  	if(this.combine && this.combine.status() == "paused"){
	      this.combine.play();
	    }
	}
	this.stop = function(){
		
	  	dojo.disconnect(this.mouseAreaOverObj);
	  	dojo.disconnect(this.mouseAreaOutObj);
	  	this.combine.stop();
	  	dojo.disconnect(this.combineObj);
	  	dojo.byId(this.blockId + "_content_value").style.top = "0px";
	}
}

function countDuration(blockId,wholeOrOne,hv,speed){
	
	var panelObj = $(blockId + "_content_panel");
	var tableObj = $(blockId + "_content_table");
	
	var per = 0;
	if(hv== "Horizontal")
		per = 1-tableObj.offsetWidth/(panelObj.offsetWidth+tableObj.offsetWidth);
	else
	if(hv== "Vertical")
		per = 1-tableObj.offsetHeight/(panelObj.offsetHeight+tableObj.offsetHeight);
		
	
	var count = 0
	
	if(wholeOrOne=="autoWhole" && hv== "Horizontal")
		count = parseInt((16-parseInt(speed))*6000*per)+5000;
	else
	if(wholeOrOne=="autoWhole" && hv== "Vertical")
		count = parseInt((16-parseInt(speed))*4000*per)-1000;
	else
	if(wholeOrOne=="autoOne" && hv== "Horizontal")
		count = parseInt((16-parseInt(speed))*500*per)-100;
	else
	if(wholeOrOne=="autoOne" && hv== "Vertical")
		count = parseInt((16-parseInt(speed))*500*per)-100;
	
	return count;
}
	
