document.menus = [];

function Menu (root_id) {
  this.root = document.getElementById(root_id);
  this.setup(this.root); }

Menu.prototype.setup = function (r) { 
  var c = r.childNodes;
  for (var i = 0; i < c.length; i++) {
    if (c[i].tagName == "A" && c[i].parentNode.tagName == "LI") {
      c[i].onmouseover = mMouOvrItm;
      c[i].onmouseout = mMouOutItm;
      c[i].getParents = mGetParents;
      var pli = c[i].parentNode;
      for (var j = 0; j < pli.childNodes.length; j++) {
        if (pli.childNodes[j].tagName == "UL")
        {
          c[i].m = pli.childNodes[j];
          c[i].m.p = c[i];
          c[i].m.style.visibility = "hidden";
          c[i].m.onmouseover = mMouOvrMnu;
          c[i].m.onmouseout = mMouOutMnu;
          c[i].ptr = document.menus.length;

          c[i].hide = mHide;
          document.menus.push(c[i]);
          break;
        }
      }
    }
    this.setup( c[i] );
  }
}

function mMouOvrItm() {
  if (this.parentNode.className) {  
    this.parentNode.classNameOrig = this.parentNode.className;
    this.parentNode.className = this.parentNode.className + "-hover";
  }
  
    if (this.tOut) clearTimeout(this.tOut);

    var p = this.getParents();

    for (var i = 0; i < document.menus.length; i++) {
      var h = true;
      for (var j = 0; j < p.length; j++)
      	if (p[j] == document.menus[i].m) h = false;
      if (h) document.menus[i].hide();
    }

    if (this.m) { 
      this.m.style.visibility = "visible";
     }
}

function mMouOutItm() {
  
  if (this.parentNode.classNameOrig) {
    this.parentNode.className = this.parentNode.classNameOrig;
    this.parentNode.classNameOrig = null;
  }
  if (this.m)
    this.tOut = setTimeout("document.menus["+this.ptr+"].hide()",2000);
}

function mMouOvrMnu() {
  if (this.p.tOut) clearTimeout(this.p.tOut);
}

function mMouOutMnu() {
  this.p.onmouseout();
}

function mHide(p) {
  this.m.style.visibility = "hidden";
}

function mGetParents() {
  var a = [];
  var p = this.parentNode;
  while (p) {
     if (p.tagName=='UL')
     	a.push(p);
     p = p.parentNode;
  }
  return a;
}

/*

function swfShow() {
  var swfs = document.getElementsByTagName('object');
  for(var i = 0; i < swfs.length; i++) {
    swfs[i].style.visibility = "visible";
  }
}

function swfHide() {
  if (document.swfOn) clearTimeout(document.swfOn)
  var swfs = document.getElementsByTagName('object');
  for(var i = 0; i < swfs.length; i++) {
    swfs[i].style.visibility = "hidden";
  }
}
*/

/* This replaces media place holder images with mediaplayers */

// CM6 mediaplayer initialization
if(null != window.jQuery) {
	var jQuery = window.jQuery;
	(function ($) {
	 	$(
	 		function()
	 		{
	 			$("img.mediaHolder").each(
	 				function (index) {
	 					var a = this.id.split('|');
						var playerType = a[0];
						var src = a[1];
						var id = "media_"+index;
						var w = this.width;
						var h = this.height
					
						var div = $('<div class="mediaholder"></div>').css({ width:w+"px", height:h+"px", display:'inline' });
					
						$(this).hide();
						$(this).before( div );
						
					try {
						switch ( playerType )
						{
							case "flash" :
								div.html( new SWFObject(src, id, w, h, 8).getSWFHTML () );							
								break;
							case "mediaplayer" :
							case "youtube" :
								var mp = new SWFObject("/js/ced/lib/player.swf",id,w,h,9);
								mp.addParam("allowfullscreen","true");
								mp.addVariable("width",w);
								mp.addVariable("height",h);
								mp.addVariable("file",src);
								div.html(mp.getSWFHTML());
								break;
							case "wmvplayer" :
								new jeroenwijering.Player(div.get(0), '/js/ced/lib/wmvplayer.xaml', { file : src, height : h+"", width : w+"" } );
								break;
						}
					} catch (error) {
							alert("Error embedding media player for "+playerType+" : "+src+"\n"+error);
					}
			
					
	 				}
	 			
	 			);
	 		}
	 	
	 	)
	 })(jQuery);
	jQuery.noConflict();
}