// CBE Cascading Drop-down Menu
// copyright (c) 2002 Mike Foster
// get CBE at cross-browser.com
// CBE and cbeDropdownMenu are licensed under the LGPL

// v1.5 30Oct02 - bug fix for when label with no box is the last label
// v1.4 29Oct02 - added support for main labels with no boxes
// v1.3 01Oct02 - utilizes the update to CBE v4.15 which allows object methods to be used as event listeners
// v1.2 27Aug02 - now licensed under LGPL
// v1.1 20Aug02 - added optional parameters to the paint() method, for re-painting on win resize
// v1.0 17Aug02 - initial release

var
  cbeMenu,
  mnuMarker,
  downgrade = true,
  ua = navigator.userAgent.toLowerCase();
 
if (
  ua.indexOf('msie') != -1 && parseInt(navigator.appVersion) >= 4  // IE4 up
  || ua.indexOf('gecko') != -1                                     // Gecko
  || ua.indexOf('konqueror') != -1                                 // Konquerer
  || window.opera                                                  // Opera
) {
  document.write("<script type='text/javascript' src='/include/cbe_core.js'></script>");
  document.write("<script type='text/javascript' src='/include/cbe_event.js'></script>");
  downgrade = false;
}

function windowOnload() {
  mnuMarker = cbeGetElementById('mnuMarker').cbe;
  
  
  cbeMenu = new cbeDropdownMenu(
    mnuMarker.pageX(), mnuMarker.pageY(), // coord of first label
    100, 14,                               // label width and height
    80,                                  // box width
    14,                                   // item height  18
    2,                                    // item left padding
    '#b7b7b7',                            // background color
    '#ffffff',                            // text color
    '#92A6C1',                            // hover background color
    '#ffffff'                             // hover text color
  );


  window.cbe.addEventListener('resize', winResizeListener, false);
}

function winResizeListener() {
  cbeMenu.paint(mnuMarker.pageX(), mnuMarker.pageY());
}

// begin class cbeDropdownMenu

function cbeDropdownMenu(mnuX, mnuY, lblW, lblH, boxW, itmH, itmPad, bgColor, txtColor, hvrBColor, hvrTColor) {

  // Properties

  this.mnuX = mnuX;
  this.mnuY = mnuY;
  this.lblW = lblW;
  this.lblH = lblH;
  this.boxW = boxW;
  this.itmH = itmH;
  this.itmPad = itmPad;
  this.bgColor = bgColor;  
  this.txtColor = txtColor; 
  this.hvrBColor = hvrBColor;
  this.hvrTColor = hvrTColor;
  this.lblCount = 0;
  this.lblActive = null;
  
  // Methods

  this.paint = function(mnuX, mnuY) { // this is the only public method
    if (arguments.length > 0) this.mnuX = mnuX;
    if (arguments.length > 1) this.mnuY = mnuY;
    var lbl = null; // of type Element
    var box = null; // of type CBE
    var mX = this.mnuX;
    var mY = this.mnuY;
    
    this.lblCount = 0;
    do {
      ++this.lblCount;
      lbl = cbeGetElementById('label' + this.lblCount)
      if (lbl) 
      {
        with (lbl.cbe) 
        {
          color(this.txtColor);    
          background('transparent'); //this.bgColor
          //background(this.bgColor);
          zIndex(2002-this.lblCount);
          
      /*    if(this.lblCount==1)
           resizeTo(65, this.lblH);
          else if(this.lblCount==2)
           resizeTo(145, this.lblH);
          else if(this.lblCount==3)
           resizeTo(150, this.lblH); 
          else if(this.lblCount==4)
           resizeTo(130, this.lblH); 
          else if(this.lblCount==5)
           resizeTo(75, this.lblH); 
        */   
          moveTo(mX, mY); 
          show();
        }
        if (lbl.cbe.nextSibling && lbl.cbe.nextSibling.id.indexOf('label')==-1) box = lbl.cbe.nextSibling;
        else box = null;
        lbl.cbe.childBox = box;
        lbl.cbe.parentLabel = null;
        if (box) this.paintBox(box, lbl.cbe, mX, mY + lbl.cbe.height(), 2002);
        
        //mX += lbl.cbe.width();
        /*
        if(this.lblCount==1)
           {mX+=100;mY+=0;}
        else if(this.lblCount==2)
           {mX+=10;mY+=0;}   
        else if(this.lblCount==3)
           {mX-=4;mY+=21;}   
        else if(this.lblCount==4)
           {mX-=30;mY+=21;}   
        else if(this.lblCount==5)
           {mX-=50;mY+=21;}   
          */
        mX=cbeGetElementById('mnuMarker'+this.lblCount).cbe.pageX();  
        
      }
    } while(lbl);
    --this.lblCount;
  }

  this.getboxW = function(box)
  {
    if(box.id == "b1")
     return 100;
     
    else if(box.id == "b2")
     return 220; 
     
    else if(box.id == "b22")
     return 135; 
     
    else if(box.id == "b3")
     return 100; 
     
    else if(box.id == "b6")
     return 210; 
     
    else if(box.id == "b62")
     return 135; 

    else if(box.id == "b4")
     return 100; 

    else if(box.id == "b42")
     return 220; 

    else if(box.id == "b5")
     return 220; 
    else if(box.id == "b522")
     return 135; 
     
    else 
     return 80; 
  }
  
  this.paintBox = function(box, parent, x, y, myzindex) {
    var mx=0, my=4, itmCount=0;
    box.background(this.bgColor);
    
    //box.width(this.boxW);
    box.width(this.getboxW(box));
    box.moveTo(x, y);
    box.zIndex(myzindex);
    var itm = box.firstChild;
    while (itm) {
      if (itm.id.indexOf('i') != -1) {
        itm.color(this.txtColor);
        itm.background(this.bgColor);
        itm.resizeTo(this.getboxW(box) - 6, this.itmH);
        itm.moveTo(mx + this.itmPad, my);
        itm.show();
        my += itm.height();
        ++itmCount;
      }
      else {
        itm.previousSibling.childBox = itm;
        itm.previousSibling.parentLabel = parent;
        this.paintBox(itm, itm.previousSibling, mx+ itm.parentNode.width()-10, my - itm.previousSibling.height(), myzindex+1);
      }
      itm = itm.nextSibling;
    }
    box.height(itmCount * this.itmH + 8);
  }

  this.mousemoveListener = function(e) {
    if (
      this.lblActive &&
      (e.cbeTarget != this.lblActive.childBox &&
      e.cbeTarget != this.lblActive &&
      e.cbeTarget.parentNode != this.lblActive.childBox)
    ) {
      if (this.lblActive.childBox) this.lblActive.childBox.hide();
      this.lblActive.color(this.txtColor);
      this.lblActive.background('transparent'); //this.bgColor
      //this.lblActive.background(this.bgColor);
      this.lblActive = this.lblActive.parentLabel;
    }
    else if (e.cbeTarget.childBox || e.cbeTarget.id.indexOf('label')!=-1) {
      e.cbeTarget.color(this.hvrTColor);
      e.cbeTarget.background('transparent'); //this.hvrBColor
      //e.cbeTarget.background(this.hvrBColor);
      this.lblActive = e.cbeTarget;
      if (this.lblActive.childBox) this.lblActive.childBox.show();
    }
  }
  
  // Constructor Code

  this.paint();
  document.cbe.addEventListener('mousemove', this.mousemoveListener, false, this);

} // end class cbeDropdownMenu

var vars="";
function max1(name)
{
var adresses = window.open("","AAAA", "height=268,width=400,top=100,left=300,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<style>a{font-size: 12px; font-face: verdana; color:#000099;}</style>");
k.write("<html><body text=000000 bgcolor=#CC9966 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><a href='javascript:window.close()'><center><img align=center border=0 src='/images/"+name+"_small.jpg' border=0></a><center>");
k.close();
}
function max2(name)
{
var adresses = window.open("","AAAA", "height=250,width=400,top=100,left=300,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<style>a{font-size: 12px; font-face: verdana; color:#000099;}</style>");
k.write("<html><body text=000000 bgcolor=#CC9966 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><a href='javascript:window.close()'><center><img align=center border=0 src='/images/representing/big"+name+".jpg' border=0></a><center>");
k.close();
}
function max3(name)
{
var adresses = window.open("","AAAA", "height=390,width=310,top=100,left=300,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<body bgcolor=#CD9768 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><style>html,body{height:100%;margin:0px;padding:0px;font-family: Tahoma;font-size:10px;}td{padding:0px;font-size:11px;}input {font-size:10px;background-color:white;border:1px dotted black;}img{margin:0px;padding:0px;}</style>");
k.write("<table width=100% height=100%><tr><td align=center><a href='javascript:window.close();'><img border=0 vspace=0 hspace=0 src='/images/news/"+name+".jpg'></a></td></tr></table>");
k.close();
}
function max4(name)
{
var adresses = window.open("","AAAA", "height=570,width=800,top=0,left=100,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<body bgcolor=#CD9768 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><style>html,body{height:100%;margin:0px;padding:0px;}td{padding:0px;font-size:11px;}input {font-size:10px;background-color:white;border:1px dotted black;}img{margin:0px;padding:0px;}</style>");
k.write("<table width=100% height=100%><tr><td align=center><a href='javascript:window.close();'><img border=0 vspace=0 hspace=0 src='/images/"+name+".jpg'></a></td></tr></table>");
k.close();
}
function max(name)
{
var adresses = window.open("","AAAA", "height=520,width=420,top=100,left=300,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<style>a{font-size: 12px; font-face: verdana; color:#000099;}</style>");
k.write("<html><body bgcolor=#CC9966><a href='javascript:window.close()'><center><img align=center border=0 src='/images/"+name+"' border=0></a><center><a href='javascript:window.close()'>Закрыть</a></center>");
k.close();
}
function max5(name)
{
var adresses = window.open("","AAAA", "height=350,width=400,top=100,left=300,scrollbars=no,directories=no,dependent=yes,hotkeys=no,menubar=no,personalbar=no,toolbar=no,status=yes","replace");
var k = adresses.document;
k.open("text/html","replace");
k.write("<body bgcolor=#CD9768 topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><style>html,body{height:100%;margin:0px;padding:0px;font-family: Tahoma;font-size:10px;}td{padding:0px;font-size:11px;}input {font-size:10px;background-color:white;border:1px dotted black;}img{margin:0px;padding:0px;}</style>");
k.write("<table width=100% height=100%><tr><td align=center><a href='javascript:window.close();'><img border=0 vspace=0 hspace=0 src='/images/clients/big"+name+".jpg'></a></td></tr></table>");
k.close();
}

