var dopan =false;
var divContent;
var divContentHolder;
var x;
var y;
var fix_obj = new Array();// [name][divContent][divContentHolder]
var on_obj = 0;
var cha_obj = 0;
var pxx = 0;
var pyy = 0;
var c1  = 'url(\'../cursor/grab_hand.cur \'), default';
var c2  = 'url(\'../cursor/pan_hand.cur \'), default';

function detect_in(prf){
	for(var i = 0 ; i < fix_obj.length ; i++ ){
		if(fix_obj.length	>	0  &&  fix_obj[i][0] == prf ){
			on_obj = i ;
			divContentHolder = fix_obj[on_obj][2] ; 
			divContent = fix_obj[on_obj][1] ; 
			return ;
		}
	}
	on_obj = fix_obj.length ; 

  divContent = document.getElementById(prf +'-content');
  divContentHolder = document.getElementById(prf +'-content-holder');
	divContentHolder.style.position = "relative";
	divContent.style.position = "relative";

	fix_obj[fix_obj.length] = new Array( prf , divContent ,divContentHolder , 0);
}

function pan_mousedown(e,prf){
	dopan = true;
	y = e.clientY;  
	for(var i = 0 ; i < fix_obj.length ; i++ ){
		if(fix_obj.length	>	0  &&  fix_obj[i][0] == prf ){
			on_obj = i ;
			divContentHolder = fix_obj[on_obj][2] ; 
			divContentHolder.style.cursor = c1 ;
			if( e.preventDefault )
			   e.preventDefault(); // prevent text selection in FF
			return ;
		}
	}
	on_obj = fix_obj.length ; 

  divContent = document.getElementById(prf +'-content');
  divContentHolder = document.getElementById(prf +'-content-holder');
  divContentHolder.style.cursor = c1 ;
	divContentHolder.style.position = "relative";
	divContent.style.position = "relative";

	fix_obj[fix_obj.length] = new Array( prf , divContent ,divContentHolder , 0);
	
  if( e.preventDefault )
		e.preventDefault(); // prevent text selection in FF
}
function pan_mousemove(e,prf){
	if( dopan == false )
		return;

	if(BrowserDetect.browser != "Safari" && BrowserDetect.browser != "Opera"){
		if( window.event ){
			if( e.button != 1 ){
				pan_mouseup();
				return;
			}
		}
	}

  var dif = y - e.clientY;
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pyy = fix_obj[on_obj][3] ; 

	if( dif > 0 ){ //move up
		if( (divContent.offsetHeight - divContentHolder.offsetHeight) > 
			Math.abs(parseInt(pyy)) ){
			//divContent.style.marginTop = (parseInt( divContent.style.marginTop ) - Math.abs(dif)*2) + 'px';
      pyy -= Math.abs(dif)*2 ;
			divContent.style.top = Math.min(0, pyy ) + 'px';
		}
	}
	else{ // move down
		if( pyy < 0 ){
			//divContent.style.marginTop = Math.min(0, (parseInt( divContent.style.marginTop ) + Math.abs(dif)*2) ) + 'px';
			pyy += Math.abs(dif)*2;
			divContent.style.top = Math.min(0, pyy ) + 'px';
		}
	}
	
	y = e.clientY;
	fix_obj[on_obj][3] = pyy ; 
}
function pan_mouseup(){	
	dopan = false;
	divContentHolder.style.cursor = c2;
}


function pan_mousedown_x(e,prf){
	dopan = true;
	x = e.clientX;  
	for(var i = 0 ; i < fix_obj.length ; i++ ){
		if(fix_obj.length	>	0  &&  fix_obj[i][0] == prf ){
			on_obj = i ;
			divContentHolder = fix_obj[on_obj][2] ; 
			divContentHolder.style.cursor = c1 ;
			if( e.preventDefault )
			   e.preventDefault(); // prevent text selection in FF
			return ;
		}
	}
	on_obj = fix_obj.length ; 

  divContent = document.getElementById(prf +'-content');
  divContentHolder = document.getElementById(prf +'-content-holder');
  divContentHolder.style.cursor = c1 ;
	divContentHolder.style.position = "relative";
	divContent.style.position = "absolute";

	fix_obj[fix_obj.length] = new Array( prf , divContent ,divContentHolder , 0);
	
  if( e.preventDefault )
		e.preventDefault(); // prevent text selection in FF
}
function pan_mousemove_x(e,prf){
	if( dopan == false )
		return;

	if(BrowserDetect.browser != "Safari" && BrowserDetect.browser != "Opera"){
		if( window.event ){
			if( e.button != 1 ){
				pan_mouseup_x();
				return;
			}
		}
	}

  var dif = x - e.clientX;
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pxx = fix_obj[on_obj][3] ; 

	if( dif > 0 ){ //move left
		if( (divContent.offsetWidth - divContentHolder.offsetWidth) > 
			Math.abs(parseInt(pxx)) ){
			//divContent.style.marginLeft = (parseInt( divContent.style.marginLeft ) - Math.abs(dif)*2) + 'px';
      pxx -= Math.abs(dif)*2;
			divContent.style.left = Math.min(0, pxx ) + 'px';
		}
	}
	else{ // move right
		if( pxx < 0 ){
			//divContent.style.marginLeft = Math.min(0, (parseInt( divContent.style.marginLeft ) + Math.abs(dif)*2) ) + 'px';
			pxx += Math.abs(dif)*2;
			divContent.style.left = Math.min(0, pxx ) + 'px';
		}
	}
	
	x = e.clientX;
	fix_obj[on_obj][3] = pxx; 
}
function pan_mouseup_x(){	
	dopan = false;
	divContentHolder.style.cursor = c2;
}


//########################################################################
count = 0
function testmouseout(e,elm){
   
    count++;
    if( window.event ){
        window.status = count + ' src: ' + e.srcElement.id + ' type: ' + e.srcElement.nodeName ;
    }else{
        window.status = count + ' src: ' + e.target.id + ' type: ' + e.target.nodeName ;
   }
}
//########################################################################


var timer, goDownRate=12, goUpRate=12, contentPrefix;
function arrow_down_mousedown(pfx, elm){
	contentPrefix = pfx;
	elm.style.background = '#FF5B00';
	detect_in(pfx);
	goUpRate = 12;
	goup();
	timer = setInterval(goup, 100);
}
function arrow_down_dblclick(pfx){
	contentPrefix = pfx;
	detect_in(pfx);
	goUpRate = 18;
	goup();
}
function arrow_down_mouseup(elm){
	elm.style.background = '#13273A';
	clearInterval( timer );
}
function goup(){
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pyy = fix_obj[on_obj][3] ; 
		
	if( (divContent.offsetHeight - divContentHolder.offsetHeight) > Math.abs(pyy) ){
		pyy -= goUpRate;
		divContent.style.top =pyy  + 'px';
		goUpRate = Math.floor( Math.min( goUpRate * 1.5, divContentHolder.offsetHeight/2) );
	}
	fix_obj[on_obj][3] = pyy ;
	if( (divContent.offsetHeight - divContentHolder.offsetHeight) <= Math.abs(pyy) ){
		document.getElementById(contentPrefix +'-arrow-down').style.background = '#13273A';
		clearInterval( timer );
	}
}
/////////////////////////////////////
function arrow_up_mousedown(pfx, elm){
	contentPrefix = pfx;
	elm.style.background = '#FF5B00';
	detect_in(pfx);
	goDownRate = 12;
	godown();
	timer = setInterval(godown, 100);
}
function arrow_up_dblclick(pfx){
	contentPrefix = pfx;
	detect_in(pfx);
	goDownRate = 18;
	godown();
}
function arrow_up_mouseup(elm){
	elm.style.background = '#13273A';
	clearInterval( timer );
}
function godown(){
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pyy = fix_obj[on_obj][3] ; 
			 
	if( pyy< 0 ){
		pyy += goDownRate ;		
		if(pyy >=  0 ) pyy = 0 ;
		divContent.style.top = pyy+ 'px';
		goDownRate = Math.floor( Math.min( goDownRate * 1.5, divContentHolder.offsetHeight/2) );
	}
	fix_obj[on_obj][3] = pyy ;
	if( pyy>= 0 ){
		document.getElementById(contentPrefix +'-arrow-up').style.background = '#13273A';
		clearInterval( timer );
	}
}
//########################################################################
//var timer, goDownRate=12, goUpRate=12, contentPrefix;
var xtimer, goRightRate=12, goLeftRate=12, xcontentPrefix;
function arrow_right_mousedown(pfx, elm){
	xcontentPrefix = pfx;
	elm.style.background = '#FF5B00';
	detect_in(pfx);
	goLeftRate = 12;
	goleft();
	xtimer = setInterval(goleft, 100);
}
function arrow_right_dblclick(pfx){
	xcontentPrefix = pfx;
	detect_in(pfx);
	goLeftRate = 18;
	goleft();
}
function arrow_right_mouseup(elm){
	elm.style.background = '#13273A';
	clearInterval( xtimer );
}
function goleft(){
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pxx = fix_obj[on_obj][3] ; 
		
	if( (divContent.offsetWidth - divContentHolder.offsetWidth) > Math.abs(pxx) ){
		pxx -= goLeftRate;
		divContent.style.left =pxx  + 'px';
		goLeftRate = Math.floor( Math.min( goLeftRate * 1.5, divContentHolder.offsetWidth/2) );
	}
	fix_obj[on_obj][3] = pxx ;
	if( (divContent.offsetWidth - divContentHolder.offsetWidth) <= Math.abs(pxx) ){
		document.getElementById(xcontentPrefix +'-arrow-right').style.background = '#13273A';
		clearInterval( xtimer );
	}
}
/////////////////////////////////////
function arrow_left_mousedown(pfx, elm){
	xcontentPrefix = pfx;
	elm.style.background = '#FF5B00';
	detect_in(pfx);
	goRightRate = 12;
	goright();
	xtimer = setInterval(goright, 100);
}
function arrow_left_dblclick(pfx){
	xcontentPrefix = pfx;
	detect_in(pfx);
	goRightRate = 18;
	goright();
}
function arrow_left_mouseup(elm){
	elm.style.background = '#13273A';
	clearInterval( xtimer );
}
function goright(){
	divContent = fix_obj[on_obj][1] ;
	divContentHolder = fix_obj[on_obj][2] ; 
	pxx = fix_obj[on_obj][3] ; 
			 
	if( pxx< 0 ){
		pxx += goRightRate ;		
		if(pxx >=  0 ) pxx = 0 ;
		divContent.style.left = pxx+ 'px';
		goRightRate = Math.floor( Math.min( goRightRate * 1.5, divContentHolder.offsetWidth/2) );
	}
	fix_obj[on_obj][3] = pxx ;
	if( pxx>= 0 ){
		document.getElementById(xcontentPrefix +'-arrow-left').style.background = '#13273A';
		clearInterval( xtimer );
	}
}


/////////////////////////
function expand_mouse_over(el){
	el.style.background = '#FF5B00';
}
function expand_mouse_out(el){
	el.style.background = '#919191';
}
///////////////////////////////