var STICKY    =  3;
var LEFT    =  7;
var RIGHT    =  8;
var CENTER    =  9;
var OFFSETX    =  10;
var OFFSETY    =  11;
var WIDTH    =  17;
var STATUS    =  19;
var AUTOSTATUS    =  20;
var AUTOSTATUSCAP  =  21;
var HEIGHT    =  22;
var SNAPX    =  24;
var SNAPY    =  25;
var FIXX    =  26;
var FIXY    =  27;
var ABOVE    =  33;
var BELOW    =  34;
var FRAME    =  42;
var TIMEOUT    =  43;
var DELAY    =  45;
var HAUTO    =  46;
var VAUTO    =  47;

if (typeof ol_width == 'undefined') { var ol_width = "-1";}
if (typeof ol_offsetx == 'undefined') { var ol_offsetx = 10;}
if (typeof ol_offsety == 'undefined') { var ol_offsety = 10;}
if (typeof ol_cap == 'undefined') { var ol_cap = ""; }
if (typeof ol_sticky == 'undefined') { var ol_sticky = 0; }
if (typeof ol_hpos == 'undefined') { var ol_hpos = RIGHT; }
if (typeof ol_status == 'undefined') { var ol_status = ""; }
if (typeof ol_autostatus == 'undefined') { var ol_autostatus = 0; }
if (typeof ol_height == 'undefined') { var ol_height = -1; }
if (typeof ol_snapx == 'undefined') { var ol_snapx = 0; }
if (typeof ol_snapy == 'undefined') { var ol_snapy = 0; }
if (typeof ol_fixx == 'undefined') { var ol_fixx = -1; }
if (typeof ol_fixy == 'undefined') { var ol_fixy = -1; }
if (typeof ol_vpos == 'undefined') { var ol_vpos = BELOW; }
if (typeof ol_aboveheight == 'undefined') { var ol_aboveheight = 0; }
if (typeof ol_frame == 'undefined') { var ol_frame = self; }
if (typeof ol_timeout == 'undefined') { var ol_timeout = 0; }
if (typeof ol_delay == 'undefined') { var ol_delay = 0; }
if (typeof ol_hauto == 'undefined') { var ol_hauto = 0; }
if (typeof ol_vauto == 'undefined') { var ol_vauto = 0; }

// INIT
var o3_cap = "";
var o3_sticky = 0;
var o3_hpos = RIGHT;
var o3_offsetx = 2;
var o3_offsety = 2;
var o3_width = 100;
var o3_status = "";
var o3_autostatus = 0;
var o3_height = -1;
var o3_snapx = 0;
var o3_snapy = 0;
var o3_fixx = -1;
var o3_fixy = -1;
var o3_vpos = BELOW;
var o3_aboveheight = 0;
var o3_frame = self;
var o3_timeout = 0;
var o3_timerid = 0;
var o3_allowmove = 0;
var o3_delay = 0;
var o3_delayid = 0;
var o3_hauto = 0;
var o3_vauto = 0;


// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_allow = 0;
var o3_showingsticky = 0;
var o3_removecounter = 0;

// Our layer
var over = null;

// Our layer
var over = null;


// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;

// DMB Support
var IsDMB = (typeof(cFrame)!="undefined");


// Microsoft Stupidity Check(tm).
if (ie4) {
  if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
    ie5 = true;
  }
  if (ns6) {
    ns6 = false;
  }
}


// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) || (ns6)) {
  if(IsDMB) mFrame.onmousemove = mouseMove;
  document.onmousemove = mouseMove;
} else {
  overlib = no_overlib;
  nd = no_overlib;
  ver3fix = true;
}


// Fake function for 3.0 users.
function no_overlib() {
  return ver3fix;
}


function overlib(str_tab, str_img, str_txt) {
  if ( (ns4) || (ie4) || (ns6) ) {
    o3_frame = ol_frame;
    if (ns4) over = o3_frame.document.overDiv
    if (ie4) over = o3_frame.overDiv.style
    if (ns6) over = o3_frame.document.getElementById("overDiv");
  }
  return overlib350(str_tab, str_img, str_txt);
}


function overlib350(str_tab, str_img, str_txt) {
  var layerhtml;

  layerhtml = ol_content_simple(str_tab, str_img, str_txt);

  if (o3_sticky) {
    o3_showingsticky = 1;
    o3_removecounter = 0;
  }

  layerWrite(layerhtml);

  if (o3_autostatus > 0) {
    if (o3_autostatus > 1) {
      o3_status = o3_cap;
    }
  }

  o3_allowmove = 0;

  if (o3_timeout > 0) {
    if (o3_timerid > 0) clearTimeout(o3_timerid);
    o3_timerid = setTimeout("cClick()", o3_timeout);
  }

  disp(o3_status);

  if (o3_sticky) {
    o3_allowmove = 0;
    return false;
  } else {
    return true;
  }
}

// LAYER GENERATION FUNCTIONS
function ol_content_simple(str_tab, str_img, str_txt) {
  var s_tab, s_img, s_txt;
  if (str_tab != "") {
    s_tab = "<TABLE "+str_tab+"><TR>";
    }
    else
    s_tab = "<TABLE><TR>";

  if (str_img != "") {
    s_img = "<TD VALIGN=MIDDLE><img border=0 src='"+str_img+"'></TD>";
    }
    else
    s_img = "";

  if (str_txt != "") {
    s_txt = "<TD>"+str_txt+"</TD>";
    }
    else
    s_txt = "";

  txt = s_tab+s_img+s_txt+"</TR></TABLE>";
  return txt;
}




// HANDLING FUNCTIONS


function disp(statustext) {
  if ( (ns4) || (ie4) || (ns6) ) {
    if (o3_allowmove == 0)   {
      placeLayer();
      showObject(over);
      o3_allowmove = 1;
    }
  }
}


function placeLayer() {
  var placeX, placeY;

  if (o3_fixx > -1) {
    placeX = o3_fixx;
  } else {
    winoffset = (ie4) ? o3_frame.document.body.scrollLeft : o3_frame.pageXOffset;
    if (ie4) iwidth = o3_frame.document.body.clientWidth;
    if (ns4) iwidth = o3_frame.innerWidth;
    if (ns6) iwidth = o3_frame.outerWidth;

    if (o3_hauto == 1) {
      if ( (o3_x - winoffset) > ((eval(iwidth)) / 2)) {
        o3_hpos = LEFT;
      } else {
        o3_hpos = RIGHT;
      }
    }

    if (o3_hpos == CENTER) { // Center
      placeX = o3_x+o3_offsetx-(o3_width/2);
    }
    if (o3_hpos == RIGHT) { // Right
      placeX = o3_x+o3_offsetx;
      if ( (eval(placeX) + eval(o3_width)) > (winoffset + iwidth) ) {
        placeX = iwidth + winoffset - o3_width;
        if (placeX < 0) placeX = 0;
      }
    }
    if (o3_hpos == LEFT) { // Left
      placeX = o3_x-o3_offsetx-o3_width;
      if (placeX < winoffset) placeX = winoffset;
    }

    if (o3_snapx > 1) {
      var snapping = placeX % o3_snapx;
      if (o3_hpos == LEFT) {
        placeX = placeX - (o3_snapx + snapping);
      } else {
        // CENTER and RIGHT
        placeX = placeX + (o3_snapx - snapping);
      }
      if (placeX < winoffset) placeX = winoffset;
    }
  }

  if (o3_fixy > -1) {
    placeY = o3_fixy;
  } else {
    scrolloffset = (ie4) ? o3_frame.document.body.scrollTop : o3_frame.pageYOffset;

    if (o3_vauto == 1) {
      if (ie4) iheight = o3_frame.document.body.clientHeight;
      if (ns4) iheight = o3_frame.innerHeight;
      if (ns6) iheight = o3_frame.outerHeight;

      iheight = (eval(iheight)) / 2;
      if ( (o3_y - scrolloffset) > iheight) {
        o3_vpos = ABOVE;
      } else {
        o3_vpos = BELOW;
      }
    }

    if (o3_vpos == ABOVE) {
      if (o3_aboveheight == 0) {
        var divref = (ie4) ? o3_frame.document.all['overDiv'] : over;
        o3_aboveheight = (ns4) ? divref.clip.height : divref.offsetHeight;
      }

      placeY = o3_y - (o3_aboveheight + o3_offsety);
      if (placeY < scrolloffset) placeY = scrolloffset;
    } else {
      placeY = o3_y + o3_offsety;
    }

    if (o3_snapy > 1) {
      var snapping = placeY % o3_snapy;

      if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
        placeY = placeY - (o3_snapy + snapping);
      } else {
        placeY = placeY + (o3_snapy - snapping);
      }
      if (placeY < scrolloffset) placeY = scrolloffset;
    }
  }
  repositionTo(over, placeX, placeY);
}

function mouseMove(e) {
  if ((ns4) || (ns6)) {o3_x=e.pageX; o3_y=e.pageY;}
  if (ie4) {o3_x=event.x; o3_y=event.y;}
  if (ie5) {o3_x=event.x+o3_frame.document.body.scrollLeft; o3_y=event.y+o3_frame.document.body.scrollTop;}

  if (o3_allowmove == 1) {
    placeLayer();
  }
  if(IsDMB) cFrame.HideMenus(e);
}


function cClick() {
  hideObject(over);
  o3_showingsticky = 0;
  return false;
}


function compatibleframe(frameid) {
  if (ns4) {
    if (typeof frameid.document.overDiv =='undefined') return false;
  } else if (ie4) {
    if (typeof frameid.document.all["overDiv"] =='undefined') return false;
  } else if (ns6) {
    if (frameid.document.getElementById('overDiv') == null) return false;
  }

  return true;
}

// LAYER FUNCTIONS
function layerWrite(txt) {
  txt += "\n";

        if (ns4) {
                var lyr = o3_frame.document.overDiv.document

                lyr.write(txt)
                lyr.close()
        } else if (ie4) {
    o3_frame.document.all["overDiv"].innerHTML = txt
  } else if (ns6) {
    range = o3_frame.document.createRange();
    range.setStartBefore(over);
    domfrag = range.createContextualFragment(txt);
    while (over.hasChildNodes()) {
      over.removeChild(over.lastChild);
    }
    over.appendChild(domfrag);
  }
}

function showObject(obj) {
        if (ns4) obj.visibility = "show";
        else if (ie4) obj.visibility = "visible";
  else if (ns6) obj.style.visibility = "visible";
}

function hideObject(obj) {
        if (ns4) obj.visibility = "hide";
        else if (ie4) obj.visibility = "hidden";
  else if (ns6) obj.style.visibility = "hidden";

  if (o3_timerid > 0) clearTimeout(o3_timerid);
  if (o3_delayid > 0) clearTimeout(o3_delayid);
  o3_timerid = 0;
  o3_delayid = 0;
        self.status = "";
}

function repositionTo(obj,xL,yL) {
  if ( (ns4) || (ie4) ) {
          obj.left = xL;
          obj.top = yL;
  } else if (ns6) {
    obj.style.left = xL + "px";
    obj.style.top = yL+ "px";
  }
}


function nd() {
  if ( o3_removecounter >= 1 ) { o3_showingsticky = 0 };
  if ( (ns4) || (ie4) || (ns6) ) {
    if ( o3_showingsticky == 0 ) {
      o3_allowmove = 0;
      if (over != null) hideObject(over);
    } else {
      o3_removecounter++;
    }
  }
  return true;
}


