
var NN_4=(document.layers)?1 : 0;
var IE=(document.all)?1 : 0;
var NN_6=(!document.all&&document.getElementById)?1 : 0;
var VISIBLE=NN_4?"show" : "visible";
var HIDDEN=NN_4?"hide" : "hidden";
var DISPLAY_ON="block";
var DISPLAY_OFF="none";
var LAYER__IS_NETSCAPE=(navigator.appName.indexOf("Explorer")==-1);
var LAYER__NETSCAPE_TIME_PATCH_COEFFICIENT=NN_4?0 : 0;
var inited_mouse_actions=false;
var LAYERS_HASH={};
var old_mouse_pos=new Object();
old_mouse_pos.left=0;
old_mouse_pos.top=0;
var allow_default_dragging=false;
var default_mousedown=null;
var default_mousemove=null;
var default_mouseup=null;
function Layer(layer_name)
{
NN_4=(document.layers)?1 : 0;
 IE=(document.all)?1 : 0;
 NN_6=(!document.all&&document.getElementById)?1 : 0;
if(typeof(LAYERS_HASH)=='undefined')
 LAYERS_HASH=new Array();
this.LayerName=layer_name;
 this.Layer=Layer__GetLayerObj(layer_name);
 this.LayerStyle=Layer__GetLayerObjStyle(layer_name);
 this.Draggable=false;
if(typeof(this.Layer)=='undefined'||typeof(this.LayerStyle)=='undefined'){
 this.Success=false;
 return null;
}
this.SetPosition=Layer__SetLayerPosition;
 this.GetPosition=Layer__GetLayerPosition;
 this.SetVisible=Layer__SetLayerVisible;
 this.IsVisible=Layer__IsLayerVisible;
 this.SetDisplay=Layer__SetLayerDisplay;
 this.Move=Layer__Move;
 this.GetDimentions=IE||NN_6?Layer__GetLayerDimentions : Layer__GetLayerDimentions_NN;
 this.SetDimentions=IE||NN_6?Layer__SetLayerDimentions : Layer__SetLayerDimentions_NN;
 this.HTML=IE||NN_6?Layer__HTML : Layer__HTML_NN;
 this.DocumentMargins=IE||NN_6?Layer__GetDocumentMargins : Layer__GetDocumentMargins_NN;
 this.Document=IE?document :(NN_6?document : this.Layer.document);
 this.InitDrag=Layer__InitDrag;
 this.ReleaseDrag=Layer__ReleaseDrag;
this.Maximize=Layer__Maximize;
 this.Center=Layer__Center;
this.DocumentMargins();
LAYERS_HASH[this.LayerName]=this;
this.Success=true;
return this;
}
function Layer__DefaultDragging(func_handler_mousedown,
 func_handler_mousemove,
 func_handler_mouseup)
{
 default_mousedown=func_handler_mousedown;
 default_mousemove=func_handler_mousemove;
 default_mouseup=func_handler_mouseup;
allow_default_dragging=true;
}
function Layer__AllowDefaultDragging()
{
 allow_default_dragging=true;
}
function Layer__ForbidDefaultDragging()
{
 allow_default_dragging=false;
}
function Layer__GetLayerObj(layer_name,nested_ref){
 var layer;
 if(NN_6){
 layer=document.getElementById(layer_name);
}else if(IE){
 layer=document.all[layer_name];
}else if(NN_4){
 var layer_parent;
 if(typeof(nested_ref)!='undefined'){
 layer_parent=document.layers[nested_ref].document;
}else{
 layer_parent=document;
}
 layer=layer_parent.layers[layer_name];
}
return layer;
}
function Layer__GetLayerObjStyle(layer_name,nested_ref){
 var layer=Layer__GetLayerObj(layer_name,nested_ref);
if(!layer)return;
if(NN_6){
 layer=layer.style;
}else if(IE){
 layer=layer.style;
}else if(NN_4){
}
return layer;
}
function Layer__SetLayerPosition(left,top)
{
 this.LayerStyle.left=left;
 this.LayerStyle.top=top;
}
function Layer__GetLayerPosition()
{
 var pos=new Object();
pos.left=parseInt(this.LayerStyle.left);
 pos.top=parseInt(this.LayerStyle.top);
return pos;
}
function Layer__SetLayerDimentions(width,height)
{
 this.LayerStyle.width=width;
 this.LayerStyle.height=height;
}
function Layer__SetLayerDimentions_NN(width,height)
{
 this.LayerStyle.clip.width=width;
 this.LayerStyle.clip.height=height;
}
function Layer__GetLayerDimentions()
{
 var dimentions=this.GetPosition();
 dimentions.width=parseInt(this.LayerStyle.width);
 dimentions.height=parseInt(this.LayerStyle.height);
return dimentions;
}
function Layer__GetLayerDimentions_NN()
{
 var dimentions=this.GetPosition();
 dimentions.width=parseInt(this.LayerStyle.clip.width);
 dimentions.height=parseInt(this.LayerStyle.clip.height);
return dimentions;
}
function Layer__Move(start_left,start_top,end_left,end_top,timeout,speed_coefficient,name)
{
 var layer=typeof(name)=='undefined'?this : new Layer(name);
if(start_left==end_left&&start_top==end_top){
 layer.SetPosition(start_left,start_top);
 return;
}
if(typeof(speed_coefficient)=='undefined'){
 speed_coefficient=1;
}
var sign_left=__Layer__Sign(start_left,end_left);
 var sign_top=__Layer__Sign(start_top,end_top);
var dleft=__Layer__Distance(start_left,end_left);
 var dtop=__Layer__Distance(start_top,end_top);
var offset_left=1;
 var offset_top=1;
if(dleft > dtop){
 if(dtop==0){
 offset_top=0;
 offset_left=1;
}else{
 offset_top=1;
 offset_left=Math.floor(dleft/dtop);
}
}else{
 if(dleft==0){
 offset_top=1;
 offset_left=0;
}else{
 offset_top=Math.floor(dtop/dleft);
 offset_left=1;
}
}
if(start_left!=end_left){
 start_left+=speed_coefficient*sign_left*offset_left+LAYER__NETSCAPE_TIME_PATCH_COEFFICIENT;
}
if(start_top!=end_top){
 start_top+=speed_coefficient*sign_top*offset_top;
}
layer.SetPosition(start_left,start_top);
var new_sign_left=__Layer__Sign(start_left,end_left);
 var new_sign_top=__Layer__Sign(start_top,end_top);
if(sign_left*new_sign_left <=0&&sign_top*new_sign_top <=0){
 return;
}
var _name=typeof(name)=='undefined'?this.LayerName : name;
if(timeout > 0){
window.setTimeout('Layer__Move('+start_left+', '+start_top+', '+end_left+', '+end_top+', '+timeout+', '+speed_coefficient+', "' + _name + '")',timeout);
}else{
 Layer__Move(start_left,start_top,end_left,end_top,0,speed_coefficient,_name);
}
}
function __Layer__Distance(start,end)
{
 if(start > 0&&end > 0){
 return Math.abs(end-start);
}
return Math.abs(start)+Math.abs(end);
}
function __Layer__Sign(start,end)
{
 if(start < end)
 return 1;
if(start==end)
 return 0;
return-1;
}
function Layer__SetLayerVisible(visible)
{
 this.LayerStyle.visibility=visible?VISIBLE : HIDDEN;
}
function Layer__IsLayerVisible()
{
 return this.LayerStyle.visibility==VISIBLE;
}
function Layer__SetLayerDisplay(visible)
{
 this.LayerStyle.display=visible?DISPLAY_ON : DISPLAY_OFF;
}
function Layer__HTML(code)
{
 this.Layer.innerHTML=code;
}
function Layer__HTML_NN(code)
{
 this.Document.open();
 this.Document.write(code);
 this.Document.close();
}
function Layer__GetDocumentMargins()
{
 this.DocumentWidth=document.body.clientWidth+document.body.scrollLeft;
 this.DocumentHeight=document.body.clientHeight+document.body.scrollTop;
 this.FullDocumentWidth=document.body.scrollWidth;
 this.FullDocumentHeight=document.body.scrollHeight;
 this.ScrollLeft=document.body.scrollLeft;
 this.ScrollTop=document.body.scrollTop;
 this.WindowWidth=document.body.clientWidth;
 this.WindowHeight=document.body.clientHeight;
}
function Layer__GetDocumentMargins_NN()
{
 this.DocumentWidth=window.innerWidth+window.pageXOffset;
 this.DocumentHeight=window.innerHeight+window.pageYOffset;
 this.FullDocumentWidth=this.DocumentWidth;
 this.FullDocumentHeight=this.DocumentHeight;
 this.ScrollLeft=window.pageXOffset;
 this.ScrollTop=window.pageYOffset;
 this.WindowWidth=window.innerWidth;
 this.WindowHeight=window.innerHeight;
}
function Layer__Maximize()
{
 this.DocumentMargins();
 this.SetDimentions(this.WindowWidth,this.WindowHeight);
}
function Layer__Center(horizontally,vertically)
{
 var pos=this.GetPosition();
 var dimentions=this.GetDimentions();
this.DocumentMargins();
if(horizontally)
 pos.left=this.WindowWidth/2-dimentions.width/2;
 if(vertically)
 pos.top=this.WindowHeight/2-dimentions.height/2;
this.SetPosition(pos.left,pos.top);
}
function Layer__InitDrag()
{
 if(!inited_mouse_actions){
if(IE){
 document.onmousedown=Layer__System__MOUSEDOWN;
 document.onclick=Layer__System__MOUSEUP;
 document.onmousemove=Layer__System__MOUSEMOVE;
}else{
 document.onmousedown=Layer__System__MOUSEDOWN;
 document.captureEvents(Event.MOUSEDOWN);
document.onmouseup=Layer__System__MOUSEUP;
 document.captureEvents(Event.MOUSEUP);
document.onmousemove=Layer__System__MOUSEMOVE;
 document.captureEvents(Event.MOUSEMOVE);
}
inited_mouse_actions=true;
}
LAYERS_HASH[this.LayerName].Draggable=true;
}
function Layer__ReleaseDrag()
{
 LAYERS_HASH[this.LayerName].Dragging=false;
}
function Layer__System__MOUSEDOWN(event_obj)
{
 var dragged_some=false;
 for(var key in LAYERS_HASH){
 if(LAYERS_HASH[key].Draggable&&Layer__System__ClickedOverLayer(LAYERS_HASH[key],event_obj)){
if(IE)
 LAYERS_HASH[key].Dragging=true;
 else
 LAYERS_HASH[key].Dragging=!LAYERS_HASH[key].Dragging;
dragged_some=true;
}
}
if(!dragged_some&&allow_default_dragging){
 var current_pos=Layer__System__CurrentMousePosition(event_obj);
 default_mousedown(current_pos);
}
}
function Layer__System__MOUSEMOVE(event_obj)
{
 var old_pos=old_mouse_pos;
var current_pos=Layer__System__CurrentMousePosition(event_obj);
 var dragged_some=false;
for(var key in LAYERS_HASH){
 if(LAYERS_HASH[key].Draggable&&LAYERS_HASH[key].Dragging){
LAYERS_HASH[key].LayerStyle.left=parseInt(LAYERS_HASH[key].LayerStyle.left)+(current_pos.left-old_pos.left);
 LAYERS_HASH[key].LayerStyle.top=parseInt(LAYERS_HASH[key].LayerStyle.top)+(current_pos.top-old_pos.top);
 dragged_some=true;
}
}
if(!dragged_some&&allow_default_dragging){
 default_mousemove(old_pos,current_pos);
}
}
function Layer__System__MOUSEUP(event_obj)
{
 var dragged_some=false;
 for(var key in LAYERS_HASH){
 if(LAYERS_HASH[key].Draggable&&
 LAYERS_HASH[key].Dragging){
if(IE)
 LAYERS_HASH[key].Dragging=false;
dragged_some=true;
}
}
if(!dragged_some&&allow_default_dragging){
 var current_pos=Layer__System__CurrentMousePosition(event_obj);
 default_mouseup(current_pos);
}
}
function Layer__System__ClickedOverLayer(layer,event_obj)
{
 var pos=Layer__System__CurrentMousePosition(event_obj);
var layer_pos=layer.GetDimentions();
 layer_pos.right=layer_pos.left+layer_pos.width;
 layer_pos.bottom=layer_pos.top+layer_pos.height;
return(pos.left >=layer_pos.left&&pos.left <=layer_pos.right&&
 pos.top >=layer_pos.top&&pos.top <=layer_pos.bottom);
}
function Layer__System__CurrentMousePosition(event_obj)
{
 var pos=new Object();
 if(IE){
 pos.left=event.clientX+document.body.scrollLeft;
 pos.top=event.clientY+document.body.scrollTop;
}else{
 pos.left=event_obj.pageX+window.pageXOffset;
 pos.top=event_obj.pageY+window.pageYOffset;;
}
old_mouse_pos=pos;
return pos;
}