// -----------------------------------------------------------------------------
var curBanner = null;
var DDSPEED = 6;
var DDTIMER = 1;

function ddMenu(id,d){

  var h = document.getElementById('m_' + id);
  var c = document.getElementById('sm_' + id);

  if (d == 1)
      ddmouseover('m_' + id);
  else if (d == -1)
      ddmouseout('m_' + id);

  if (c != null) {

      clearInterval(c.timer);
      if(d == 1) {

        clearTimeout(h.timer);
        if(c.maxh && c.maxh <= c.offsetHeight){
            return
        } else if(!c.maxh){

          c.style.display = 'block';
          c.style.height = 'auto';
          c.maxh = c.offsetHeight;
          c.style.height = '0px';

        }

        c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);

      }else{
        h.timer = setTimeout(function(){ddCollapse(c)},50);
      }

  }

}

function ddSlide(c,d){

  var currh = c.offsetHeight;
  var dist;

  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }

  if(dist <= 1 && d == 1){
    dist = 1;
  }

  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';

  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }

}

function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

function cancelHide(id){

  var h = document.getElementById('m_' + id);
  var c = document.getElementById('sm_' + id);

  clearTimeout(h.timer);
  if (c != null) {

    clearInterval(c.timer);
    if(c.offsetHeight < c.maxh){
        c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
    }

  }

}

function ddmouseover(id, pid) {

    obj = document.getElementById(id);
    if (obj != null) {

        var style = getStyle(".menulink_hover");
        if (style != null) {
            obj.style.backgroundColor = style.style.backgroundColor;
            obj.style.color = style.style.color;
            if (pid != null && (pobj = document.getElementById(pid)) != null) {
                pobj.style.backgroundColor = style.style.backgroundColor;
                pobj.style.color = style.style.color;
            }
        }

    }

}

function ddmouseout(id, pid) {

    obj = document.getElementById(id);
    if (obj != null) {

        var style = getStyle(".menulink_std");
        if (style != null) {
            obj.style.backgroundColor = style.style.backgroundColor;
            obj.style.color = style.style.color;
            if (pid != null && (pobj = document.getElementById(pid)) != null) {
                pobj.style.backgroundColor = style.style.backgroundColor;
                pobj.style.color = style.style.color;
            }
        }

    }

}

function ddonclick(id) {

    var event = null;
    for (a = 0; a < MENU_EVENTS.length; ++a) {

        obj = MENU_EVENTS[a];
        if (obj['ID'] == id) {
            event = obj;
            break;
        }

    }

    if (event != null) {

        url = 'subpage';
        if (event['ISLANG']) {
            url += "_" + locale;
        }
        url += "/" + event['URL'];

        if (id.substr(0, 3) == 'sm_') {
            xx = id.split("_");
            ddMenu(xx[1],-1);
        }

        if (event['BANNER'] != null && event['BANNER'] != "") {
            if (curBanner == null)
                curBanner = new Banner(event['BANNER']);
            else
                curBanner.change(event['BANNER']);
        }

        if (event['ARGS'] != null) {
            createArgumentCall(url, 'main', event['ARGS']);
        } else {
            createCall(url, 'main', null);
        }

    }

}

function ddonclick(id, args) {

    var event = null;
    for (a = 0; a < MENU_EVENTS.length; ++a) {

        obj = MENU_EVENTS[a];
        if (obj['ID'] == id) {
            event = obj;
            break;
        }

    }

    if (event != null) {

        url = 'subpage';
        if (event['ISLANG']) {
            url += "_" + locale;
        }
        url += "/" + event['URL'];

        if (id.substr(0, 3) == 'sm_') {
            xx = id.split("_");
            ddMenu(xx[1],-1);
        }

        if (event['BANNER'] != null && event['BANNER'] != "") {
            if (curBanner == null)
                curBanner = new Banner(event['BANNER']);
            else
                curBanner.change(event['BANNER']);
        }

        if (event['ARGS'] != null) {
            createExtraArgumentCall(url, 'main', event['ARGS'], args);
        } else {
            createExtraArgumentCall(url, 'main', null, args);
        }

    }

}