/*******************************
 * popupscripts.js 
 * Function popup i nyt vindue 
 *******************************/
// detect if the browser is IE or not.
var IE = document.all?true:false;

function popup(mylink) {
  var newwindow = window.open('', 'img_popup');
  var iOldX = newwindow.screenX;
  var iOldY = newwindow.screenY;
  newwindow.close();
  if(typeof(iOldX)=='undefined'){iOldX=iOldY=0;}

  var href;
  if (typeof(mylink) == 'string') href=mylink;
  else href=mylink.href;

  var w = h = 800;
  var oChildren = mylink.children;
  if (oChildren[0]) {
    var h = Math.min(1200,screen.height)-100-iOldY;
    if(h<0){
      iOldX = iOldY = 0; 
      h = Math.min(1200,screen.height)-100;
    }
    var w = Math.round(h*oChildren[0].width/oChildren[0].height);
    if ((iOldX+w) > screen.width){
      w = screen.width-iOldX;
      h = Math.round(w*oChildren[0].height/oChildren[0].width);
    }
  }
  var sParam = 'toolbar=no,location=no,directories=no,status=no,menubar=no,left='
               +iOldX+',top='+iOldY+',width='+w+',height='
               +h+',scrollbars=yes,resizable=yes,dependent=yes';
  newwindow=window.open(href, 'img_popup', sParam);
  if (window.focus) {newwindow.focus()}
  return false;
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft,curtop];
  }
}

function GetWidth() {
  var x = 0;
  if (self.innerHeight) { x = self.innerWidth; }
  else if (document.documentElement && document.documentElement.clientHeight) {
    x = document.documentElement.clientWidth; }
  else if (document.body) {
    x = document.body.clientWidth;
  }
  return x;
}

function GetHeight() {
  var y = 0;
  if (self.innerHeight) { y = self.innerHeight; }
  else if (document.documentElement && document.documentElement.clientHeight) {
    y = document.documentElement.clientHeight; }
  else if (document.body) {
    y = document.body.clientHeight;
  }
  return y;
}

var iWidthWidth = GetWidth()
var iWindowHeight = GetHeight()
//alert(iWidthWidth+' '+iWindowHeight)

/*******************************
 * Function showImg - vis billede i 3xstørrelsen af det lille billede i overlay */
function showImg(billede, ImageUrl) {
  var oContainer = document.getElementById('midsize');
  if (oContainer) {
    var href;
    if (typeof(billede) == 'string') { href=billede; }
    else { href=billede.href; }

    var aImgCorner = findPos(billede);

    var w; var h;
    var children = billede.childNodes;
    var oImage = children[0];
    if (oImage.getAttributeNS) {
      w = parseInt(oImage.getAttributeNS(null, "width"));
      h = parseInt(oImage.getAttributeNS(null, "height"));
    }
    else {
      w = parseInt(oImage.getAttribute("width"));
      h = parseInt(oImage.getAttribute("height"));
    }

    oContainer.style.left = (aImgCorner[0]+w+2)+'px';
    if (IE) { oContainer.style.top = (aImgCorner[1])+'px'; } 
    else { oContainer.style.top = (aImgCorner[1]-h+8)+'px'; }
    oContainer.innerHTML = "<img src='"+href+"' style='width:"+(3*w)+"; height:"+(3*h)+"; border:9px solid gray;' alt=''>";
    oContainer.style.visibility = 'visible';
  }
}

/***********************************
 * Function hideImg - hide overlay */
function hideImg() {
  var oContainer = document.getElementById('midsize');
  if (oContainer) { oContainer.style.visibility = 'hidden';}
}


/*******************************
 * Gooogle Analytics           */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19731773-2']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

