function nextSibling1(node)
 {
     var n = node;

     while ( n && !( n.nodeType == 1 && n.nodeName == "DIV" ))
         n = n.nextSibling;

     return n;
 }

 function nextImage(iImage)
 {
     var divs = document.getElementsByTagName( "div" );

     for ( var i = 0, j = 0; i < divs.length; i++ ) {
         if ( hasClass( divs, "vekselbilde" ) ) {
             if ( j == iImage ) {
                 for ( var chi = nextSibling1(divs.firstChild); chi; chi = nextSibling1(chi.nextSibling) ) {
                     if ( chi.style.display == "" ) {
                         chi.style.display = "none";

                         if ( nextSibling1(chi.nextSibling) )
                             nextSibling1(chi.nextSibling).style.display = "";
                         else
                             nextSibling1(divs.firstChild).style.display = "";
                         break;
                      }
                 }
                 break;
             } else
                 j++;
         }
     }
 }

 function checkToggleImages()
 {
     var paragraphs = document.getElementsByTagName( "p" );

     for ( var i = 0, j = 0; i < paragraphs.length; i++ ) {
         if ( hasClass( paragraphs, "vekselbilde" ) ) {
             var link = document.createElement( "a" );

             link.setAttribute( "href", "javascript:nextImage(" + (j++) + ");" );
             link.setAttribute( "title", "alternativbilde" );
             link.appendChild( paragraphs.firstChild );

             paragraphs.appendChild( link );
             paragraphs.style.display = "";
         }
     }
 }
 
 addOnloadHook( checkToggleImages );