var Tape = {	

	speedHoriz:		75, // 1/x
	speedVert:			65, // 1/x

	boxTop:				new Array(),
	boxLeft:				new Array(),
	boxTimer:			new Array(),
	boxWidth:			new Array(),
	boxBodyWidth:	new Array(),
	boxHeight:			new Array(),
	boxBodyHeight:	new Array(),

	runHoriz : function(id, direction, stop) // direction == 1 -- right
	{
		pid = this.getPrimaryId(id);
		if (!direction) direction = 0;
		if (!stop) stop = 0;

		//-
		if (!this.boxLeft[pid]) this.boxLeft[pid] = 0;
		this.boxWidth[pid]			= gE(pid + "_ul").clientWidth;
		this.boxBodyWidth[pid]	= gE(pid + "_body").clientWidth;
		//-
//gE("123123").innerHTML = Math.abs(this.boxLeft[pid]);		
		var f = false;
		f =  !direction ? Math.abs(this.boxLeft[pid])>this.boxWidth[pid]-this.boxBodyWidth[pid] : this.boxLeft[pid] == 0;

		if(f || stop)
		{
			clearTimeout(this.boxTimer[pid]);
			return;
		}

		if (direction == 1)
		{
			var delta = Math.round(Math.abs(this.boxLeft[pid])/10);		
			delta = delta == 0 ? 1 : delta;
			this.boxLeft[pid] += delta;
		}
		else
		{
			var delta = Math.round((this.boxWidth[pid]-this.boxBodyWidth[pid]-Math.abs(this.boxLeft[pid]))/10);		
			if (ua != "IE") delta = this.boxWidth[pid]-this.boxBodyWidth[pid]-Math.abs(this.boxLeft[pid]) != 0 && delta == 0 ? 1 : delta;
			this.boxLeft[pid] -= delta;
		}

		$("#" + pid + "_ul").css({left:this.boxLeft[pid]+"px"});
		this.boxTimer[pid] = setTimeout("Tape.runHoriz('" + id + "', " + direction + ", " + stop + ")", this.speedHoriz - Math.round((1/delta) * 40));
	},

	runVert : function(id, direction, stop) // direction == 1 -- down
	{
		pid = this.getPrimaryId(id);
		if (!direction) direction = 0;
		if (!stop) stop = 0;

		//-
		if (!this.boxTop[pid]) this.boxTop[pid] = 0;
		this.boxHeight[pid]			= gE(pid + "_ul").clientHeight;
		this.boxBodyHeight[pid]	= gE(pid + "_body").clientHeight;
		//-
//gE("123123").innerHTML = this.boxTop[pid];		
		var f = false;
		f =  !direction ? Math.abs(this.boxTop[pid])>this.boxHeight[pid]-this.boxBodyHeight[pid] : this.boxTop[pid] == 0;

		if(f || stop)
		{
			clearTimeout(this.boxTimer[pid]);
			return;
		}

		if (direction == 1)
		{
			var delta = Math.round(Math.abs(this.boxTop[pid])/10);		
			delta = delta == 0 ? 1 : delta;
			this.boxTop[pid] += delta;
		}
		else
		{
			var delta = Math.round((this.boxHeight[pid]-this.boxBodyHeight[pid]-Math.abs(this.boxTop[pid]))/10);		
			/*if (ua != "IE")*/ delta = this.boxHeight[pid]-this.boxBodyHeight[pid]-Math.abs(this.boxTop[pid]) != 0 && delta == 0 ? 1 : delta;
			this.boxTop[pid] -= delta;
		}

		$("#" + pid + "_ul").css({top:this.boxTop[pid]+"px"});
		this.boxTimer[pid] = setTimeout("Tape.runVert('" + id + "', " + direction + ", " + stop + ")", this.speedVert - Math.round((1/delta) * 40));
	},

	runLeft : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id);
	},

	runLeftStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 0, 1);
	},

	runRight : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 1);
	},

	runRightStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 1, 1);
	},

	runUp : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id);
	},

	runUpStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 0, 1);
	},

	runDown : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 1);
	},

	runDownStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 1, 1);
	},

	getPrimaryId: function(id)
	{
		var re = new RegExp("\_[^_]+$","ig");
		id = id.replace(re, '');
		
		return id;
	}
}

