// script for dynamically resizing iframe to fit content.
var ifr_originalID = "iframe-2"; // id of original embedded iframe
var ifr_replacedID = "iframe-1";  // id after replacement through script (needs to be different from original)
var ifr_flag=0; // flag to indicate whether target function has already been run

try {
// script for dynamically resizing iframe to fit content.
document.writeln("<style type=\"text\/css\"><!-- .wpcTeaserSmall { margin-right:8px; } .wpcTeaser { margin-right:12px; } --><\/style>");	

top.document.getElementById(ifr_originalID).scrolling = 'no';
document.body.style.overflow = 'hidden';
} catch(e) {
}

var ifr_isIE=(document.all && !window.opera);
// determine when DOM is ready in order to call "ifr_pageSwitch" method.
if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
	var _timer=setInterval(function(){
    if(/loaded|complete/.test(document.readyState)){
    	clearInterval(_timer);
		ifr_flag=1;
    	ifr_pageSwitch(); // call target function
    }}, 10)
} else if (document.addEventListener)
	document.addEventListener("DOMContentLoaded", function(){
		ifr_flag=1; 
		ifr_pageSwitch();
	}, false)
else if (ifr_isIE){
	document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
    var contentloadtag=document.getElementById("contentloadtag");
    contentloadtag.onreadystatechange=function(){
    	if (this.readyState=="complete"){
      		ifr_flag=1;
      		ifr_pageSwitch();
    	}
  	}
}
// resize iframe to match content
function ifr_resize(){

	if(parent.document.getElementById(ifr_originalID) && document.getElementsByTagName("iframe").length == 0) {
	    var ifr = parent.document.getElementById(ifr_originalID);
//		document.body.style.overflow = 'hidden';
		
        ifr.scrolling = "no";
        ifr.setAttribute("scrolling","no");		
		var height = document.body.scrollHeight;
		ifr.height=height;	
		document.body.style.visibility='visible'; // … after resizing make <body> visible
	}
}
// css class "js" added to <body>, which is used to set
// initial 'visibility' of <body> to 'hidden'
function ifr_initVis() {
	var attrName=ifr_isIE ? "className" : "class";
	var classNames=document.body.getAttribute(attrName);
	document.body.setAttribute(attrName, classNames+" js");
}
// replace iframe on page in order to ensure scrolling is set to "no"
function ifr_replace() {
	var ifr=document.getElementById(ifr_originalID);
	var newIfr = document.createElement("iframe");
	newIfr.setAttribute("id",ifr_replacedID);
	newIfr.setAttribute("src",ifr.getAttribute("src"));
	newIfr.setAttribute("width",ifr.getAttribute("width"));
	newIfr.setAttribute("height",ifr.getAttribute("height"));
	newIfr.setAttribute("scrolling","no");
	newIfr.setAttribute("frameBorder","0");
	newIfr.setAttribute("marginHeight","0");
	newIfr.setAttribute("marginWidth","0");
	ifr.parentNode.replaceChild(newIfr,ifr);
}
// method called when DOM is ready
function ifr_pageSwitch() {
	if(parent.document.getElementById(ifr_replacedID)) // page within iframe
		ifr_initVis();
	else if(document.getElementById(ifr_originalID)) // page containing iframe
		ifr_replace();
	else if(parent.document.getElementsByTagName("iframe").length == 0 && ifr_url)
		document.location.href=ifr_url;
}
// cross-browser event handler for IE5+, NS6+ and Mozilla/Gecko, by Scott Andrew
function ifr_addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r=elm.attachEvent('on'+evType, fn);
		return r;
	} else {
		elm['on' + evType]=fn;
	}
}
ifr_addEvent(window, 'load', ifr_resize, false);
