var image1 = new Image();
image1.src="/img/gears.gif";
/*var image2= new Image();
image2.src="/img/menubutton_lit.png";
var image3= new Image();
image3.src="/img/menubutton_over.png";*/
var image4= new Image();
image4.src="/img/smallloader.gif";
/*var image5= new Image();
image5.src="/img/smallloader.png";*/


/*var image4= new Image();
image4.src="/images/spit_lit.gif";
var image5= new Image();
image5.src="/images/spitbig_lit.gif";
var image6 = new Image();
image6.src="/images/loader_s.gif";*/


function showloadbox(obj,small)
{
var i=1;
if (ie||ns6||opera)
{
while  (document.getElementById("loadbox"+i) && document.getElementById("loadbox"+i).style.visibility=="visible") i++;
if (!document.getElementById("loadbox"+i)) createloadbox(i);
loadbox=document.getElementById("loadbox"+i)
if (small)
 {
  loadbox.className="loadboxsmall";
  loadbox.innerHTML='';
  var height="40";
  var width="40";
 }
else
 {
  loadbox.className="loadbox";
  var height="60";
  var width="210";
  loadbox.innerHTML='<b>Запрос обрабатывается...</b><br>Пожалуйста подождите...<br><img src="/img/loadinganim.gif">';
 }
if (!obj) obj = document.body;
loadbox.style.left=loadbox.style.top=-500;
loadbox.x=getposOffset(obj, "left")
loadbox.y=getposOffset(obj, "top")
loadbox.style.left=loadbox.x+Math.floor(obj.offsetWidth / 2)-(width/2)+"px"
loadbox.style.top=loadbox.y+Math.floor(obj.offsetHeight / 2)-(height/2)+"px";
loadbox.style.visibility="visible";
loadbox.appear=true;
loadbox.style.opacity="0.1";
if (ie)
loadbox.style.filter="alpha(opacity=1)";
setTimeout("inctrans("+i+")",50);
return i;
}
}

function boxerror(i)
{
 loadbox=document.getElementById("loadbox"+i);
 loadbox.innerHTML='<b>Ошибка! попробуйте по позже!</b><br><img src="/img/loadinganim.gif">';
 setTimeout("hidebox("+i+");",3000);
}

function boxretry(i,num)
{
 loadbox=document.getElementById("loadbox"+i);
 loadbox.innerHTML='<b>Ошибка! Повтор номер '+num+'</b><br><img src="/img/loadinganim.gif">';
}


function inctrans(i)
{
obj=document.getElementById("loadbox"+i);
objstyle=obj.style;
if (objstyle.opacity<1 && obj.appear)
{
objstyle.opacity=Math.abs(objstyle.opacity)+0.3;
if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
setTimeout("inctrans("+i+");",80);
}
}

function dectrans(i)
{
obj=document.getElementById("loadbox"+i);
objstyle=obj.style;
if (objstyle.opacity>0.1)
{
objstyle.opacity=Math.abs(objstyle.opacity)-0.3;
if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
setTimeout("dectrans("+i+");",80);
}
else
{
objstyle.visibility="hidden";
objstyle.left="-500px";
}
}


function hidebox(ID){
box=document.getElementById("loadbox"+ID);
box.appear=false;
setTimeout("dectrans("+ID+");",80);
}

function createloadbox(ID){
var divblock=document.createElement("div");
divblock.setAttribute("id", "loadbox"+ID);
divblock.className="loadbox";
document.body.appendChild(divblock);
}


//----------------------------------------------WINDOW ENGINE------------------------------------------------------------------------------------------

var WinBox=new Array();
var nowinleft = true;

function hidewinbox(i)
{
WinBox[i].last=true;
for (var j=1;j<WinBox.length;j++)
if (WinBox[j].showing && !WinBox[i].hiding && (j!=i)) WinBox[i].last=false;
WinBox[i].hiding=true;
setTimeout("decwintrans("+i+");",40);
}

function GetWinBox()
{
var i=1;
while (WinBox[i] && WinBox[i].showing) i++;
if (!WinBox[i])
{
var divblock=document.createElement("div");
divblock.setAttribute("id", "winbox");
document.body.appendChild(divblock);
WinBox[i]=[];
WinBox[i].win=divblock;
WinBox[i].order=Infinity;
}
WinBox[i].win.innerHTML='';
WinBox[i].lastrequest='';
WinBox[i].showing=true;
WinBox[i].hiding=false;

ReOrganizeWindows(i);

WinBox[i].last=true;
for (var j=1;j<WinBox.length;j++)
if (WinBox[j].showing && !WinBox[i].hiding && (j!=i)) WinBox[i].last=false;
return i;
}


function ReOrganizeWindows(tofront)
 {
  var pass=0;
  var Finished=false;
  var NextOrder=0;
  var BiggestOrder=0;
  var BiggestOrderID=0;
  if (tofront==false)
     tofront=false;
  else
   {
    WinBox[tofront].order=0;
    NextOrder=1;
    for (var j=1;j<WinBox.length;j++)
     if (WinBox[j].showing && tofront!==j)
      WinBox[j].order++;
   }

  while (!Finished)
   {
    pass++;
    BiggestOrder=Infinity;
    BiggestOrderID=false;
    for (var j=1;j<WinBox.length;j++)
     if (WinBox[j].showing && (tofront!==j))
       if ((WinBox[j].order<BiggestOrder) && (WinBox[j].order>=NextOrder))
        {
         BiggestOrder=WinBox[j].order;
         BiggestOrderID=j;
        }
    if (BiggestOrderID!==false)
     {
      WinBox[BiggestOrderID].order=NextOrder;
      WinBox[BiggestOrderID].win.style.zIndex=95-(NextOrder);
      NextOrder++;
      if (ie) WinBox[BiggestOrderID].win.style.filter="alpha(opacity=100)";
     }
    else
     Finished=true;
   }

 }


function showwinbox(wincontents, obj,width,height,header,noclose,startNotHidden,favbutton)
{
if (ie||ns6)
{
greyscr=document.getElementById('greyscreen');
var FullWidth=document.body.scrollWidth;
var FullHeight=0;
if (document.body.scrollHeight<document.body.offsetHeight)
FullHeight=document.body.offsetHeight;
else
FullHeight=document.body.scrollHeight;

var i=GetWinBox();

if (obj)
 {
  WinBox[i].x=getposOffset(obj, "left");
  WinBox[i].y=getposOffset(obj, "top");
 }
else
 {
  WinBox[i].x=Math.floor((FullWidth-width)/2);
  if (height)
   WinBox[i].y=((document.body.scrollTop)+(Math.floor(document.body.clientHeight-height)/3));
  else
   WinBox[i].y=document.body.scrollTop+50;
  if (WinBox[i].y<10) WinBox[i].y=10;
 }

if (!width) width='500';


WinBox[i].win.style.left=Math.floor(document.body.offsetWidth/2)-Math.floor(width/2);
WinBox[i].win.style.top=WinBox[i].y+"px";

WinBox[i].win.style.width=width;

minheight='';
if ((wincontents=='') && height)
 {
  height+='px';
  if (!ie)
   {
    minheight=' min-height:'+height;
    height='auto';
   }
 }
else
height='auto';

WinBox[i].win.style.height=height;

var fav='';
var twidth=30;

if (!header) header='shturman';

if (favbutton)
{
 twidth+=75;
 fav = '<a href="" onclick="DirectLink(\''+LastContentPost+favbutton+'\'); return false"><img width="24" height="16" src="/img/linkbtn_dim.png" alt="!directlink!" title="!directlink!" style="margin-right:2px;" onMouseOver="this.src=\'/img/linkbtn_lit.png\'" onMouseOut="this.src=\'/img/linkbtn_dim.png\'"></a><a href="" onclick="AddFavorite(\''+LastContentPost+favbutton+'\',\''+document.title+' | ['+header+']\'); return false"><img width="24" height="16" src="/img/favbtn_dim.png" alt="!addtofav!" title="!addtofav!" style="margin-right:2px;" onMouseOver="this.src=\'/img/favbtn_lit.png\'" onMouseOut="this.src=\'/img/favbtn_dim.png\'"></a>';
 header='G-Works'+' | '+header;
}

var close='<a href="" onclick="hidewinbox('+i+'); return false"><img width="24" height="16" src="/img/closebtn_dim.png" alt="!close!" title="!close!" style="margin-right:2px;" onMouseOver="this.src=\'/img/closebtn_lit.png\'" onMouseOut="this.src=\'/img/closebtn_dim.png\'"></a>'
if (noclose)
 {twidth-=25; close='';}
WinBox[i].win.innerHTML='<table cellspasing="0" cellpadding="0" class="floatwin" width="100%" onMouseDown="ReOrganizeWindows('+i+')"><tr class="winheader"><td id="windrag'+i+'" style="padding-left:3px;padding-top:2px;width:'+(width-30)+'px;" ><img src="/img/logo.gif" width="14" height="14" style="float:left;">&nbsp;&nbsp;'+header+'</td><td width="'+twidth+'"><span style="float:right">'+fav+close+'</span></td></tr><tr><td height="100%" colspan="2" width="100%" style="vertical-align:top;"><div width=100% height="100%" class="wincontent" style="width:auto; height:100%;'+minheight+'" id="wincontent'+i+'" onMouseDown="ReOrganizeWindows('+i+')">'+wincontents+'</div></td></table>';
Drag.init(document.getElementById("windrag"+i),WinBox[i].win);
WinBox[i].contents=document.getElementById("wincontent"+i)
WinBox[i].win.style.visibility="visible";



if (!startNotHidden)
{
 WinBox[i].contents.style.opacity='0.0';
 WinBox[i].contents.style.visibility="hidden";
 if (ie) WinBox[i].contents.style.filter="alpha(opacity=0)";
}

setTimeout('resizegreyscreen();',100);

if (WinBox[i].last) greyscr.style.visibility="visible";
if (ie)
 {
  WinBox[i].win.style.filter="alpha(opacity=1)";
  if (WinBox[i].last) greyscr.style.filter=WinBox[i].win.style.filter;
 }
WinBox[i].win.style.opacity="0.1";
if (WinBox[i].last) greyscr.style.opacity=WinBox[i].win.style.opacity;
setTimeout("incwintrans("+i+");",80);


return i;
}
}

function resizegreyscreen()
 {
  greyscr=document.getElementById('greyscreen');
  var FullWidth=document.body.scrollWidth;
  var FullHeight=0;
  if (document.body.scrollHeight<document.body.offsetHeight)
   var FullHeight=document.body.offsetHeight;
  else
   FullHeight=document.body.scrollHeight;
  greyscr.style.width=FullWidth;
  greyscr.style.height=FullHeight;
 }


function TrimBox(i)
 {
  if(!ie) WinBox[i].contents.style.minHeight="";
  WinBox[i].win.style.height="auto";
  WinBox[i].contents.style.height="auto";
  setTimeout('resizegreyscreen();',100);
 }

function SetWinResponseText(text,i,trim)
{
 if (trim) trim='TrimBox('+i+');';
 FadeOut(WinBox[i].contents,true,true,'<div style="font-size:12px;margin:10px;">'+text+'</div>',trim);
 //WinBox[i].contents.innerHTML='<div style="font-size:12px;margin:10px;">'+text+'</div>';
}

function SetWinResponseText2(text,i,trim)
{
 if (trim) trim='TrimBox('+i+');';
 WinBox[i].contents.innerHTML=text;
 //FadeOut(WinBox[i].contents,text);
}


function incwintrans(i)
{
objstyle=WinBox[i].win.style;
greyscr=document.getElementById('greyscreen');
greyscrstyle=greyscr.style;
if (objstyle.opacity<1 && WinBox[i].showing)
{
objstyle.opacity=Math.abs(objstyle.opacity)+0.6;
if (WinBox[i].last) greyscrstyle.opacity=Math.abs(greyscrstyle.opacity)+0.3;

if (ie)
{
objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
if (WinBox[i].last) greyscrstyle.filter="alpha(opacity="+Math.floor(Math.abs(greyscrstyle.opacity)*100)+")";
}
setTimeout("incwintrans("+i+");",80);
}
}

function decwintrans(i)
{
obj=WinBox[i].win;
objstyle=obj.style;
greyscr=document.getElementById('greyscreen');
greyscrstyle=greyscr.style;
if (objstyle.opacity>0.1)
{
objstyle.opacity=Math.abs(objstyle.opacity)-0.6;
if (WinBox[i].last) greyscrstyle.opacity=Math.abs(greyscrstyle.opacity)-0.3;

if (ie)
{
objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
if (WinBox[i].last) greyscrstyle.filter="alpha(opacity="+Math.floor(Math.abs(greyscrstyle.opacity)*100)+")";
}

setTimeout("decwintrans("+i+");",80);
}
else
{
WinBox[i].showing=false;
WinBox[i].hiding=false;
WinBox[i].contents.innerHTML='';
if (WinBox[i].last)
 {
  greyscrstyle.width=1;
  greyscrstyle.height=1;
  greyscrstyle.visibility="hidden";
  WinBox[i].last=false;
 }
else
 {

 }
ReOrganizeWindows(false);
objstyle.visibility="hidden";
objstyle.left="-500px";
}
}
//----------------------------------------------------------------------------------------------------------------------------------

//---------------------------------------------- DRAG ENGINE --------------------------------------------------------------------------------
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

        o.root.style.opacity="0.7";
        if (ie) o.root.style.filter="alpha(opacity=70)";

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        if (ie) Drag.obj.root.style.filter="alpha(opacity=70)";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);

		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
        Drag.obj.root.style.opacity="1";
        if (ie) Drag.obj.root.style.filter="alpha(opacity=100)";
        resizegreyscreen();
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
//------------------------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------

function attEvt_ie(obj, event, func)
{
  obj.attachEvent('on' + event, func);
}

function attEvt_moz(obj, event, func)
{
  obj.addEventListener(event, func, false);
}
if (ie)
  attEvt = attEvt_ie;
else
  attEvt = attEvt_moz;

function createMethodRef(object, methodName, arg2)
{
  return function()
  {
    return object[methodName].apply(object, [arg2, arguments]);
  }
}

function ImgPreloader()
 {
  this.ImgObj=false;
  this.AfterAction='';

  this.ImgLoad=OnImgLoad;
  this.PreloadImg=ImgPreload;

  function OnImgLoad()
  {
   //document.images[document.images.length]=this.ImgObj;
   eval(this.AfterAction);
  }

  function ImgPreload(src,exec)
  {
   this.AfterAction=exec;
   this.ImgObj= new Image();
   this.ImgObj.src=src;
   if (this.ImgObj.complete==false)
    attEvt(this.ImgObj,'load',createMethodRef(this,'ImgLoad'));
   else eval(exec);
  }
 }

//----------------------------------------------
function make_confirmation(conf_text,width,height,yesstring,yes,nostring,no)
 {
  var nobutton='';
  var id=showwinbox('',false,width,height,'',true,true);
  if (no) nobutton=' <input class="formbtn" type=button id="button" value="'+no+'" onclick="'+nostring+';hidewinbox('+id+');">';
  SetWinResponseText2('<table width="100%"><tr><td><div width="100%" style="font-size:12px;margin:10px 10px 5px 10px;" >'+conf_text+'</div></td></tr><tr><td><div width="100%" align="center"><input id="button" class="formbtn" type=submit value="'+yes+'" onclick="'+yesstring+';hidewinbox('+id+');">'+nobutton+'</div></td></tr></table>',id);
  return id;
 }


function showpic(obj,name,src,width,height)
{
 var loadbox=showloadbox(obj,true);
 var ImgPrel = new ImgPreloader();
 ImgPrel.PreloadImg(src,'hidebox('+loadbox+');showpic2(false,"'+name+'","'+src+'",'+width+','+height+');');
}


function showpic2(obj,name,src,width,height)
{
 var id=showwinbox('',false,width+5,height+5,name,false,true);
 SetWinResponseText2('<a href="" onclick="hidewinbox('+id+');return false;" title="[!clicktoclosewin!]"><img class="image" width="'+width+'" height="'+height+'" src="'+src+'"></a>',id)
}

///--------------------- Fader -------------------------

FadeObjects= new Array();

function FadeOut(obj,fin,fout,text,exec2,exec1)
 {
  var i=0;
  while (FadeObjects[i] && FadeObjects[i]!=null && FadeObjects[i].obj!=obj) i++;
  if (!FadeObjects[i] || FadeObjects[i]==null)
   {
    FadeObjects[i]=[];
    FadeObjects[i].obj=obj;
   }
   FadeObjects[i].fadein=fin;
   FadeObjects[i].fadeout=fout;

  if (text!=false)
    FadeObjects[i].text=text;

  if (exec2)
   FadeObjects[i].exec2=exec2;
  else
   FadeObjects[i].exec2=false;

  if (exec1)
   FadeObjects[i].exec1=exec1;
  else
   FadeObjects[i].exec1=false;

  if (obj.style.opacity==null || obj.style.opacity=='') obj.style.opacity='1';

  if (fout && obj.style.opacity>0)
  {
   if (FadeObjects[i].timer!=null)
    clearTimeout(FadeObjects[i].timer);
   FadeObjects[i].timer=setTimeout("fadeoutobj("+i+");",100);
  }
  else
  if (fin)
  {
   if (FadeObjects[i].timer!=null)
    clearTimeout(FadeObjects[i].timer);
   if (text!=false)
    obj.innerHTML=text;
   FadeIn(i);
  }
 }

function FadeIn(i)
 {
   FadeObjects[i].obj.style.visibility="visible";
   if (FadeObjects[i].timer!=null)  clearTimeout(FadeObjects[i].timer);
   FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",100);
 }


function fadeinobj(i)
 {
  obj=FadeObjects[i].obj;
  objstyle=obj.style;
  if (objstyle.opacity<1)
   {
    objstyle.opacity=Math.abs(objstyle.opacity)+0.3;
    if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
    FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",100);
   }
  else
  {
   if (ie) objstyle.filter=null;
   objstyle.opacity=null
   if (FadeObjects[i].exec2) eval(FadeObjects[i].exec2);
   FadeObjects[i].fadeout=false;
   FadeObjects[i].fadein=false;
   clearTimeout(FadeObjects[i].timer)
  }
 }

function fadeoutobj(i)
 {
  obj=FadeObjects[i].obj;
  objstyle=obj.style;
  if (objstyle.opacity>0.1)
   {
    objstyle.opacity=Math.abs(objstyle.opacity)-0.3;
    if (ie) objstyle.filter="alpha(opacity="+Math.floor(Math.abs(objstyle.opacity)*100)+")";
    FadeObjects[i].timer=setTimeout("fadeoutobj("+i+");",100);
   }
  else
   {
    if (FadeObjects[i].fadein && FadeObjects[i].fadeout)
     {
      if (FadeObjects[i].text!=false)
       FadeObjects[i].obj.innerHTML=FadeObjects[i].text;
      if (FadeObjects[i].exec1) eval(FadeObjects[i].exec1);
      FadeObjects[i].fadeout=false;
      FadeObjects[i].timer=setTimeout("fadeinobj("+i+");",100);
     }
    else
    {
     clearTimeout(FadeObjects[i].timer);
     objstyle.visibility="hidden";
    }
   }
 }
//----------------------------------------INFO BOX--------------------------------------------------

var InfoBox= new Array();
var InfoBoxLeftPosCorr=9;//------------------------------------
var InfoBoxTopPosCorr=2; //----------------------
var InfoBoxTimerID=false;
var prevobj=false;

function InfoBoxDraw()
{
 var i=1;
 var CanDoTimeout=false;
 InfoBoxTimerID=false;
 while (InfoBox[i] && InfoBox[i].block)
 {
 if (InfoBox[i].showing)
 {
  if (InfoBox[i].growingout)
   {
    InfoBox[i].width=InfoBox[i].width+(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toleft) InfoBox[i].leftcorr=InfoBox[i].leftcorr-(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toup) InfoBox[i].upcorr=InfoBox[i].upcorr-InfoBox[i].speed;
    InfoBox[i].height=InfoBox[i].height+InfoBox[i].speed;
    if (InfoBox[i].height>=InfoBox[i].newheight)
     {
      InfoBox[i].growingout=false;
      InfoBox[i].contentbox.innerHTML=InfoBox[i].content;
     }
    else
    CanDoTimeout=true;
   }
  if (InfoBox[i].growingin)
   {
    InfoBox[i].width=InfoBox[i].width-(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toleft) InfoBox[i].leftcorr=InfoBox[i].leftcorr+(InfoBox[i].speed*InfoBox[i].whcoef);
    if (InfoBox[i].toup) InfoBox[i].upcorr=InfoBox[i].upcorr+InfoBox[i].speed;
    InfoBox[i].height=InfoBox[i].height-InfoBox[i].speed;
    if (InfoBox[i].height<=10)
     {
      InfoBox[i].width=0;
      InfoBox[i].height=0;
      InfoBox[i].growingin=false;
      InfoBox[i].growingout=false;
      InfoBox[i].showing=false;
      InfoBox[i].block.style.visibility="hidden";
      InfoBox[i].leftarrow.style.visibility="hidden";
      InfoBox[i].rightarrow.style.visibility="hidden";
     }
    else
     CanDoTimeout=true;
   }
   if (InfoBox[i].toleft)
    {
     InfoBox[i].block.style.left=Math.floor(InfoBox[i].leftcorr);
    }
   if (InfoBox[i].toup)
    {
     InfoBox[i].block.style.top=Math.floor(InfoBox[i].upcorr);
    }
  InfoBox[i].block.style.width=Math.floor(InfoBox[i].width)+browserleftcorrection;
  InfoBox[i].block.style.height=InfoBox[i].height;
}
 i++;
}
 //clearTimeout(InfoBoxTimerID);
 if (CanDoTimeout)
 {
 InfoBoxTimerID=setTimeout(InfoBoxDraw,10);
 }

}



function getinfobox(obj)
{
var i=1;
while (InfoBox[i] && InfoBox[i].obj!=obj) i++;
if (!InfoBox[i] || !InfoBox[i].block)
{
 InfoBox[i]=[];
 InfoBox[i].obj=obj;
 var divblock=document.createElement("div");
 divblock.setAttribute("id", "infobox"+i);
 document.body.appendChild(divblock);
 divblock.className='infobox';
 InfoBox[i].block=divblock;
 InfoBox[i].block.innerHTML='<div id="infobox'+i+'content" class="infoboxcontent" onmouseover="StopInfoBoxHide('+i+');" onclick="HideInfoBox('+i+');" onmouseout="InfoBoxTimeout('+i+')"></div>';
 InfoBox[i].contentbox=document.getElementById("infobox"+i+"content");
 var divblock=document.createElement("img");
 divblock.setAttribute("id", "arrowR"+i);
 divblock.src="/img/arrow_right.gif";
 document.body.appendChild(divblock);
 divblock.className='arrowR';
 InfoBox[i].rightarrow=divblock;
 var divblock=document.createElement("img");
 divblock.setAttribute("id", "arrowL"+i);
 divblock.src="/img/arrow_left.gif";
 document.body.appendChild(divblock);
 divblock.className='arrowL';
 InfoBox[i].leftarrow=divblock;
 InfoBox[i].toleft=false;  //------------
 InfoBox[i].toup=false;  //--------------
}
return i;
}

function ShowInfoBox(boxcontent,obj,tipwidth,height)
{
var i=getinfobox(obj);
StopInfoBoxHide(i);
HideAllBoxes();
if ((InfoBox[i].obj!=obj) || !InfoBox[i].showing)
 {
  //prevobj=i;
  InfoBox[i].contentbox.innerHTML='';
  x=getposOffset(obj, "left")+3;
  y=getposOffset(obj, "top")-4;

  if ((x-23+browserleftcorrection-tipwidth)<0)
   InfoBox[i].toleft=false;
  else
   InfoBox[i].toleft=(InfoBox[i].toleft && true);

  if ((y-height+13)<0)
   InfoBox[i].toup=false;
  else
   InfoBox[i].toup=(InfoBox[i].toup && true);
  InfoBox[i].speed=Math.floor(Math.sqrt(tipwidth+height)*0.3);
  if (InfoBox[i].toleft)
   {
    InfoBox[i].block.style.left=x+InfoBoxLeftPosCorr+browserleftcorrection;
    InfoBox[i].leftarrow.style.visibility="hidden";
    InfoBox[i].rightarrow.style.visibility="visible";
    InfoBox[i].rightarrow.style.left=x-2+InfoBoxLeftPosCorr+browserleftcorrection;
   }
  else
   {
    InfoBox[i].block.style.left=x+9-InfoBoxLeftPosCorr+obj.offsetWidth;
    InfoBox[i].rightarrow.style.visibility="hidden";
    InfoBox[i].leftarrow.style.visibility="visible";
    InfoBox[i].leftarrow.style.left=x-InfoBoxLeftPosCorr+obj.offsetWidth+2;
   }
   if (InfoBox[i].toup)
    {
     InfoBox[i].block.style.top=y+8+InfoBoxTopPosCorr;
    }
   else
    {
     InfoBox[i].block.style.top=y-3+InfoBoxTopPosCorr;
    }
  InfoBox[i].rightarrow.style.top=y+5+InfoBoxTopPosCorr;
  InfoBox[i].leftarrow.style.top=y+5+InfoBoxTopPosCorr;
  InfoBox[i].block.style.width=0;
  InfoBox[i].block.style.height=0;
  if (boxcontent!='')
   InfoBox[i].content=boxcontent;
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  InfoBox[i].showing=true;
  InfoBox[i].width=InfoBox[i].height=0;
  InfoBox[i].newwidth=tipwidth;
  InfoBox[i].newheight=height;
  InfoBox[i].leftcorr=x+browserleftcorrection-InfoBoxLeftPosCorr;
  InfoBox[i].upcorr=y+21+InfoBoxTopPosCorr;
  InfoBox[i].whcoef=(InfoBox[i].newwidth/InfoBox[i].newheight);
  InfoBox[i].block.style.visibility="visible";
  if (!InfoBoxTimerID)
  InfoBoxDraw();
  return InfoBox[i];
 }
else
 {
  if (InfoBox[i].growingin)
  {
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
  }
  return InfoBox[i];
 }
}

function GetBoxByObj(obj)
{
var i=1;
while (InfoBox[i] && InfoBox[i].obj!=obj) i++;
if (!InfoBox[i] || !InfoBox[i].block) return false;
else return i;
}


function SetInfoBoxText(obj,text)
{
var i=1;
if (i=GetBoxByObj(obj))
 {
  if (InfoBox[i].contentbox.innerHTML!='')
   InfoBox[i].contentbox.innerHTML=text;
  else
   InfoBox[i].content=text;
 }
}

function StopInfoBoxHide(i)
{
if (InfoBox[i].hidetimer) clearTimeout(InfoBox[i].hidetimer);
 if (InfoBox[i].growingin)
  {
  InfoBox[i].growingin=false;
  InfoBox[i].growingout=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
  }
}

function HideInfoBox(i)
{
  InfoBox[i].contentbox.innerHTML='';
  InfoBox[i].growingout=false;
  InfoBox[i].growingin=true;
  if (!InfoBoxTimerID)
   InfoBoxDraw();
}

function HideAllBoxes()
{
for (var i=0;i<InfoBox.length;i++)
if (InfoBox[i] && InfoBox[i].showing) HideInfoBox(i);
}


function InfoBoxTimeout2(obj)
{
 var i=1;
 if (i=GetBoxByObj(obj))
  {
   if (!InfoBox[i].growingin)
   InfoBox[i].hidetimer=setTimeout("HideInfoBox("+i+")",300);
  }
}


function InfoBoxTimeout(i)
{
InfoBox[i].hidetimer=setTimeout("HideInfoBox("+i+")",200);
}



