/** ********************************
 * file:       main.js
 * author:     Floris Gaisser
 * created:    30-mar-2006 16:09
 *
 * edit history:
 *
 *
 */


window.onload = Load;
window.onresize = Load;
var box;
var showing;

function Load()
{
   //if (!box) box = outputBox();

   setMenu();
}

function changeBanner(i) {
   var banner = elemById('banner'+i);
   var bannerlink = elemById('banner_link'+i);
   counter[i]++;
      if (counter[i] > arrBanner.length - 1) {
         counter[i] = 0;
      }
   banner.src = arrBanner[counter[i]].src;
}

function changeFormBanner(i) {
   var banner = elemById('banner'+i);
   var bannerid = elemById('bannerid'+i);
   var bannerform = elemById('bannerform'+i);
   counter[i]++;
      if (counter[i] > arrBanner.length - 1) {
         counter[i] = 0;
      }
   banner.src = arrBanner[counter[i]].src;
   bannerid.value = arrBannerID[counter[i]];
}

function submitForm(formid) {
   var bannerform = elemById(formid);
   bannerform.submit();
}

function alterOffset(newValue) {
   var elOffset = elemById('offset');
   elOffset.setAttribute('value',newValue);
}

//--[ show/hide functions ]--
function show(idName) {
   if(!isUndefined(showing)) {
      hide(showing);
   }
   showBlock = elemById(idName);
   showBlock.style.display = 'block';
   showing = idName;
   return false;
}

function hide(idName) {
   try {
      elemById(idName).style.display = 'none';
   } catch(e) {}
   showing = null;
}


//--[ roll down menu functions ]--
var activeMenu = null;
var activeMenuItem = null;
var hideTimer;
var showTimer;
function setMenu() {
   var arrMenuItems = elemsByClass('nav_item');

   for(var i=0; i < arrMenuItems.length; i++) {
      arrMenuItems[i].onmouseover = function () {
         clearTimeout(hideTimer);
         hideMenu();

         subMenu = elemById('nav_sub_menu_' + this.name);

         showTimer = setTimeout('showMenu();',500);

         activeMenu = subMenu;
         activeMenuItem = this;
      }

      arrMenuItems[i].onmouseout = function () {
         clearTimeout(showTimer);
         hideTimer = setTimeout('hideMenu();',500);
      }

      listen(document,'click',hideMenu);
   }
}

function hideMenu() {
   clearTimeout(showTimer);
   if (activeMenu) {
      activeMenu.style.display = 'none';
   }
}

function showMenu() {
   clearTimeout(hideTimer);
   if (activeMenu) {
      if (activeMenuItem) {
         activeMenu.style.display = 'block';
         if(navigator.appVersion.indexOf("MSIE")>-1) {
            activeMenu.style.marginLeft = elemById('master').offsetLeft + 5 + 'px';
         }else{
            activeMenu.style.marginLeft = '5px';
         }
         activeMenu.style.left = activeMenuItem.offsetLeft + 'px';


         activeMenu.onmouseover = function () {
            clearTimeout(hideTimer);
            hideMenu();
            activeMenu = this;
            this.style.display = 'block';
         }

         activeMenu.onmouseout = function () {
            hideTimer = setTimeout('hideMenu();',500);
         }
      }
   }
}

//simple showHide
function showHide(id,state)
{
	if (state == 'hide')
		Style(id).display = 'none';
	else if (state == 'show')
		Style(id).display = 'block';

	return false;
}

