jQuery.fn.centerDIV = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
$(document).ready(function(){
						   
	  var iframe = $('iframe[name^="kalender"]');
	  
	  // Called once the Iframe's content is loaded.
	  iframe.load(function(){
		// The Iframe's child page BODY element.
		var iframe_content = iframe.contents().find('body');
		
		// Bind the resize event. When the iframe's size changes, update its height as
		// well as the corresponding info div.
		iframe_content.resize(function(){
		  var elem = $(this);
		  
		  // Resize the IFrame.
		  iframe.css({ height: elem.outerHeight( true ) });
		  
		  // Update the info div width and height.
		  $('#iframe-info').text( 'IFRAME width: ' + elem.width() + ', height: ' + elem.height() );
		});
		
		// Resize the Iframe and update the info div immediately.
		iframe_content.resize();
	  });
	   
						   
						   
						   

$("input.switch").blur(function(){ if($(this).val()==''){ $(this).val($(this).attr('title')); } });
$("input.switch").focus(function(){ if($(this).val()==$(this).attr('title')){ $(this).val(''); } });
$(".laesmere").before(function(){ return '<a style="cursor:pointer;" onClick="$(\'#'+$(this).attr('id')+'\').slideDown();$(this).hide();">L&aelig;s mere...</a>'; });
$(".laesmere").replaceWith(function(){ return '<div style="display:none;" id="'+$(this).attr('id')+'">'+$(this).html()+'</div>'; });
$(".sirf_replace").replaceWith(function(){ return '<img src="/asp/request.aspx?text='+encodeURIComponent($(this).html())+'" />'; });


$("a.iframepdf").click(function(event){
  	event.preventDefault();
	
	$('#pdfframe').remove();
	var frameHeight=$(window).height()*0.9;
	var frameWidth=$(window).width()*0.9;
  	
	var pdflink=$(this).attr('href');
	
	if($(this).attr('type')!=''){
		var dwn='<a href="'+pdflink+'&forcedownload=true'+'" id="pdfclose" style="background-color:#FFFFCC;border:solid 4px black; padding:5px; cursor:pointer; position:absolute; left:50px; top:-31px;"><b>Download</b></a>';
	} else {
		var dwn='';
	}
	
	$(this).after('<div id="pdfframe" style="z-index: 1000;background-color:white;display:none;position:absolute;width:'+frameWidth+'px;height:'+frameHeight+'px;border:solid 4px black;"><a id="pdfclose" style="background-color:#FFFFCC;border:solid 4px black;padding:5px;cursor:pointer;position:absolute;left:5px;top:-31px;"><b>Luk</b></a>'+dwn+'<!--<img id="pdfclose2" style="cursor:pointer;position:absolute;left:5px;top:-29px;" src="http://www.ds-net.dk/images/close2.png"/>--><iframe onload="closeBar();" frameborder="0" width="'+frameWidth+'" height="'+frameHeight+'" src="'+pdflink+'"></iframe></div>');
	
	$('#pdfframe').centerDIV();
	$('#pdfframe').fadeIn();
    $('#pdfclose').click(function(event){
		$('#pdfframe').remove();
	});
  });
  
  	$('a.test').click(function(event){
		event.preventDefault();
		$('#shd_back').remove();
		var imagelink=$(this).attr('href');
		$(this).after('<div id="shd_back" style="background-color:white;border:solid 4px black;display:none;width:1px;height:1px;position:absolute;"><!--<img style="width:100%;height:100%;position:absolute;" src="http://www.ds-net.dk/images/shadow770x600.png" />--><div id="shd_front" style="position:absolute;padding:25px;"><img src="'+imagelink+'" onload="showShadowImg();" onClick="hideShadowImg();"/>');
	});
  
  
  $("a.imagepop").click(function(event){
  	event.preventDefault();
	$('#imagepop').remove();
  	var imagelink=$(this).attr('href');
	$(this).after('<div id="imagepop" style="display:none;padding:20px;background-color:white;border:solid 4px black;position:absolute;"><a id="imageclose" style="background-color:#FFFFCC;border:solid 4px black;padding:5px;cursor:pointer;position:absolute;left:5px;top:-31px;text-decoration:none;"><b style="text-decoration:none;">Luk</b></a><img onload="showAndCenterImage();" style="cursor:pointer;" id="popimage" src="'+imagelink+'" /></div>');

	
//	$('#imagepop').css({top:'50%',left:'50%',margin:'-'+($('#imagepop').height() / 2)+'px 0 0 -'+($('#imagepop').width() / 2)+'px'});


	$('#imageclose').click(function(event){
		$('#imagepop').remove();
	});
	$('#popimage').click(function(event){
		$('#imagepop').remove();
	});
  });
  


  
  
  
  
});

function showAndCenterImage(){
	$('#imagepop').centerDIV();
	$('#imagepop').fadeIn();		
}

function closeBar(){
	$('#loadingbar').fadeOut();
}
function showShadowImg(){
	var back_height=$('#shd_front').height()+50;
	var back_width=$('#shd_front').width()+50;
	$('#shd_back').fadeIn();
	$('#shd_back').height(back_height);
	$('#shd_back').width(back_width);
	$('#shd_back').centerDIV();

}
function hideShadowImg(){
	$('#shd_back').remove();
}

function changeHeight(iframe)
      {
        try
        {
          var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
          if (innerDoc.body.offsetHeight) //ns6 syntax
          {
             iframe.height = innerDoc.body.offsetHeight + 32; //Extra height FireFox
          }
          else if (iframe.Document && iframe.Document.body.scrollHeight) //ie5+ syntax
          {
             iframe.height = iframe.Document.body.scrollHeight;
          }
        }
        catch(err)
        {
          alert(err.message);
        }
      }
