

onresize=Set_Resize;
var zooming,insideMap= false;

var Map_X =0
var Map_Y =0
var z_index=100;

var boxLineWidth=1;
var zoomColor= '#ff0000';

var windowX =0;
var windowY =0;

function setEvents(){
	if (isNav)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEUP);
		document.onmousemove = getMouse();
		document.onmouseup =msStop;
	}
	if (isIE || isOp || isFF || isMoz) {
		document.onmousemove = getMouse;
		document.onmouseup = msStop;
	}
}

function clipLayer(name, clipleft, cliptop, clipright, clipbottom){
	var layer = getLayer(name);
	if (isIE || isFF || isMoz || isOp) {
		layer.clip='rect('+cliptop+' '+clipright+' '+clipbottom+' '+clipleft+')';
	}
	if (isNav){
		layer.clip.left   = clipleft;
		layer.clip.top    = cliptop;
		layer.clip.right  = clipright;
		layer.clip.bottom = clipbottom;
	}
}

function setClip()
{
  var tempX=startX;
  var tempY=startY;

  if (startX>x2) 
  {
    zright=startX;
    zleft=x2;
  } else {
    zleft=startX;
    zright=x2;
  }

  if (startY>y2) 
  {
    zbottom=startY;
    ztop=y2;
  } else {
    ztop=startY;
    zbottom=y2;
  }
	
  if ((startX != x2) && (startY != y2)) 
  {
    var ovBoxSize = boxLineWidth;

   clipLayer('BoxTop',zleft,ztop,zright,ztop+ovBoxSize);
   clipLayer('BoxLeft',zleft,ztop,zleft+ovBoxSize,zbottom);
   clipLayer('BoxRight',zright-ovBoxSize,ztop,zright,zbottom);
   clipLayer('BoxBottom',zleft,zbottom-ovBoxSize,zright,zbottom);
   }
}

function msBegin(e){
	insideMap =1;
	startBox(e);
	visibl_hint(0);
	set_show('BoxTop',1);
	set_show('BoxLeft',1);
	set_show('BoxRight',1);
	set_show('BoxBottom',1);
	return false;
}

function msStop(){
	if (insideMap){
 		Viewreg_param();
 		set_show('BoxTop',0);
 		set_show('BoxLeft',0);
 		set_show('BoxRight',0);
 		set_show('BoxBottom',0);
 		insideMap=0;
 	}
}

function Viewreg_param(){
 x1=Math.min(startX,x2);
 x2=Math.max(startX,x2);

 y1=Math.min(startY,y2);
 y2=Math.max(startY,y2);

 if(x1<0) x1=0;
 if(y1<0) y1=0;

 if(x2>Map_Width) x2=Map_Width;
 if(y2>Map_Height) y2=Map_Height;

 if ((x2-x1>5) && (y2-y1>5))
 {
 w_cmd=tool_cmd;
 w_cmd_param=x1+','+y1+';'+x2+','+y2;
 }
 else
 {
 w_cmd=3;
 w_cmd_param ='0&uamap_x='+x1+'&uamap_y='+y1;
 }
 req_new();
}

function getMouse(e){
	if (isIE) getImageXY(event);
	if (isNav) getImageXY(e);
	if (isFF || isMoz || isOp) getImageXY(e);
	if (zooming){
		if (mouseX<0) mouseX = 0;
		if (mouseX>Map_Width) mouseX = Map_Width;
		if (mouseY<0) mouseY = 0;
		if (mouseY>Map_Height)mouseY = Map_Height;
		x2 = mouseX;
		y2 = mouseY;
		setClip();
		return false;
	}
	return true;
}

function getImageXY(e){
	if (isIE) {
		windowX = e.clientX + document.body.scrollLeft;
		windowY = e.clientY + document.body.scrollTop;
	}
	if (isNav) {
		windowX=e.pageX;
		windowY=e.pageY;
	}
	if (isFF || isMoz || isOp) {
		windowX = e.clientX + document.body.scrollLeft;
		windowY = e.clientY + document.body.scrollTop;
	}
	mouseX = x2 = windowX-Map_X;
	mouseY = y2 = windowY-Map_Y;
}


function Set_Resize(){
 (isIE || isFF || isMoz || isOp)?mapPospage():set_mapsize(index_img_size,1);
}

function addZoombox() 
{
 createLayer('BoxTop',zoomColor);
 createLayer('BoxLeft',zoomColor);
 createLayer('BoxRight',zoomColor);
 createLayer('BoxBottom',zoomColor);

// mapPospage();
// setEvents();
}

function startBox(e) {
	if (insideMap) {
		getImageXY(e);
		startX=mouseX;
		startY=mouseY;
		x2=startX++;
		y2=startY++;
		clipLayer('BoxTop',startX,startY,x2,y2);
		clipLayer('BoxLeft',startX,startY,x2,y2);
		clipLayer('BoxRight',startX,startY,x2,y2);
		clipLayer('BoxBottom',startX,startY,x2,y2);
		clipLayer('BoxBottom',startX,startY,x2,y2);
		zooming=true;
	}
}

