var idList = new Array("block-tree_menus-1");

function initMenu() {
  for (var k = 0; k < idList.length; k++) {
    var nodes = document.getElementById(idList[k]).getElementsByTagName("li");
    for (var i=0; i<nodes.length; i++)
    {
      nodes[i].onmouseover = function()
      {
        $(this).className += " hover";
      }
      nodes[i].onmouseout = function()
      {
        this.className = this.className.replace(" hover", "");
      }
    }
  }
}
if (document.all && !window.opera) attachEvent("onload", initMenu);

// flash animation in menu
var backgrounds={};
$(document).ready(function() {
  replace_menu_background($('.tree-menu.menu-1 li.active,.tree-menu.menu-1 li.expanded'));

  // hover functions for main menu items
  $('.tree-menu.menu-1 li').hover(
    function() {
      // if menu is active, do nothing
      if ($(this).hasClass('active')) return;
      
      replace_menu_background(this);
    },
    function() {

      // clean span, next time object will be added again
      // animation will start from begining.
      // but not for active menu item
      if (!$(this).hasClass('active')) $(this).find('span').html('');
    }
  );

  // submit form, when user clicks on submit link
  $('form#frmSS1 a').click(function(){
    if($('input[name="email"]').val()=='Din e-postadress'||$('input[name="email"]').val()=='') {
      alert('Ange din e-postadress');
    } else {
      $('form#frmSS1').submit();
    }
    return false;
    
  });
});

function replace_menu_background(t) {
      id=$(t).attr('class');
      // check if cache for backgrounds exists
      if (backgrounds[id]==null) {
        // get url from background and replace it with swf file
        url=$(t).find('span').css('background-image');
        if (!url) return;
        url=url.match(/url\('?"?(.*?)'?"?\)/)
        if (!url) return;
        url=url[1].replace('.gif','.swf');
        
        // get information about the size of container
        w=$(t).find('span').width();
        h=$(t).find('span').height();		
  
        // fix margin
        $(t).find('span').css('margin-top','-1px');
        
        // prepare object, remove background and store object in cache
        data='<object type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" data="'+url+'" width="'+w+'" height="'+h+'"  wmode="transparent" scale="noScale"><param name="movie" value="'+url+'"/><param name="scale" value="noScale"/> <param name="wmode" value="transparent"/></object>';
        
        $(t).find('span').css('background','none');
        backgrounds[id]=data;			
      }
      // add object code from cache into span
      $(t).find('span').html(backgrounds[id]).css('display','block');
}
