//20080319.022
var KK = {
  scriptName: "/index.php",
  kuoteBoxFadeInterval: null,
  menuHitBestTimeout: null,

  /*---------------------------------------------------------------------------
  - Method: createXHR
  ---------------------------------------------------------------------------*/
  createXHR: function() {
    try {
      var XHR;
      if(window.XMLHttpRequest) XHR = new XMLHttpRequest();
      else if(window.ActiveXObject) XHR = new ActiveXObject("Microsoft.XMLHTTP");
      return XHR;
    } catch(e) { }
  },

  /*---------------------------------------------------------------------------
  - Method: addEvent
  ---------------------------------------------------------------------------*/
  addEvent: function(elementTarget, eventType, functionHandler) {
    try {
      if(elementTarget.addEventListener) elementTarget.addEventListener(eventType, functionHandler, false);
      else if(elementTarget.attachEvent) elementTarget.attachEvent("on" + eventType, functionHandler);
      else elementTarget["on" + eventType] = functionHandler;
    } catch(e) { }
  },

  /*---------------------------------------------------------------------------
  - Method: checkLogin
  ---------------------------------------------------------------------------*/
  checkLogin: function(userField, passField) {
    var objs = new Array(userField, passField);
    for(i in objs) {
      if(document.getElementById(objs[i]).value.length < 1) {
        document.getElementById(objs[i]).select();
        document.getElementById(objs[i]).focus();
        return false;
      }
    }
    return true;
  },

  /*---------------------------------------------------------------------------
  - Method: getRandomKuote
  ---------------------------------------------------------------------------*/
  getRandomKuoteForHeader: function() {
    var kuoteBox = document.getElementById("randomKuoteBox");
    try {
      var rkXHR = KK.createXHR();
      rkXHR.open("GET", KK.scriptName + "?acmd=getRandomKuoteForHeader", false);
      rkXHR.send(null);
      kuoteBox.innerHTML = rkXHR.responseText;
      KK.setAlpha(kuoteBox, 0.05);
      KK.kuoteBoxFadeInterval = setInterval(function() { KK.kuoteBoxFade(); }, 100);
    } catch(e) { }
  },

  /*---------------------------------------------------------------------------
  - Method: kuoteBoxFade
  ---------------------------------------------------------------------------*/
  kuoteBoxFade: function() {
    var kuoteBox = document.getElementById("randomKuoteBox");
    var curAlpha = parseFloat(kuoteBox.style.MozOpacity);
    if(curAlpha < 1.00) {
      curAlpha = curAlpha + 0.13;
      KK.setAlpha(kuoteBox, curAlpha);
    } else {
      clearInterval(KK.kuoteBoxFadeInterval);
    }
  },

  /*---------------------------------------------------------------------------
  - Method: setAlpha
  ---------------------------------------------------------------------------*/
  setAlpha: function(obj, alpha) {
    obj.style.MozOpacity = alpha;
    obj.style.filter = "alpha(opacity=" + (alpha * 100) + ")";
    obj.style.Opacity = alpha;
  },

  /*---------------------------------------------------------------------------
  - Method: menuHitBestOver
  ---------------------------------------------------------------------------*/
  menuHitBestOver: function() {
    clearTimeout(KK.menuHitBestTimeout);
    document.getElementById("menuHitBestRoll").style.display = "block";
    document.getElementById("menuHitBest").style.display = "none";
  },

  /*---------------------------------------------------------------------------
  - Method: menuHitBestOut
  ---------------------------------------------------------------------------*/
  menuHitBestOut: function() {
    KK.menuHitBestTimeout = setTimeout(function() { KK.menuHitBestOutExec(); }, 1000);
  },

  /*---------------------------------------------------------------------------
  - Method: menuHitBestOutExec
  ---------------------------------------------------------------------------*/
  menuHitBestOutExec: function() {
    document.getElementById("menuHitBest").style.display = "block";
    document.getElementById("menuHitBestRoll").style.display = "none";
  },

  /*---------------------------------------------------------------------------
  - Method: popupAddComment()
  ---------------------------------------------------------------------------*/
  popupExec: function(content, setAction, XParam1) {
    var ajaxCommand = "";
    switch(content) {
      case "addComment":
        ajaxCommand = "getAddCommentPopupHtmlCode";
        break;
      case "sendPrivateMessage":
        ajaxCommand = "getSendPrivateMessagePopupHtmlCode";
        break;
    }
    if(ajaxCommand == "") return;
    KK.showPopupContainer();
    var popup = document.getElementById("popupContainer");
    try {
      var popupXHR = KK.createXHR();
      var params = "action=" + setAction + "&XParam1=" + XParam1;
      popupXHR.open("POST", KK.scriptName + "?acmd=" + ajaxCommand, false);
      popupXHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      popupXHR.send(params);
      popup.innerHTML = popupXHR.responseText;
    } catch(e) { }
  },

  /*---------------------------------------------------------------------------
  - Method: init
  ---------------------------------------------------------------------------*/
  showPopupContainer: function() {
    var innerWidth = parseInt((window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth) - 30;
    var innerHeight = parseInt((window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight);
    var pageYOffset = parseInt((window.innerWidth) ? window.pageYOffset : document.documentElement.scrollTop);
    var popup = document.getElementById("popupContainer");
    var popupGnd = document.getElementById("popupContainerGnd");
    popupGnd.style.width = innerWidth + "px";
    popupGnd.style.height = innerHeight + "px";
    popupGnd.style.top = pageYOffset + "px";
    popup.style.top = (pageYOffset + ((innerHeight - 350) / 2)) + "px";
    popup.style.left = ((innerWidth - 500) / 2) + "px";
    popup.style.display = popupGnd.style.display = "block";
    KK.setAlpha(popupGnd, 0.8);
  },

  /*---------------------------------------------------------------------------
  - Method: init
  ---------------------------------------------------------------------------*/
  init: function() {
    //Check if the browser is DOM compliant
    if(!document.getElementById) {
      alert("Browser too old!");
      return;
    }
    setInterval("KK.getRandomKuoteForHeader()", 30000);
  }
}

KK.addEvent(window, "load", KK.init);