  sfHover = function()
{
  var sfEls = document.getElementById("nav").getElementsByTagName("LI");
      for (var i=0; i<sfEls.length; i++) 
    {
        sfEls[i].onmouseover=function() 
      {
         this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() 
      {
           //this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
         this.timer = new Timer(this);
        this.timer.setTimeout("out",20);
        }
      sfEls[i].out=function() 
      {
      this.className=this.className.replace(new RegExp("\\bsfhover\\b"), "");
      }
    }
  }
if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.addEventListener) window.addEventListener( "load", sfHover, false );

function Timer()
{
    this.obj = (arguments.length)?arguments[0]:window;
    return this;
}

// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be
//   passed to the method when it is evaluated.

Timer.prototype.setInterval = function(func, msec)
{
    var i = Timer.getNew();
    var t = Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setInterval(t,msec);
    return i;
}
Timer.prototype.setTimeout = function(func, msec)
{
    var i = Timer.getNew();
    Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
    return i;
}

// The clear functions should be called with
// the return value from the equivalent set function.

Timer.prototype.clearInterval = function(i)
{
    if(!Timer.set[i]) return;
    window.clearInterval(Timer.set[i].timer);
    Timer.set[i] = null;
}
Timer.prototype.clearTimeout = function(i)
{
    if(!Timer.set[i]) return;
    window.clearTimeout(Timer.set[i].timer);
    Timer.set[i] = null;
}

// Private data

Timer.set = new Array();
Timer.buildCall = function(obj, i, args)
{
    var t = "";
    Timer.set[i] = new Array();
    if(obj != window){
        Timer.set[i].obj = obj;
        t = "Timer.set["+i+"].obj.";
    }
    t += args[0]+"(";
    if(args.length > 2){
        Timer.set[i][0] = args[2];
        t += "Timer.set["+i+"][0]";
        for(var j=1; (j+2)<args.length; j++){
            Timer.set[i][j] = args[j+2];
            t += ", Timer.set["+i+"]["+j+"]";
    }}
    t += ");";
    Timer.set[i].call = t;
    return t;
}
Timer.callOnce = function(i)
{
    if(!Timer.set[i]) return;
    eval(Timer.set[i].call);
    Timer.set[i] = null;
}
Timer.getNew = function()
{
    var i = 0;
    while(Timer.set[i]) i++;
    return i;
}
    
    
    
    
    
var b7Items = 0;
var myB7ads = new Array();
var normalItems = 0;
var myNormalads = new Array();
var slItems = 0;
var mySlads = new Array();
var textItems = 0;
var myTextads = new Array();
var b7random = 0;
var b7lastrandom = -1;
var normalrandom = 0;
var normalcounter = 0;
var normallastrandom = -1;
var slrandom = 0;
var sllastrandom = -1;
var textrandom = 0;
var textlastrandom = -1;
var B7AdTimeout = 10000;
var normalAdTimeout = 5000;
var slAdTimeout = 5000;
var textAdTimeout = 3000;

  



function adInfo(image,text,link)
{
  this.image = image; 
  this.text = text;
  this.link = link;
}

function setb7AdInfo(b7ads)
{
  
  var i=0;
  for (i=0;i< b7ads.length; i+=3)
  {
    myB7ads[b7Items] = new adInfo(b7ads[i],b7ads[i+1],b7ads[i+2]); 
    b7Items ++;
//    alert(b7Items);
  }
  
}
function setNormalAdInfo(normalads)
{
  var i=0;
  for (i=0; i< normalads.length; i+=3)
  {
    myNormalads[normalItems] = new adInfo(normalads[i],normalads[i+1],normalads[i+2]); 
    normalItems ++;
//    alert("normals: " + normalItems);
  }
  
}
function setSlAdInfo(slads)
{
  
  var i=0;
  for (i=0; i< slads.length; i+=3)
  {
    mySlads[slItems] = new adInfo(slads[i],slads[i+1],slads[i+2]); 
    slItems ++;
  }
  
}
function setTextAdInfo(textads)
{
  var i=0;
  for (i=0; i< textads.length; i+=3)
  {
    myTextads[textItems] = new adInfo(null,textads[i+1],textads[i+2]); 
    textItems ++;
  }
  
}
function replaceB7Ads()
{
  /*var now = new Date();
  b7random = now.getSeconds()%b7Items; 
  b7random = now.getSeconds()%normalItems;
  if (b7random == b7lastrandom)
  {
    if (b7random == b7Items-1) b7random--; else b7random++; 
  }*/
  b7random++
  if (myB7ads.length <= b7random)
  {
    b7random = 0
  }
  document.getElementById('b7adimage').src = myB7ads[b7random].image;
  document.getElementById('b7adtext').innerHTML = myB7ads[b7random].text;
  document.getElementById('b7adlink').href = myB7ads[b7random].link;
  //b7lastrandom = b7random; 
  setTimeout('replaceB7Ads()',this.B7AdTimeout);
}
function replaceNormalAds()
{
  
  normalrandom++
  if (myNormalads.length <= normalrandom)
  {
    normalrandom = 0
  }
  //normalcounter = normalrandom
  /*normalrandom = now.getSeconds()%normalItems;
  
  //if (normalrandom == normallastrandom)
  {
    if (normalrandom == normalItems-1) normalrandom--; else normalrandom++; 
  }*/
  /*alert("Normalrandom "+normalrandom)
  alert("Lengde "+myNormalads.length)
  alert("Counter "+normalcounter)*/
  
  document.getElementById('normaladimage').src = myNormalads[normalrandom].image;
  document.getElementById('normaladtext').innerHTML = myNormalads[normalrandom].text;
  document.getElementById('normaladlink').href = myNormalads[normalrandom].link;
  //normallastrandom = normalrandom;
  setTimeout('replaceNormalAds()',this.normalAdTimeout);
}
function replaceSlAds()
{
  /*var now = new Date();
  
  slrandom = now.getSeconds()%slItems;
  
  if (slrandom == sllastrandom)
  {
    if (slrandom == slItems-1) slrandom--; else slrandom++; 
  }*/
   slrandom++
  if (mySlads.length <= slrandom)
  {
    slrandom = 0
  }
  document.getElementById('sladimage').src = mySlads[slrandom].image;
  document.getElementById('sladtext').innerHTML = mySlads[slrandom].text;
  document.getElementById('sladlink').href = mySlads[slrandom].link;
  //sllastrandom = slrandom;
  setTimeout('replaceSlAds()',this.slAdTimeout);
}
function replaceTextAds()
{
  var now = new Date();
  textrandom = now.getSeconds()%textItems;
  if (textrandom == textlastrandom)// && textItems > 1)
  {
    if (textrandom == textItems-1) textrandom--; else textrandom++; 
  }
  document.getElementById('textadtext').innerHTML = myTextads[textrandom].text;
  document.getElementById('textadlink').href = myTextads[textrandom].link;
  textlastrandom = textrandom;
  setTimeout('replaceTextAds()',this.textAdTimeout);
}

function startAdRotation(b7ads,normalads,textads,slads,B7AdTimeout,normalAdTimeout,textAdTimeout,slAdTimeout, number_of_menuitems, numOfMenuItems) 
{  
  //  "javascript:startAdRotation(['http://www.bellona.no/imagearchive/adimage_AkerASA_B7_logo_web.jpg','Aker ASA','http://www.akerasa.com','http://www.bellona.no/imagearchive/appliedplasmaphysicsas','Applied Plasma Physics AS','http://www.app.no/','http://www.bellona.no/imagearchive/adimage_Avikom-logo_web-1..jpg','Avikom','http://www.avikom.no','http://www.bellona.no/imagearchive/adimage_bama_logo_web.jpg','Bama','http://www.bama.no','http://www.bellona.no/imagearchive/adimage_bwgas_logo_web.jpg','BWGas','http://www.bwgas.com/','http://www.bellona.no/imagearchive/cocacolanorgeas','Coca Cola Norge AS','http://www.cocacola.no/','http://www.bellona.no/imagearchive/conocophillips','ConocoPhillips','http://www.conocophillips.no/','http://www.bellona.no/imagearchive/adimage_EBL_b7_logo_web.jpg','Energibedriftenes landsforening','http://www.ebl.no','http://www.bellona.no/imagearchive/eidesvikas','Eidesvik as','http://www.eidesvik.no/','http://www.bellona.no/imagearchive/eiendomsspar','Eiendomsspar','http://www.epi.no/eiendomsspar/','http://www.bellona.no/imagearchive/adimage_EB_logo-1..jpg','Energiselskapet Buskerud AS','http://www.eb.no/','http://www.bellona.no/imagearchive/erametnorge','Eramet Norge','http://www.eramet.fr/','http://www.bellona.no/imagearchive/ferrolegeringsindustriensforskningsforening','Ferrolegeringsindustriens Forskningsforening','http://www.ferroforsk.com/','http://www.bellona.no/imagearchive/findus','Findus','http://www.findus.no/','http://www.bellona.no/imagearchive/adimage_flytoget2_logo_web-1..jpg','Flytoget','http://www.flytoget.no','http://www.bellona.no/imagearchive/adimage_Hafslund_logo_web.jpg','hafslund','http:www.hafslund.no','http://www.bellona.no/imagearchive/marineharvest','Marine Harvest','http://www.marineharvest.no','http://www.bellona.no/imagearchive/marinepower','Marine Power','http://www.marinepower.no/','http://www.bellona.no/imagearchive/mesta','Mesta','http://www.mesta.no/','http://www.bellona.no/imagearchive/noahas','Noah AS','http://www.noah.no/ ','http://www.bellona.no/imagearchive/norskindustri','Norsk Industri','http://www.norskindustri.no/','http://www.bellona.no/imagearchive/norskeshellas','Norske Shell as','http://www.shell.no/','http://www.bellona.no/imagearchive/adimage_pon-power.jpg','Pon Power','http://www.ponpower.no/','http://www.bellona.no/imagearchive/adimage_saab_logo_web-5..jpg','Saab','http://www.saab.no','http://www.bellona.no/imagearchive/adimage_siemens_logo_web.jpg','Siemens ','http://www.siemens.no','http://www.bellona.no/imagearchive/adimage_skretting_logo_web_b7.jpg','Skretting AS','http://www.skretting.no/','http://www.bellona.no/imagearchive/adimage_statkraft_ny_logo_web_150x4.jpg','Statkraft','http://www.statkraft.no/','http://www.bellona.no/imagearchive/statoil','Statoil','http://www.statoil.no/MAR/SVG01183.nsf/fs/start','http://www.bellona.no/imagearchive/adimage_veolia_logo_web.jpg','Veolia Miljø AS','http://www.veolia.no','http://www.bellona.no/imagearchive/waterpowerindustriesas','Water Power Industries AS','','http://www.bellona.no/imagearchive/adimage_wilh.wilhelmsen_logo_web-1..jpg','Wilh Wilhelmsen','http://www.ww-group.com','http://www.bellona.no/imagearchive/woodpolymertechnologiesasa','Wood Polymer Technologies ASA','http://www.wpt.no/','http://www.bellona.no/imagearchive/adimage_yara_logo_web-1..jpg','Yara','http://www.yara.com'],['http://www.bellona.no/imagearchive/adimage_sor-norge-alu_logo_web.jpg','Sør-Norge Aluminium','http://www.soral.no/eng/'],[],[],15000,15000,10000,15000,8,['6','5','8','5','7','6','5'])">
//  alert("b7ads length:" + b7ads.length + " --> normalads length: " + normalads.length);
//  alert(normalads);
  for (num=1; num<=number_of_menuitems; num++)
  {
    nn = numOfMenuItems[num-1]
    
    initializeMenu("menu"+num, "actuator_slot"+num,"img"+num);
    for (n=1; n<=nn; n++)
    {
      
      initializeMenu("submenu"+num+"_"+n, "submenu_actuator_slot"+num+"_"+n,"img"+num+"_"+n);  
      
    }
  }

  this.B7AdTimeout = B7AdTimeout;
  this.normalAdTimeout = normalAdTimeout;
  this.slAdTimeout = slAdTimeout;
  this.textAdTimeout = textAdTimeout;
  
//  this.textAdTimeout =  100;
//  this.slAdTimeout = 100;
//  this.B7AdTimeout = 100;
//  this.normalAdTimeout = 100;
  setb7AdInfo(b7ads);
  setNormalAdInfo(normalads);
  setSlAdInfo(slads);
  setTextAdInfo(textads);
  var now = new Date();
  b7random = now.getSeconds()%b7Items; 
  b7lastrandom = b7random;
  normalrandom = now.getSeconds()%normalItems; 
  normallastrandom = normalrandom;
  slrandom = now.getSeconds()%slItems; 
  sllastrandom = slrandom;
  textrandom = now.getSeconds()%textItems; 
  textlastrandom = textrandom;
  
  if (myB7ads[b7random] != null)
  {
      document.getElementById('b7adimage').src = myB7ads[b7random].image;
      document.getElementById('b7adtext').innerHTML = myB7ads[b7random].text;
      document.getElementById('b7adlink').href = myB7ads[b7random].link;
  }

  if (myNormalads[normalrandom] != null)
  {
      document.getElementById('normaladimage').src = myNormalads[normalrandom].image;
      document.getElementById('normaladtext').innerHTML = myNormalads[normalrandom].text;
      document.getElementById('normaladlink').href = myNormalads[normalrandom].link;
  }
  if (mySlads[slrandom] != null)
  {
      try{
      document.getElementById('sladimage').src = mySlads[slrandom].image;
      document.getElementById('sladtext').innerHTML = mySlads[slrandom].text;
      document.getElementById('sladlink').href = mySlads[slrandom].link;
      }
      catch(err)
      {
      }
  }
  if (myTextads[textrandom] != null)
  {
      document.getElementById('textadtext').innerHTML = myTextads[textrandom].text;
      document.getElementById('textadlink').href = myTextads[textrandom].link;
  }
  if (b7Items > 1)
  {  
    setTimeout('replaceB7Ads()',this.B7AdTimeout);
  }
  if (normalItems > 1)
  {
    setTimeout('replaceNormalAds()',this.normalAdTimeout);
  }
  if (slItems > 1)
  {
    setTimeout('replaceSlAds()',this.slAdTimeout);
  }
  if (textItems > 1)
  {
    setTimeout('replaceTextAds()',this.textAdTimeout);
  }
  
}







function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// LIST ALL SHOW/HIDE ELEMENT IDS HERE
menus_array = new Array ('ddNA','ddAA','ddBlog','ddDA','ddPress','ddLink','ddFaq', 'ddAO', 'ddBk');
menus_status_array = new Array ();// remembers state of switches
img_close = 'style/minus_white.jpg';
img_open = 'style/plus_white.jpg';

function showHideSwitch (theid) {
  
  if (document.getElementById) 
  {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[theid] != 'show') 
    {
      if (button_id != null)
      {
        button_id.setAttribute ('src', img_close);
      }
      if (switch_id != null)
      {
        switch_id.className = 'showSwitch';
      }
      menus_status_array[theid] = 'show';
      document.cookie = theid+'=show';
    }
    else
    {
      if (button_id != null)
      {
        button_id.setAttribute ('src', img_open);
      }
       if (switch_id != null)
      {
        switch_id.className = 'hideSwitch';
      }
      menus_status_array[theid] = 'hide';
      document.cookie = theid+'=hide';
    }
  }
}
function resetMenu () { // read cookies and set menus to last visited state
  if (document.getElementById) {
    for (var i=0; i<menus_array.length; i++) {
      var idname = menus_array[i];
      var switch_id = document.getElementById(idname);
      var imgid = idname+'Button';
      var button_id = document.getElementById(imgid);
      if (getCookie(idname) == 'show')
      {
        if (button_id != null)
        {
          button_id.setAttribute ('src', img_close);
        }
        if (switch_id != null)
        {
          switch_id.className = 'showSwitch';
        }
        menus_status_array [idname] = 'show';
      }
      else
      {
        if (button_id != null)
        {
          button_id.setAttribute ('src', img_open);
        }
        if (switch_id != null)
        {
          switch_id.className = 'hideSwitch';
        }
        menus_status_array [idname] = 'hide';
      }
    }
  }
}


/*
 * menuExpandable3.js - implements an expandable menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId,imgId) {
    
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    var img = document.getElementById(imgId);
    if (menu == null || actuator == null || img == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.parentNode.style.backgroundImage = "url(style/plus_white.jpg)";
    actuator.onclick = function() {
        var display = menu.style.display;
        /*this.parentNode.style.backgroundImage =
            (display == "block") ? "url(style/plus_white.jpg)" : "url(style/minus_white.jpg)";*/
        /*this.parentNode.style.backgroundImage =
            (display == "block") ? "url(style/plus_white.jpg)" : "url(style/minus_white.jpg)";*/
        if (img.parentNode.id.substring(0,7)== 'submenu')
        {
          img.src = (display == "block") ? "style/plus_white_lightblue.jpg" : "style/minus_white_lightblue.jpg";
        }
        else
        {
          img.src = (display == "block") ? "style/plus_white.jpg" : "style/minus_white.jpg";
        }
        menu.style.display = (display == "block") ? "none" : "block";

        return false;
    }
}