/* ©2008-2009 www.araujoengenharia.com.br; desenvolvido por iD Studio - www.idstudio.art.br */

var Images = [];

function preload(src, w, h) {
  var _i;
  if (!document.images) return false;
  _i = new Image(w, h);
  _i.src = src;
  Images.push(_i);
  return Images.length - 1;
}
function getObj(_o) { return typeof _o == "object" ? _o : document.getElementById(_o); }
function getOffset(el, attribute) {
  var amount = 0;
  while (el.nodeName != "HTML") {
    if ((el = el.parentNode).className == "wrapper") continue;
    amount += el[attribute];
  }
  return amount;
}
function InputFocus(e) { if (e.value == e.defaultValue) return void(e.value = ""); }
function InputBlur(e) { if (!e.value) return void(e.value = e.defaultValue); }
Array.prototype.last = function() { return this[this.length - 1]; }
function debug(msg) { document.getElementById("Page").innerHTML = "<p>" + msg.replace(/\n/g, "<br />") + "</p>" + document.getElementById("Page").innerHTML; }


// M E N U


var IE = /MSIE/.test(navigator.userAgent), Menu = [null], ActiveMenu = null, MenuDelay = 300, MenuFate = null, MenuDir = "H", MenuOffsetLeft = 0, MenuOffsetTop = -6;
// menu.state = 0 (off), 1 (on but lost focus), 2 (on and with focus); menu.menuDir = false (horizontal), true (vertical)

function GetMenu(id) {
  // Accepts - id : object, id, menuId
  var o = {submenu : Menu}, j = 100;
  if (!parseInt(id)) return (o = getObj(id)) ? (o.menuId ? o : null) : null;
  id = parseInt(id);
  while (j < id) j *= 100;
  for (; j >= 100 && o; j /= 100) o = o.submenu[Math.floor(id / (j / 100)) - (Math.floor(id / j) * 100)];
  return o;
}

function RegisterMenu(obj, parentMenu, onScript, offScript) {
  // Accepts - obj : object, id; parentMenu : object, id, menuId; onScript/offScript : function, string
  var ancestor = obj = getObj(obj), count = 1;
  if (!obj) return false;
  if (obj.menuId) return obj.menuId;
  obj.parentMenu = GetMenu(parentMenu) || null;
  obj.state = 0;
  obj.menuDir = String(MenuDir).toUpperCase().indexOf("V") == 0 || parseFloat(MenuDir) || MenuDir === true ? true : false;
  obj.submenu = [obj.caller = null];
  obj.menuOffsetLeft = MenuOffsetLeft;
  obj.menuOffsetTop = MenuOffsetTop;
  obj.onshow = typeof onScript == "function" ? onScript : (onScript ? eval("obj.onshow = function() {\n  " + onScript + "\n}") : null);
  obj.onhide = typeof offScript == "function" ? offScript : (offScript ? eval("obj.onhide = function() {\n  " + offScript + "\n}") : null);
  obj.menuId = obj.menuNumber = (obj.parentMenu ? obj.parentMenu.submenu : Menu).push(obj) - 1;
  while (ancestor.parentMenu) obj.menuId += (ancestor = ancestor.parentMenu).menuNumber * Math.pow(100, count++);
  return obj.menuId;
}


function UseMenu(m, state, e) {
  // Accepts - m : object, id, menuId; state : anything; e : object, id
  var x, y;
  if (state && !(e = getObj(e))) return false;
  if (!(m = GetMenu(m))) {
    if (ActiveMenu) {
	m = ActiveMenu;
	state = false;
    } else return false;
  }
  if (state) {
    if (m.state) return CheckMenu(m, true);
    if (ActiveMenu) {
	if (ActiveMenu == m.parentMenu) clearTimeout(MenuFate);
	else {
	  x = ActiveMenu.parentMenu && ActiveMenu.parentMenu == m.parentMenu;
	  if (x) m.parentMenu.state = 2;
	  UseMenu(ActiveMenu, false);
	  if (x) m.parentMenu.state = 1;
	}
    }
    x = e.offsetLeft + (IE && !m.parentMenu ? getOffset(e, "offsetLeft") : 0) + m.menuOffsetLeft + (m.menuDir ? e.clientWidth : 0) + (m.parentMenu ? parseInt(m.parentMenu.style.left) : 0);
    if (document.body.parentNode.offsetWidth + document.body.parentNode.scrollLeft < x + (IE ? m.clientWidth : m.offsetWidth)) x -= (IE ? m.clientWidth : m.offsetWidth) + (m.menuDir ? e.offsetWidth : 0) - (m.menuOffsetLeft * 2);
    y = e.offsetTop + (IE && !m.parentMenu ? getOffset(e, "offsetTop") : 0) + m.menuOffsetTop + (m.menuDir ? 0 : e.clientHeight) + (m.parentMenu ? parseInt(m.parentMenu.style.top) + e.parentNode.offsetTop : 0);
    m.caller = e;
    e.className += " hover";
    m.style.left = x + "px";
    m.style.top = y + "px";
    m.state = 2;
    ActiveMenu = m;
    m.style.visibility = "visible";
    if (m.onshow) m.onshow();
  } else {
    while (m.state == 1) {
	m.state = 0;
	clearTimeout(MenuFate);
	if (m.onhide) m.onhide();
	m.style.visibility = "hidden";
	if (m.caller) m.caller.className = m.caller.className.replace("hover", "");
	m.caller = null;
	if (m.parentMenu) ActiveMenu = m = m.parentMenu;
	else ActiveMenu = null;
    }
  }
  return true;
}

function CheckMenu(m, state) {
  // Accepts - m : object, id, menuId; state : anything
  if (!(m = GetMenu(m))) return false;
  if (state) {
    m.state = 2;
    clearTimeout(MenuFate);
    if (ActiveMenu.menuId != m.menuId) UseMenu(ActiveMenu, false);
  } else {
    m.state = 1;
    MenuFate = setTimeout("UseMenu(" + m.menuId + ", false);", MenuDelay);
  }
  return true;
}


// B U Z Z E R


var ImageObj = null, ImageSetCount = 0, ImageSetName = "", ImageSetExtension = "", ImageSetTimer = null, SwitchInterval = 5000, SwitchStop = false, CurrentImage = 0, SwitchRandom = false, ImageSetWidth = 746, ImageSetHeight = 275;

function SetupBuzzer(name, ext, count) {
  var i = 1;
  ImageObj = document.getElementById("Buzzer");
  ImageSetName = name;
  ImageSetExtension = ext;
  ImageSetCount = count = parseInt(count);
  for (; i <= count; i++) preload(name + i + "." + ext, ImageSetWidth, ImageSetHeight);
  SwitchBuzzer();
  ImageSetTimer = setInterval("SwitchBuzzer()", SwitchInterval);
}

function SwitchBuzzer(s) {
  if (typeof s != "undefined") SwitchStop = Boolean(s);
  if (SwitchStop) return clearInterval(ImageSetTimer);
  if (SwitchRandom) CurrentImage = Math.ceil(Math.random() / (1 / ImageSetCount));
  else if (++CurrentImage > ImageSetCount) CurrentImage = 1;;
  ImageObj.style.backgroundImage = "url(\"" + ImageSetName + CurrentImage + "." + ImageSetExtension + "\")";
}


// S C R A M B L E R


function es2(txt, a2, a3, a1, css) {
  var _2 = "&#64;", _d = "&#46;", _lt = "<", _gt = ">";
  return _lt + "a" + " hr" + "ef" + "=\"&#109;&#97;" + "&#105;&#108;" + "&#116;&#111;" + "&#58;" + a1 + _2 + a2 + _d + a3 + "\"" + (css ? " class=\"" + css + "\"" : "") + _gt + (txt ? txt : a1 + _2 + a2 + _d + a3) + _lt + "/a" + _gt;
}
