// modified by Shkodenko V. Taras 06/07/2006

/***********************************************
* Pop-it menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var defaultMenuWidth=150; //set default menu width
var defaultLeftPos  =5;   //set default left position
var defaultTopPos   =283; //set default top position
var extra_last_m_width = 0;

var left_pos=new Array();
var top_pos=new Array();
var m_width=new Array();
var linkset=new Array();
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT
linkset[0]='';
linkset[1]='';
linkset[2]='';
linkset[3]='';
linkset[4]='';
linkset[5]='';
linkset[6]='';
linkset[7]='';
linkset[8]='';
linkset[9]='';

/*
top_pos[0]=defaultTopPos;
top_pos[1]=defaultTopPos;
top_pos[2]=defaultTopPos;
top_pos[3]=defaultTopPos;
top_pos[4]=defaultTopPos;
top_pos[5]=defaultTopPos;
top_pos[6]=defaultTopPos;
top_pos[7]=defaultTopPos;
top_pos[8]=defaultTopPos;
top_pos[9]=defaultTopPos;
*/
/*
left_pos[0]='5px';
left_pos[1]='55px';
left_pos[2]='105px';
left_pos[3]='155px';
left_pos[4]='205px';
left_pos[5]='255px';
*/
/*
m_width[0]=defaultMenuWidth;
m_width[1]=defaultMenuWidth;
m_width[2]=defaultMenuWidth;
m_width[3]=defaultMenuWidth;
m_width[4]=defaultMenuWidth;
m_width[5]=defaultMenuWidth;
m_width[6]=defaultMenuWidth;
m_width[7]=defaultMenuWidth;
m_width[8]=defaultMenuWidth;
m_width[9]=defaultMenuWidth;
*/

////No need to edit beyond here
var ie5=document.all && !window.opera;
var ns6=document.getElementById;

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body;
}

if (ie5||ns6)
{
var draw_div = '<div id="popitmenu" style="position: absolute; left: 415px; top: 451px; z-index:10" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>';
 // alert(draw_div);
 document.write(draw_div);
}

function showmenu(e, which, t, optWidth)
{
//if(t == 8)
//    alert('e: '+e+', which: '+which+', optWidth: '+optWidth+', t: '+t+', left_pos['+t+']: '+left_pos[t]+', dw: '+get_document_width());
/*
alert('e: '+e+', which: '+which+', optWidth: '+optWidth+', t: '+t+', left_pos['+t+']: '+left_pos[t]);
*/
var dw=get_document_width();
var lw=left_pos[t]+optWidth-dw;
if(lw>0) optWidth-=lw;
//alert('menu width: '+optWidth+', lw: '+lw);
if (!document.all&&!document.getElementById) return;
clearhidemenu();
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu");
menuobj.innerHTML=which;
menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth;
menuobj.style.left=(typeof t!="undefined")? left_pos[t] : defaultLeftPos;
menuobj.style.top=(typeof t!="undefined")? top_pos[t] : defaultTopPos;
menuobj.contentwidth=menuobj.offsetWidth;
menuobj.contentheight=menuobj.offsetHeight;
eventX=ie5? event.clientX : e.clientX;
eventY=ie5? event.clientY : e.clientY;
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX;
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY;
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
{
 //move the horizontal position of the menu to the left by it's width
 // menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px";
}
else
{
  //position the horizontal position of the menu where the mouse was clicked
  // menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px";
}
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
{
 // menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px";
}
else
{
 // menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px";
}
menuobj.style.visibility="visible";
return false;
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj) menuobj.style.visibility="hidden";
}

function dynamichide(e){
if (ie5&&!menuobj.contains(e.toElement)) hidemenu();
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) hidemenu();
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500);
}

function clearhidemenu(){
if (window.delayhide) clearTimeout(delayhide);
}

// Added by Shkodenko V. Taras 27/06/2006
// Auto set left position of left menu in float tables
function t_auto_set_left_pos() {
  for(var i=0;i<top_pos.length;i++) {
    left_pos[i] = parseInt(defaultLeftPos);
    if(i>0) {
        for(var j=i; j>0; j--) {
            eval("left_pos["+i+"] += parseInt(document.getElementById('t"+j+"').offsetWidth);");
        }
    }
  }
  //
  var dw=get_document_width();
  var l=i-1;
  eval("var ww = parseInt(left_pos["+l+"]+document.getElementById('t"+l+"').offsetWidth);");  
  if(dw>ww)
    extra_last_m_width=dw-ww;
//alert('l: '+l+', ww: '+ww+', dw: '+dw+', extra_last_m_width: '+extra_last_m_width);
//
//  for(var t=0; t<left_pos.length; t++)
//   left_pos[t] = left_pos[t]+"px";
}

// Added by Shkodenko V. Taras 06/07/2006
function get_document_width(){
    // get document width
    var dw=0;
    // Opera, Mozilla Firefox
    if (window.innerWidth || window.innerHeight) { 
//        alert('first: '+window.innerWidth);
        return window.innerWidth-1;
    }
    // IE
    if (document.body.clientWidth || document.body.clientHeight) {
//        alert('second: '+document.body.clientWidth);
        return document.body.clientWidth-1;
    }
}

if (ie5||ns6)
document.onclick=hidemenu;
