if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
{
  var tn_w = 50;
  var tn_h = 50;
}

// global variables used while dragging
var IE = document.all ? true : false;
var is_op = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1)) ? true : false;
var is_old = (navigator.userAgent.indexOf('MSIE 5') != -1) ? true : false;
var selectedObj;

var offsetX;
var offsetY;
var version = clientVer;

var image_w;
var image_h;
var linkmake = '';

var tn_w_min;
var tn_h_min;

var anchor_w;
var anchor_h;

var keep_proportions = true;

var coord_delta = 0;
var bounds_delta = (is_ie) ? 0 : 2;
var x_divcorr=0;
var y_divcorr=0;

var main_bg_color = '#ddd';

/*
var is_lt_moved = false;
var is_rt_moved = false;
var is_lb_moved = false;
var is_rb_moved = false;
*/

var detect = navigator.userAgent.toLowerCase();

if (!is_ie) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN);
addEvent(document, "mouseup", release);

function checkIt(string)
{
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}

if (checkIt('konqueror'))
{
  browser = "Konqueror";
  OS = "Linux";
}
else if (checkIt('safari')) { browser = "Safari"; }
else if (checkIt('omniweb')) { browser = "OmniWeb"; }
else if (checkIt('opera')) { browser = "Opera"; }
else if (checkIt('webtv')) { browser = "WebTV"; }
else if (checkIt('icab')) { browser = "iCab"; }
else if (checkIt('msie')) { browser = "Internet Explorer"; }
else if (!checkIt('compatible'))
{
  browser = "Netscape Navigator";
  version = detect.charAt(8);
}
else { browser = "unknown"; }


// positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y)
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  if (x < 0 + x_divcorr) x = 0+x_divcorr; else
  if (x > image_w - _px(obj.style.width) - bounds_delta + x_divcorr) x = image_w - _px(obj.style.width) - bounds_delta+x_divcorr;

  if (y < 0+y_divcorr) y = 0+y_divcorr; else
  if (y > image_h - _px(obj.style.height) - bounds_delta+y_divcorr) y = image_h - _px(obj.style.height) - bounds_delta+y_divcorr;

  //
//  x+=offcetTop

  obj.style.left = x+"px";
  obj.style.top = y+"px";

  move_anchors();
}

function resize_at_rb(obj, x, y)
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

    //niz pravo - _px(obj.style.left) +x_divcorr
  if (x < _px(obj.style.left) + tn_w_min) x = _px(obj.style.left) + tn_w_min; else
  if (x >= image_w - bounds_delta+x_divcorr) x = image_w - bounds_delta+x_divcorr;

  // _px(obj.style.top) +
  if (y < _px(obj.style.top) + tn_h_min) y = _px(obj.style.top) + tn_h_min; else
  if (y >= image_h - bounds_delta + y_divcorr) y = image_h - bounds_delta + y_divcorr;

  x -= _px(obj.style.left);
  y -= _px(obj.style.top);


  if (keep_proportions==true)
  {
    var cur_by_standard = (x / y) / tn_x_by_y;

    if (cur_by_standard > 1) x = Math.ceil(x / cur_by_standard); else
    if (cur_by_standard < 1) y = Math.ceil(y * cur_by_standard);
  }

    if (x<tn_w)x=tn_w;
    if (y<tn_h)y=tn_h;

  obj.style.width = x+"px";
  obj.style.height = y+"px";

  move_anchors();

}

function resize_at_rt(obj, x, y)
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

//  _ge("dump").innerHTML += " x0="+x;

  if (x < _px(obj.style.left) + tn_w_min+x_divcorr) x = _px(obj.style.left) + tn_w_min+x_divcorr; else
  if (x >= image_w - bounds_delta+x_divcorr) x = image_w - bounds_delta+x_divcorr;

//  _ge("dump").innerHTML += " x="+x+" ";

  if (y < 0+y_divcorr) y = 0+y_divcorr; else
  if (y > _px(obj.style.top) + _px(obj.style.height) - tn_h_min+y_divcorr) y = _px(obj.style.top) + _px(obj.style.height) - tn_h_min+y_divcorr;

  tmp_x = x - _px(obj.style.left);
  tmp_y = _px(obj.style.height) + _px(obj.style.top) - y;


  if (keep_proportions==true)
  {
    var old_tmp_y = tmp_y;

    var cur_by_standard = (tmp_x / tmp_y) / tn_x_by_y;

    if (cur_by_standard > 1) tmp_x = Math.ceil(tmp_x / cur_by_standard); else
    if (cur_by_standard < 1) { tmp_y = Math.ceil(tmp_y * cur_by_standard); y += old_tmp_y - tmp_y; }

  }


  if (tmp_x<tn_w)tmp_x=tn_w;
  if (tmp_y<tn_h){
    y-=tn_h-tmp_y;
    tmp_y=tn_h;
    }
  obj.style.top = y+"px";
  obj.style.width = tmp_x+"px";
  obj.style.height = tmp_y+"px";



  move_anchors();
}

function resize_at_lb(obj, x, y)
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  if (x < 0+x_divcorr) x = 0+x_divcorr; else
  if (x > _px(obj.style.left) + _px(obj.style.width) - tn_w_min+x_divcorr) x = _px(obj.style.left) + _px(obj.style.width) - tn_w_min+x_divcorr;

  if (y < _px(obj.style.top) + tn_h_min+y_divcorr) y = _px(obj.style.top) + tn_h_min+y_divcorr; else
  if (y >= image_h - bounds_delta+y_divcorr) y = image_h - bounds_delta + y_divcorr;

  tmp_x = _px(obj.style.width) + _px(obj.style.left) - x;
  tmp_y = y - _px(obj.style.top);


  if (keep_proportions==true)
  {
    var old_tmp_x = tmp_x;

    var cur_by_standard = (tmp_x / tmp_y) / tn_x_by_y;

    if (cur_by_standard > 1) { tmp_x = Math.ceil(tmp_x / cur_by_standard); x += old_tmp_x - tmp_x; } else
    if (cur_by_standard < 1) tmp_y = Math.ceil(tmp_y * cur_by_standard);
  }

  if (tmp_x<tn_w){
    x-=tn_w-tmp_x;
    tmp_x=tn_w;}
  if (tmp_y<tn_h){

    tmp_y=tn_h;
    }

  obj.style.width = tmp_x+"px";
  obj.style.height = tmp_y+"px";

  obj.style.left = x+"px";

  move_anchors();
}

function resize_at_lt(obj, x, y)
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  if (x < 0+x_divcorr) {x = 0+x_divcorr;} else
  if (x > _px(obj.style.left) + _px(obj.style.width) - tn_w_min+x_divcorr) x = _px(obj.style.left) + _px(obj.style.width) - tn_w_min+x_divcorr;

  if (y < 0+y_divcorr) {y = 0+y_divcorr;} else
  if (y > _px(obj.style.top) + _px(obj.style.height) - tn_h_min+y_divcorr) y = _px(obj.style.top) + _px(obj.style.height) - tn_h_min+y_divcorr;

  tmp_x = _px(obj.style.width) + _px(obj.style.left) - x;
  tmp_y = _px(obj.style.height) + _px(obj.style.top) - y;

  if (keep_proportions==true)
  {
    var old_tmp_x = tmp_x;
    var old_tmp_y = tmp_y;

    var cur_by_standard = (tmp_x / tmp_y) / tn_x_by_y;

    if (cur_by_standard > 1) { tmp_x = Math.ceil(tmp_x / cur_by_standard); x += old_tmp_x - tmp_x; } else
    if (cur_by_standard < 1) { tmp_y = Math.ceil(tmp_y * cur_by_standard); y += old_tmp_y - tmp_y; }
  }

  if (tmp_x<tn_w){
    x-=tn_w-tmp_x;
    tmp_x=tn_w;}
  if (tmp_y<tn_h){
    y-=tn_h-tmp_y;
    tmp_y=tn_h;
    }


  obj.style.width = tmp_x+"px";
  obj.style.height = tmp_y+"px";

  obj.style.left = x+"px";
  obj.style.top = y+"px";

  move_anchors();
}

// set global var to a reference to dragged element
function setSelectedObj(e)
{
  if (e)
  {
    var onObj = e.target;
  }
  else
  {
    e = window.event;
    var onObj = e.srcElement;
  }

  //e = e || window.event;
  //var onObj = e.target || e.srcElement;

  if (
      //onObj.id == "jwindow2_title_all1" || onObj.id == "jwindow2_title_all2" || onObj.id == "jwindow_title_all2" || onObj.id == "jwindow_title_all1" ||
      onObj.id == "tn_area1" || onObj.id == "tn_area" || onObj.id == "left_top" || onObj.id == "left_bottom" ||
      onObj.id == "right_top" || onObj.id == "right_bottom"
     )
  {
    selectedObj = onObj;
    return;
  }

  selectedObj = null;

  return;
}

// do the dragging (called repeatedly by onMouseMove)
function dragIt(e)
{
  if (e)
  {
    var event = e;
  }
  else
  {
    var event = window.event;
  }

  if (selectedObj)
  {
    switch (selectedObj.id)
    {
      case "tn_area":
        shiftTo(E.tn_area, event.clientX -   offsetX, event.clientY  - offsetY);
        break;
      case "tn_area1":
        shiftTo(E.tn_area, event.clientX -   offsetX, event.clientY  - offsetY);
        break;
      case "left_top":
        resize_at_lt(E.tn_area, event.clientX - offsetX, event.clientY   - offsetY);
        break;
      case "left_bottom":
        resize_at_lb(E.tn_area, event.clientX - offsetX, event.clientY   - offsetY + anchor_h);
        break;
      case "right_top":
        resize_at_rt(E.tn_area, event.clientX - offsetX + anchor_w, event.clientY   - offsetY);
        break;
      case "right_bottom":
        resize_at_rb(E.tn_area, event.clientX -  offsetX + anchor_w, event.clientY   - offsetY + anchor_h);
        break;
    }

    return false;
  }
}

// set global vars and turn on mousemove trapping (called by onMouseDown)
function engage2(e)
{
  setSelectedObj(e);

  image_w = document.getElementById('map').offsetWidth;
  image_h = document.getElementById('map').offsetHeight;

  if (is_ie || is_op)
  {
    var _tmp1 = window.event.offsetX;
    var _tmp2 = window.event.offsetY;
  }
  else
  {
    var _tmp1 = e.layerX; //e.pageX
    var _tmp2 = e.layerY; //e.pageY
  }

  if (selectedObj)
  {
    E.tn_img.src = '/i/z.gif';

    addEvent(document, "mousemove", dragIt);

    if (selectedObj.id == 'jwindow_title_all1' || selectedObj.id == 'jwindow_title_all2'  || selectedObj.id == 'jwindow2_title_all1'  || selectedObj.id == 'jwindow2_title_all2')
    {
      addEvent(_ge(selectedObj.id), "mousemove", dragIt);
    }
    else
    {
      addEvent(E.left_top, "mousemove", dragIt);
      addEvent(E.left_bottom, "mousemove", dragIt);
      addEvent(E.right_top, "mousemove", dragIt);
      addEvent(E.right_bottom, "mousemove", dragIt);
    }

    offsetX = _tmp1 - document.body.scrollLeft;
    offsetY = _tmp2 - document.body.scrollTop;
  }

  if (!is_ie && e.preventDefault) e.preventDefault();
  return false;
}

// restore everything as before (called by onMouseUp)
function release(e)
{
  if (selectedObj)
  {
    E.tn_img.src = '/i/z.gif';

    document.onmousemove = null;
    selectedObj = null;

    make_tn(E.tn_area);
  }

  return true;
}

function make_tn(previewObj, doit)
{
  //return;

  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  var x = _px(previewObj.style.left)-x_divcorr;
  var y = _px(previewObj.style.top)-y_divcorr;
  var w = _px(previewObj.style.width);
  var h = _px(previewObj.style.height);
  //alert(x+' '+y+' '+w+' '+h);

  var w1=E.map.offsetWidth;
  var h1=E.map.offsetHeight;

  var aleft= Math.floor(getAbsLeft(E.thepreview)-x*tn_h/h-1);
  var atop= Math.floor(getAbsTop(E.thepreview)-y*tn_w/w-1);

  if (x==0) aleft = Math.floor(getAbsLeft(E.thepreview)-x-1);
  if (y==0) atop = Math.floor(getAbsTop(E.thepreview)-y-1);

  var theheight = Math.ceil(tn_h/h*h1);
  var thewidth = Math.ceil(tn_w/w*w1);

  if (getAbsLeft(E.thepreview)+E.thepreview.offsetWidth>=aleft+thewidth) thewidth++;
  if (getAbsTop(E.thepreview)+E.thepreview.offsetHeight>=atop+theheight) theheight++;

  _ge('previm').style.width  = thewidth+'px';
  _ge('previm').style.height  = 'auto';
  _ge('previm').style.top  = atop+'px';
  _ge('previm').style.left  = aleft+'px';

  _ge('previm').style.display  = 'block';

  var da_url = '/make_tn.php?'+'avatar_src='+escape(avatar_src)+'&x='+x+'&y='+y+'&w='+w+'&h='+h+'&usm=3';

  if (typeof doit != 'undefined')
  {
    window.location = da_url+'&save=1';
  }
  else if (!selectedObj)
  {
    E.tn_img.src = da_url;
  }
}

function move_anchors(fromt)
{
  //jwindow and borders check
  bwidth = document.getElementById('map').offsetWidth;
  bheight = document.getElementById('map').offsetHeight;
  var add_line_corr=0;

  if (is_op && version!=9) coord_delta=2;

  E.left_top.style.left =  _px(E.tn_area.style.left) + "px";
  E.left_top.style.top =  _px(E.tn_area.style.top) + "px";

  if (_px(E.tn_area.style.top)<(25+add_line_corr) && image_h-(20+add_line_corr)<_px(E.tn_area.style.top)+_px(E.tn_area.style.height))
  {
    // _ge("add_line").style.top =  (_px(E.tn_area.style.top)+5) + "px";
    // _ge("add_line").style.left =  (_px(E.tn_area.style.left)+5) + "px";
  }
  else if (_px(E.tn_area.style.top)>(25+add_line_corr))
  {
    // _ge("add_line").style.top =  (_px(E.tn_area.style.top)-(20+add_line_corr)) + "px";
  }
  else
  {
    // _ge("add_line").style.top =  (_px(E.tn_area.style.top)+_px(E.tn_area.style.height)+4) + "px";
  }

  E.right_top.style.left = ( _px(E.tn_area.style.left) + _px(E.tn_area.style.width) - anchor_w  - coord_delta ) + "px";
  E.right_top.style.top = _px(E.tn_area.style.top) + "px";

  E.left_bottom.style.left =  _px(E.tn_area.style.left) + "px";
  E.left_bottom.style.top = ( _px(E.tn_area.style.top) + _px(E.tn_area.style.height) - anchor_h  - coord_delta) + "px";

  E.right_bottom.style.left = ( _px(E.tn_area.style.left) + _px(E.tn_area.style.width) - anchor_w  - coord_delta ) + "px";
  E.right_bottom.style.top = ( _px(E.tn_area.style.top) + _px(E.tn_area.style.height) - anchor_h  - coord_delta ) + "px";

  make_tn(E.tn_area);
}

function cancel_fastblock()
{
  E.tn_area.style.display = 'none';
  _ge("add_line").style.display = 'none';
  E.left_top.style.display = 'none';
  E.right_top.style.display = 'none';
  E.left_bottom.style.display = 'none';
  E.right_bottom.style.display = 'none';
  if (adding_block!=3) adding_block=2;
  if (makingurl==1)
  {
    _ge("add_line").className='add_line';
    _ge("add_line").innerHTML=addblmen;
    makingurl=0;
    tn_w_min = 21;
    tn_h_min = 21;
    center_block();
  }

  if (edit_block_id > 0)
  {
    edit_block_id=0;
    center_block();
  }

  if (tagfilter_mem!='')
  {
    zfile=0;
    tagfilter=tagfilter_mem;
    tagfilter_mem='';
    update_objects('refresh');
    update_uri();
  }
}

//functions ******************************************************************************************************


function load_add(type)
{
  if (!_ge('map')) return;

  E = {map: _ge('map')}

  x_divcorr=getAbsLeft(E.map);
  y_divcorr=getAbsTop(E.map);

  adding_block=1;
  offsetX = 100;
  offsetY = 100;

  var tooltipObject = document.createElement("div");
  tooltipObject.style.zIndex = 2000;

  var inclu='';
  if (browser == "Internet Explorer")
  {
    //inclu='<img src="/blank.gif" width="100%" height="100%" id="tn_area1" name="tn_area1">';
    inclu='<div name="tn_area1" id="tn_area1" style="overflow: hidden;FILTER: alpha(opacity=0); BACKGROUND-COLOR: #fff; width:100%;height:100%;"></div>';
  }
  else if (is_op)
  {
    inclu='<div name="tn_area1" id="tn_area1" style="overflow: hidden;width:100%;height:100%;"><!-- --></div>';
  }

  tooltipObject.innerHTML = '<div id="tn_area" name="tn_area">'+inclu+'</div>';

  document.body.appendChild(tooltipObject);

  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML = '<div style="overflow: hidden;BACKGROUND-COLOR: white; " id="left_top"></div>';
  document.body.appendChild(tooltipObject);
  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML = '<div style="overflow: hidden;BACKGROUND-COLOR: white; " id="left_bottom"></div>';
  document.body.appendChild(tooltipObject);
  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML = '<div style="overflow: hidden;BACKGROUND-COLOR: white; " id="right_top"></div>';
  document.body.appendChild(tooltipObject);
  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML = '<div style="overflow: hidden;BACKGROUND-COLOR: white; " id="right_bottom"></div>';
  document.body.appendChild(tooltipObject);

  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  var tn_img1 = document.createElement("img");
  tn_img1.id = 'tn_img';
  tn_img1.src = '/i/z.gif';
  tn_img1.alt = '';
  tn_img1.style.borderWidth = 0;
  tn_img1.style.position = 'relative';
  tn_img1.style.left = '-1px';
  tn_img1.style.top = '-1px';
  tn_img1.style.width = tn_w+'px';
  tn_img1.style.height = tn_h+'px';

  E = {
map: _ge('map'),
tn_area: _ge('tn_area'),
tn_area1: _ge('tn_area1'),
left_top: _ge('left_top'),
left_bottom: _ge('left_bottom'),
right_top: _ge('right_top'),
right_bottom: _ge('right_bottom'),
thepreview: _ge('thepreview'),
tn_img: tn_img1
}

  E.thepreview.appendChild(E.tn_img);

  addblmen='';

  linkmake = '';

  E.thepreview.style.width=(tn_w-2)+"px";
  E.thepreview.style.height=(tn_h-2)+"px";

  var image_w_ = document.body.offsetWidth;
  var image_h_ = document.body.clientHeight;

  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML  = '<div></div>';
  tooltipObject.id  = 'clr1';
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.zIndex  = 20;
  tooltipObject.style.width=getAbsLeft(E.thepreview)-2;
  tooltipObject.style.height=(image_h_)+"px";
  tooltipObject.style.top="0px";
  tooltipObject.style.background=main_bg_color;
  tooltipObject.style.left="0px";
  //tooltipObject.style.overflow="hidden";
  //tooltipObject.style.border="solid 1px #499";
  document.body.appendChild(tooltipObject);

  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML  = '<div></div>';
  tooltipObject.style.width=(image_w_-getAbsLeft(E.thepreview)+500)+"px";
  tooltipObject.style.top="0px";
  tooltipObject.id  = 'clr2';
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.height=(image_h_)+"px";
  tooltipObject.style.background=main_bg_color;
  tooltipObject.style.zIndex  = 20;
  tooltipObject.style.left=(getAbsLeft(E.thepreview)+tn_w)+"px";
  //tooltipObject.style.border="solid 1px #000";
  //tooltipObject.style.overflow="none";
  document.body.appendChild(tooltipObject);

  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML  = '<div></div>';
  tooltipObject.id  = 'clr3';
  tooltipObject.style.width=(image_w_+500)+"px";
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.top="0px";
  tooltipObject.style.left="0px";
  tooltipObject.style.zIndex  = 20;
  tooltipObject.style.background=main_bg_color;
  tooltipObject.style.height=getAbsTop(E.thepreview)-2+"px";
  document.body.appendChild(tooltipObject);

  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML  = '<div></div>';
  tooltipObject.style.left="0px";
  tooltipObject.style.top=(getAbsTop(E.thepreview)+tn_h)+"px";
  tooltipObject.id  = 'clr4';
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.zIndex  = 20;
  tooltipObject.style.background=main_bg_color;
  tooltipObject.style.width=(image_w_+600)+"px";
  tooltipObject.style.height=(image_h_-getAbsTop(E.thepreview)+500)+"px";
  //tooltipObject.style.border="solid 1px #000";
  document.body.appendChild(tooltipObject);


  var tooltipObject = document.createElement("img");
  tooltipObject.src  = E.map.src;
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.top  = '10px';
  tooltipObject.style.left  = '10px';
  tooltipObject.style.display  = 'none';
  tooltipObject.style.zIndex  = 10;
  tooltipObject.id  = 'previm';
  document.body.appendChild(tooltipObject);



  var tooltipObject = document.createElement("div");
  tooltipObject.innerHTML  = '<div style="overflow: hidden;"><table border=0 width="100%" height="100%"><tr><td></td></tr></table></div>';
  tooltipObject.id  = 'clr0';
  tooltipObject.style.position  = 'absolute';
  tooltipObject.style.zIndex  = 251;
  tooltipObject.style.width=E.map.offsetWidth+"px";
  tooltipObject.style.height=E.map.offsetHeight+"px";
  tooltipObject.style.top=y_divcorr+"px";
  //tooltipObject.style.background="#fff";
  tooltipObject.style.left=x_divcorr+"px";
  //tooltipObject.style.overflow="hidden";
  //tooltipObject.style.border="solid 1px #499";
  document.body.appendChild(tooltipObject);

  tn_w_min = tn_w;
  tn_h_min = tn_h;

  anchor_w = 10;
  anchor_h = 10;

  //var keep_proportions = true;
  tn_x_by_y = tn_w/tn_h;

  E.left_top.style.width = anchor_w+"px";
  E.left_top.style.height = anchor_h+"px";

  E.right_top.style.width = anchor_w+"px";
  E.right_top.style.height = anchor_h+"px";

  E.left_bottom.style.width = anchor_w+"px";
  E.left_bottom.style.height = anchor_h+"px";

  E.right_bottom.style.width = anchor_w+"px";
  E.right_bottom.style.height = anchor_h+"px";

  center_block();
  move_anchors();

  addEvent(E.tn_area, "mousedown", engage2);
  addEvent(E.tn_area, "mouseup", release);

  if (is_ie) addEvent(E.tn_area1, "mousedown", engage2);
  if (is_ie) addEvent(E.tn_area1, "mouseup", release);

  addEvent(E.left_top, "mousedown", engage2);
  addEvent(E.left_top, "mouseup", release);

  addEvent(E.right_top, "mousedown", engage2);
  addEvent(E.right_top, "mouseup", release);

  addEvent(E.left_bottom, "mousedown", engage2);
  addEvent(E.left_bottom, "mouseup", release);

  addEvent(E.right_bottom, "mousedown", engage2);
  addEvent(E.right_bottom, "mouseup", release);

  //deleted
  // addEvent(document, "mouseup", release);

  make_tn(E.tn_area);
}

function center_block()
{
  if (typeof tn_w == 'undefined' || typeof tn_h == 'undefined' || !tn_w || !tn_h)
  {
    var tn_w = 50;
    var tn_h = 50;
  }

  image_w = E.map.offsetWidth;
  image_h = E.map.offsetHeight;
  var image_s_left=x_divcorr;
  var image_s_top=y_divcorr;
  var image_s_w=tn_w;
  var image_s_h=tn_h;

  while (image_s_w<image_w && image_s_h<image_h)
  {
    image_s_w++;
    image_s_h=Math.floor(image_s_w*tn_h/tn_w);
  }

  if (image_s_h>image_h)
  {
    image_s_h=image_h;
    image_s_w=Math.floor(image_s_h*tn_w/tn_h);
  }
  else if (image_s_w>image_w)
  {
    image_s_w=image_w;
    image_s_h=Math.floor(image_s_w*tn_h/tn_w);
  }

  if (image_w-image_s_w>1)
  {
    image_s_left+=Math.floor((image_w-image_s_w)/2);
  }
  else if (image_h-image_s_h>1)
  {
    image_s_top+=Math.floor((image_h-image_s_h)/2);
  }

  //setting default settings
  E.tn_area.style.left = image_s_left+"px";
  E.tn_area.style.top = image_s_top+"px";
  E.tn_area.style.width = image_s_w-bounds_delta+"px";
  E.tn_area.style.height = image_s_h-bounds_delta+"px";
}


// Get and set positions
function getAbsLeft(o)
{
     oLeft = o.offsetLeft;
     while(o.offsetParent!=null) {
          oParent = o.offsetParent;
          oLeft += oParent.offsetLeft;
//          oLeft -= oLeft
          o = oParent;
     }
     return oLeft;
}
function getAbsTop(o) {
     oTop = o.offsetTop;
     while(o.offsetParent!=null) {
          oParent = o.offsetParent;
          oTop += oParent.offsetTop;
          o = oParent;
     }
     return oTop;
}
