/**********************************************
IE FF

全域變數說明
obj 要捲動的DIV
range DIV的可視範圍

html範例

<div id="left">
	<img src="images/arrow_left.png" onMouseOver="turnRight(3)" onMouseOut="stopMove()" onMouseDown="turnRight(8)" onMouseUp="turnRight(3)">
</div>
<div id="center">
	<div id="tmp_img" style="position:relative;top:0px;left:0px;width:<?=$img_center_width?>px">
		很多圖片或是DIV的GROUP                                             ↑所有圖片或是DIV的GROUP 加起來的總寬
	</div>
</div>
<div id="right">
	<img src="images/arrow_right.png" onMouseOver="turnLeft(3)" onMouseOut="stopMove()" onMouseDown="turnLeft(8)" onMouseUp="turnLeft(3)">
</div>

CSS
#left {
	position:absolute;
	top:0px;
	left:4px;
	width:18px;
	height:70px;
}
#center {
	position:absolute;
	top:0px;
	left:23px;
	width:490px;
	height:100px;
	overflow:hidden;
}
#right {
	position:absolute;
	top:0px;
	left:513px;
	width:18px;
	height:70px;
}
***********************************************/
var timerID;
var obj = null;
var range = 0;
/*
var obj=document.getElementById('tmp_img');
var range=450;
*/
function turnLeft(rate)
{
	clearInterval(timerID);
	timerID=setInterval("startTurnLeft("+rate+")",5);
}
function turnRight(rate)
{
	clearInterval(timerID);
	timerID=setInterval("startTurnRight("+rate+")",5);	
}
function startTurnRight(rate)
{
	var position=getPosition('x');
	if(position<0)
	{
		obj.style.left=eval(position)+rate + "px";
	}
}
function startTurnLeft(rate)
{	
	var position=getPosition('x');
	var width=(obj.style.width).slice(0,-2);
	if(-position<(width-range))
	{
		obj.style.left=position-rate + "px";	
	}
}
function turnUp(rate)
{
	clearInterval(timerID);
	timerID=setInterval("startTurnUp("+rate+")",5);
}
function turnDown(rate)
{
	clearInterval(timerID);
	timerID=setInterval("startTurnDown("+rate+")",5);	
}
function startTurnDown(rate)
{
	var position=getPosition('y');
	if(position<0)
	{
		obj.style.top=eval(position)+rate + "px";
	}
}
function startTurnUp(rate)
{	
	var position=getPosition('y');
	var height=(obj.style.height).slice(0,-2);
	if(-position<(height-range))
	{
		obj.style.top=position-rate + "px";		
	}
}
function stopMove()
{
	clearInterval(timerID);	
}

function getPosition( type )
{
	if( type == 'x' )
	{
		return (obj.style.left).slice(0,-2);
	}
	else if( type == 'y' )
	{
		return (obj.style.top).slice(0,-2);
	}
}

function SetScroller( obj_id , block_range )
{
	obj = document.getElementById( obj_id );
	range = block_range;
}
