


jQuery(document).ready(function()
	{
		// Set specific variable to represent all iframe tags.
		
		if(!jQuery('#iframe'))
		    return;
		
		
		var iFrames = document.getElementsByTagName('iframe');
        var contentHeight;
		// Resize heights.
		function iResize()
		{
			// Iterate through all iframes in the page.
			//alert("iResize");
			
			//
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
			    var cw = iFrames[i].contentWindow;
			    //console.log(cw);
			    
			    if(!cw)
			        continue;
			
			    contentHeight = iFrames[i].contentWindow.document.body.offsetHeight;
			    contentWidth = iFrames[i].contentWindow.document.body.offsetWidth;
				
			   //trace("resetting iframe to "+contentWidth + " x " + contentHeight);
			
				// Set inline style to equal the body height of the iframed content.
				iFrames[i].style.height = contentHeight + 'px';
				iFrames[i].contentWindow.document.body.style.margin = "0px";
				//iFrames[i].style.width = iFrames[i].contentWindow.document.body.offsetWidth + 'px';
			}
			/*
			jQuery("#iframe").contents().find("a")
				.click(function (){
					var href = jQuery(this).attr("href");
					if(href.indexOf("http") != -1)
					{
						event.preventDefault();
						var answer = confirm(CONFIRM_LEAVE_SITE);
						if (answer)
							window.location = href;
					}
				});*/
		}
		
		function ieResize()
		{
		    for (var i = 0, j = iFrames.length; i < j; i++)
			{
			    var cw = iFrames[i].contentWindow;
			   
			    if(!cw)
			        continue;
			
			    contentHeight = iFrames[i].contentWindow.document.body.scrollHeight;
			    contentWidth = iFrames[i].contentWindow.document.body.scrollWidth;
			   // alert("resetting iframe to "+contentWidth + " x " + contentHeight);
			
				iFrames[i].style.height = contentHeight + 'px';
				iFrames[i].contentWindow.document.body.style.margin = "0px";
				//iFrames[i].style.width = iFrames[i].contentWindow.document.body.offsetWidth + 'px';
			}
			//jQuery(this).css("height", contentHeight + 'px');
		}

		// Check if browser is Safari or Opera.
		if (jQuery.browser.safari || jQuery.browser.opera)
		{
			// Start timer when loaded.
			jQuery('iframe').load(function()
			{
				setTimeout(iResize, 0);
			});

			// Safari and Opera need a kick-start.
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				var iSource = iFrames[i].src;
				iFrames[i].src = '';
				iFrames[i].src = iSource;
			}
		}
		else if(jQuery.browser.msie)
		{
		    // For other good browsers.
			 //alert("IE page load");
			jQuery('#iframe').load(function()
		    {
			    //alert("IE frame load");
			    setTimeout(ieResize, 200);	
		    });
			setTimeout(ieResize, 200);
		}
		else
		{
		    // For other good browsers.
			//alert("firefox page load");
			jQuery('#iframe').load(function()
			{
			   // console.log("ff iframe load");
				setTimeout(iResize, 0);  					
			});
			//setTimeout(iResize, 200);
		}
	}
);
