/** ********************************
 * 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();
/*
   var master = elemById('master');
   var header = elemById('header');
   var headerHeight = 180;
   var footerHeight = elemById('footer').offsetHeight;
   var kolomlinks = elemById('left_frame');
   var kolomlinkscontent = elemById('left_content');
   var kolomrechts = elemById('right_frame');
   var kolomrechtsspacer = elemById('right_spacer');
   var kolomrechtscontent = elemById('right_content');
   var contentblok = elemById('body');
   var contentframe = elemById('content_frame');
   var windowHeight = measure('window').y;
   var remainingHeight = windowHeight - headerHeight - footerHeight;
   var kolomrechtscontentoffsetheight;

   var maxColumnHeight = Math.max(kolomlinks.offsetHeight, kolomrechts.offsetHeight, contentframe.offsetHeight);
   if ((headerHeight + maxColumnHeight + footerHeight) > windowHeight)
   {
      box.set('this site be too big');
   }

   box.set(master.offsetHeight);
   box.set(windowHeight);
   box.set(master.offsetHeight > windowHeight? 'site is bigger':' site is smaller')

   if(kolomrechtscontent) {
      kolomrechtscontentoffsetheight = kolomrechtscontent.offsetHeight;
   } else {
      kolomrechtscontentoffsetheight = 0;
   }

   //--[ get amount off banners ]--
   var arrBanners = elemsByClass('right_banner');
   banner_height = 180;
   if(arrBanners.length == 1) {
      banner_height = 86;
   } else if(arrBanners.length == 2) {
      banner_height = 180;
   }

   //kolomlinks.style.height = remainingHeight + 'px';
   //kolomlinkscontent.style.height = remainingHeight - 23 + 'px';
   kolomrechts.style.height = remainingHeight + 10 + 'px';
   kolomrechtsspacer.style.height = remainingHeight - 23 - banner_height - kolomrechtscontentoffsetheight + 'px';

   contentblok.style.height = remainingHeight + 'px';
   contentframe.style.height = remainingHeight + 'px';
*/

}

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;
   //bannerlink.href = arrBannerLink[counter[i]];
}

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]];
   //bannerform.action = arrBannerURL[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) { //getStyleValue(activeMenu, 'margin-left', true) > 0
            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;
}
