
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

// Temporary variables to hold mouse x,y pos.s
var tempX = 0
var tempY = 0


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
	//alert(tempX);


    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true;
}

function ddInit(e){
  topDOM=isIE ? "BODY" : "HTML";
  whichDOM=isIE ? document.all.theLayer : document.getElementById("theLayer");
  hotDOM=isIE ? event.srcElement : e.target;
  titletextDOM=isIE ? document.all.titletext : document.getElementById("titletext");
  bodytextDOM=isIE ? document.all.bodytext : document.getElementById("bodytext");
  while (hotDOM.id!="titleBar"&&hotDOM.tagName!=topDOM){
    hotDOM=isIE ? hotDOM.parentElement : hotDOM.parentNode;
  }
  if (hotDOM.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDOM.style.left);
    nowY=parseInt(whichDOM.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDOM.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  whichDOM.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDOM.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";


tempX = 200;
tempY = 200;
}

function showMe(title_txt,body_txt){

if (tempX < 200)
{
  whichDOM.style.left = tempX+100;
  whichDOM.style.top = tempY-50;
}


else if (tempX > 600)
{
  whichDOM.style.left = tempX-300;
  whichDOM.style.top = tempY-50;
}


else {
  whichDOM.style.left = tempX-100;
  whichDOM.style.top = tempY-50;
}


  titletextDOM.innerHTML = title_txt;
  bodytextDOM.innerHTML = body_txt;



//Legg til koordinater i toppen av vinduet
//titletextDOM.innerHTML = titletextDOM.innerHTML + " X: " + tempX + " Y: " + tempY;


// Legg til koordinater

//  alert(whichDOM.style.left);
//  alert(whichDOM.style.top);
//  alert(tempY);


  //alert(titletextDOM.innerHTML);
  //alert(bodytextDOM.innerHTML);
  //whichDOM.style.titletext.innerHTML = "test";
  if (isIE||isNN) whichDOM.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");




//Script for å åpne linker i nytt vindu
//Scriptet trigges ved å benytte: <a href="document.html" rel="external">external link</a>
//Kilde: http://www.sitepoint.com/article/standards-compliant-world




/*
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

window.onload = externalLinks;
*/





    /* this function shows the pop-up when
     user moves the mouse over the link */
    function popupShow(divid)
    {
        /* get the mouse left position */
        x = event.clientX + document.body.scrollLeft;

        if (x > 600)
		{
		x = 300;
		}
        /* get the mouse top position  */
        y = event.clientY + document.body.scrollTop - 35;
        /* display the pop-up */
        divid.style.display="block";

        /* set the pop-up's left */
        divid.style.left = x;
        /* set the pop-up's top */
        divid.style.top = y;
    }
    /* this function hides the pop-up when
     user moves the mouse out of the link */
    function popupHide(divid)
    {
        /* hide the pop-up */
        divid.style.display="none";
    }

function popupL(divid)
{
        x = event.clientX + document.body.scrollLeft;
        divid.style.left = x - 200;
}


function popupR(divid)
{
        x = event.clientX + document.body.scrollLeft;
        divid.style.left = x + 200;
}


function popupU(divid)
{
        y = event.clientY + document.body.scrollTop;
        divid.style.top = y - 200;
}

function popupD(divid)
{
        y = event.clientY + document.body.scrollTop;
        divid.style.top = y + 200;
}

