// JavaScript Document

var cur_length=0;

var if_stop=false;
var hint_txt = 'click to pause';
var need_hint=false;

var in_block=0;
var no_hide=false;

var x_pos_type=5; //default; x=-80 - right side; 
var y_pos_type=20; //default; y=-25 - bottom side;



var IE = document.all?true:false


if (!IE) document.captureEvents(Event.MOUSEMOVE)


document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0


// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
	var main_left=document.getElementById('main_box').offsetLeft-50;
	var main_top=document.getElementById('main_box').offsetTop;
	var main_width=document.getElementById('main_box').offsetWidth+100;
	var main_height=document.getElementById('main_box').offsetHeight;
		
		
		new_in_block=checkPos();
		
		if(in_block!=new_in_block){
		  //alert(new_in_block)
			if(new_in_block==0){
				hideHint();
				no_hide=true;
			}else{
				if(no_hide)
				clearTimeout(hintTimer);
				showHint();
			}
			in_block=new_in_block;
		}
		
		
		
		
	if((tempX>main_left)&&(tempX<main_left+main_width)&&(tempY>main_top)&&(tempY<main_top+main_height)){
		var box_left=document.getElementById('show_box').offsetLeft;
		var box_width=document.getElementById('show_box').offsetWidth;
		var box_middle=box_left+box_width/2;
		cur_length=box_middle-tempX;
		//window.status='in box';
	}else{
		//window.status='out of box';
	}
 	theObj=document.getElementById('hint_div');
	if(need_hint){
		theObj.style.left=tempX+x_pos_type+'px';
		theObj.style.top=tempY+y_pos_type+'px';
		theObj.style.display='';
	}else{
		theObj.style.display='none';
	} 
//	if(tempX<=box_middle) msg='LEFT SIDE'; else msg='RIGHT SIDE';

 // document.getElementById('show_box').innerHTML =msg+"::"+cur_length+"::"+tempX
  return true
}

function showHint(){
	need_hint=true;
	no_hide=true;
	document.getElementById('hint_div').innerHTML=hint_txt;
	hintTimer=setTimeout("hideHint()",4000);
/* 	document.getElementById('hint_div').style.display='block';
	document.getElementById('hint_div').style.left=tempX+x_pos_type+'px';
	document.getElementById('hint_div').style.top=tempY+y_pos_type+'px'; */
	
//	window.setTimeout('hintTimerF()',10);
}




 function hideHint(){
 	need_hint=false;
	document.getElementById('hint_div').style.display='none';
}

function doHideHint(){
	if(!was_over){
		need_hint=false;
		no_hint=false;
	}
} 

function dodoHideHint(){
	need_hint=false;
	//no_hint=true;
	document.getElementById('hint_div').style.display='none';
}


function checkPos(){
	var box_left=document.getElementById('show_box').offsetLeft;
	var box_width=document.getElementById('show_box').offsetWidth;
	var box_top=document.getElementById('show_box').offsetTop;
	var box_height=document.getElementById('show_box').offsetHeight;

	if((tempX>box_left)&&(tempX<box_left+box_width)){
		if((tempY>box_top)&&(tempY<box_top+box_height)){
//			if(cur_length<-275)
			if(tempX>box_left+box_width-90)
				x_pos_type=-80; else x_pos_type=5;
			if(tempY>box_top+box_height-40)
				y_pos_type=-25; else y_pos_type=20;
	//	alert(cur_length);
//	alert(tempX);
//			document.getElementById('trace_box').innerHTML='1';
			return 1;
		}		
	}
//document.getElementById('trace_box').innerHTML='0';

return 0;	
}




function scrollFrame(){

	if(if_stop) return true;
	
	cur_length=parseInt(cur_length);
	//var frame_left=document.getElementById('img_frame').offsetLeft;
	var frame_width=document.getElementById('img_frame').offsetWidth;
	
	var box_left=document.getElementById('show_box').offsetLeft;
	var box_width=document.getElementById('show_box').offsetWidth;
	var box_top=document.getElementById('show_box').offsetTop;
	var box_height=document.getElementById('show_box').offsetHeight;
	
	var frameX=parseInt(document.getElementById('img_frame').style.left);
	

	
	if(frame_width<box_width) return true;
	
	
	//left
	if((cur_length>0)&&(frameX+cur_length/10>=0)){
//		if(cur_length<20) alert(tempY);
		frameX=0;
		document.getElementById('img_frame').style.left=frameX+'px';
		setTimeout("scrollFrame()",100);
//showHint();
		return true;
	}
	//if(box_width+frame_width>box_left+box_width){frameX=frame_width-500;}
	
	//right
	if((cur_length<0)&&(frameX<=0-frame_width+box_width-cur_length/10)){
		frameX=0-frame_width+box_width;
		document.getElementById('img_frame').style.left=frameX+'px';
		setTimeout("scrollFrame()",100);
		return true;
	}

	//document.getElementById('trace_box').innerHTML=frameX+'::'+frame_width+'::'+cur_length;

	document.getElementById('img_frame').style.left=frameX+(cur_length/10)+'px';
	setTimeout("scrollFrame()",100);
}
	

function setStop(){
	if_stop=!if_stop;
	if(if_stop)hint_txt = 'click to resume';else hint_txt = 'click to pause';
//	no_hint=false;
	showHint();
}
function useLink(){
	return if_stop?false:true;
}



/*
function findPos(obj) {

	var curleft = curtop = 0;

	if (obj.offsetParent) {

		curleft = obj.offsetLeft

		curtop = obj.offsetTop

		while (obj = obj.offsetParent) {

			curleft += obj.offsetLeft

			curtop += obj.offsetTop

		}

	}
	
	return curleft;
	//return [curleft,curtop];

}
*/



