/* (c) 2005 CaribMedia
* this module places IFRAME elements behind UL elements
* in order to prevent content to be placed
* on top of the dynamic menus
*/

/*
 * @name  addMenuEffects
 * @description places the IFRAME
 * preconditions:
 *  - there can be only one IFRAME
 *  - the menu has an id of "nav"
 *  - the menu is built as a nested list (UL/LI)
* - the script is run in IE
 * @author  Michiel van der Blonk
 * @date  Nov 22, 2005
*/

/* anonymous function wrapper, protects global namespace */
(function() {
	if (!document.getElementById)
		return;
	if (!window.MooTools)
		return;

	window.debugInfo = function(s) {
		if (!$('contentPane'))
    return;
		if (!window.debugmode)
			window.debugmode = true;
		else
			$('contentPane').innerHTML = '';
		$('contentPane').innerHTML += s;
	};

	var addMenuEffects = function(obj, doShim, doHover)
  {

		/* only in IE */
	  if (!cxlEnv.isIE5or6 || !obj)
			return;

	  var iframeCode = '<iframe class="menushim" src="about:blank" scrolling="no" frameborder="0"></iframe>';

    // add an IFRAME to all UL's in the menu,
    // this will make IE display the menu on top of all other elements
	  if (doShim)
    {
	    $(obj).getElements('ul').each(function(tag) {
	      tag.innerHTML=(iframeCode + tag.innerHTML);
	      //tag.addEvent('mouseover', function() {tag.addClass('over');});
	      //tag.addEvent('mouseout', function() {tag.removeClass('over');});
	    });
  }

		// resize the iframe
		$(obj).getElements('li ul').each(function(tag) {
			tag.addEvent('mouseenter', function() {
				tag.getElements('iframe')[0].setStyle('height', tag.clientHeight -1 + 'px');
			});
		 });
      };

/*
 * @name  startList
 * @description adds the menu effects for several menus
 * @author  Michiel van der Blonk
 * @date  Nov 22, 2005
*/
	var startList = function()
{
		['dynamicMenu', 'nav', 'subMenu'].each(function(item) {
				if ($(item))
	      	addMenuEffects($(item), true, true);
	  });
};

/*
 * @name  addEvent
 * @description adds an event handler to an element
 * this way multiple functions can be triggered by an event
 * @author  Michiel van der Blonk
 * @date  Nov 22, 2005
*/
	if (!window.addEvent)
	{
		window.addEvent = function(obj, evType, fn)
{
  var ret = false;
  // MB:check if fn exists
		  if (!fn || typeof fn != 'function')
    return false;
  // adds an eventListener for browsers which support it
  // Written by Scott Andrew: nice one, Scott
  if (obj.addEventListener)
  {
    obj.addEventListener(evType,fn,true);
    ret = true;
  }
  else
    if (obj.attachEvent)
    {
      var r = obj.attachEvent("on"+evType,fn);
      ret = r;
    }
  return ret;
		};
}

	var dragStuff = function()
{
	// if mootools is loaded, use the short version
		if (window.MooTools && $chk(Drag))
		$$('.drag').makeDraggable();
	else
	{
    if (!window.Drag || !document.getElementById)
      return;
		draggableItems = ['obj1', 'extra3'];
		for (var i=0; i < draggableItems.length; i++) {
			var dragger = document.getElementById(draggableItems[i]);
			if (dragger) {
				dragger.style.position = 'relative';
				Drag.init(dragger, null);
			}
		}
	}
	};

	// window.addEvent('load', startList);
	window.addEvent('load', dragStuff);
	window.addEvent('load', function(){setMenuCookie(-1);});
})();