﻿/*
Document ready
Dette sker lige når browsere har læst dokumentet igennem
*/
jQuery(function () {
  if (jQuery("#container-navigation-column li").length <= 0){
    jQuery("#container-navigation-column").addClass("hide");
  }
  $("a[rel^='prettyPhoto']").prettyPhoto();
  
  jQuery("ul li:first").addClass("first");
  jQuery("ul li:last").addClass("last");

  
  jQuery("dl.referencer dt:first").addClass("selected");
  jQuery("dl.referencer dd:first").addClass("selected");

    jQuery("dl.referencer dt").hover(function () {
        jQuery("dl.referencer dt").removeClass("selected");
        jQuery("dl.referencer dd").css("zIndex", "0")
        jQuery(this).addClass("selected");
        jQuery(this).next("dd").css("zIndex","200")
    });     
      
      // Tag højde for at der kan være referencer uden galleri
      if ( jQuery("#billeder ul li").length > 0 ) {
        var theSlider = jQuery("#billeder").sudoSlider(
          {
            continuous:true,  
            updateBefore: true,
            customLink:'a.customLink',        
            controlsShow:false
          }
        );   
        
        jQuery("#galleri .zoom").click(function(){
          // Find current slide
          var currentSlide = theSlider.getValue('currentSlide');    
          // Get path and text for the overlay
          var path = jQuery("#billeder li img").eq(currentSlide).attr("src");   
          var desc = jQuery(".billedtekst").text();
          jQuery(this).attr("href", path);     
          
          var replacedPath = path.substr(0, path.lastIndexOf("&H") );
          replacedPath = replacedPath + "&Width=900";
          
          var images = new Array();
          var titles = new Array();
          var desciptions = new Array();

          var galImages = jQuery("#slider li img");
          var galLength = galImages.length;
          galImages.each(function(i){
            if (i > 0 && i != galLength-1) {
              var replacedPath = jQuery(this).attr("src").substr(0, jQuery(this).attr("src").lastIndexOf("&") );
              replacedPath = replacedPath + "&Width=900";
              
              images[images.length] = replacedPath ;
              titles[titles.length] = "";
              desciptions[desciptions.length] = "";
            }
          })
          

          // Open gallery  
          //jQuery.prettyPhoto.open(images,titles,desciptions);
          
          
          // Open lightbox
          jQuery.prettyPhoto.open(replacedPath,'',desc);
          return false;
        });
      } else {
        jQuery("#galleri").hide();
      }
      
   
   
      
// Equal Height Blocks in Rows
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;

$('.smallbanners li').each(function() {

   $el = $(this);
   topPostion = $el.position().top;

   if (currentRowStart != topPostion) {

     // we just came to a new row.  Set all the heights on the completed row
     for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
       rowDivs[currentDiv].height(currentTallest);
     }

     // set the variables for the new row
     rowDivs.length = 0; // empty the array
     currentRowStart = topPostion;
     currentTallest = $el.height();
     rowDivs.push($el);

   } else {

     // another div on the current row.  Add it to the list and check if it's taller
     rowDivs.push($el);
     currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);

  }

  // do the last row
   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
     rowDivs[currentDiv].height(currentTallest);
   }

});
$('.referenceList .item').each(function() {

   $el = $(this);
   topPostion = $el.position().top;


     // another div on the current row.  Add it to the list and check if it's taller
     rowDivs.push($el);
     currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);

  

  // do the last row
   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
     rowDivs[currentDiv].height(currentTallest);
   }

});
// Equal Height Blocks in Rows // ENDS 
     
     
     
      
});

/*
Window load
Dette sker når browseren har læst dokumentet OG downloaded alle filer
*/
jQuery(window).bind("load", function() {

});
/*
  IPaper Specific START
*/
//Gør et eller andet ved IPaper, som ellers fejler.
function onPaperLoad() { return; }

function checkIpaperOpen() {
  var showIpaper = getURLParam("ShowIpaper");
  if (showIpaper && showIpaper != "") {
    showPopup("IPaper", showIpaper);
  }
}

function checkIpaperClose() {
  window.setInterval(checkToClose, 300);
}

function checkToClose() {
  var allIsDisplayNone = true;
  jQuery(".popupContent").each(function() {
    if (jQuery(this).css("display") === "block") {
      allIsDisplayNone = false;
    }
  });
  if (allIsDisplayNone)
    window.opener.closePopUp(window);
}
/*
IPaper Specific END
*/



function getURLParam(strParamName) {
  return getParameterFromLink(strParamName, window.location.href);
}
function getParameterFromLink(strParamName, link) {
  var strReturn = "";
  var strHref = link;
  if (strHref.indexOf("?") > -1) {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for (var iParam = 0; iParam < aQueryString.length; iParam++) {
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}
