/**
 * @author Stephane Roucheray
 * @extends jquery
 */
jQuery.fn.iframeResize = function(options){
	var settings = jQuery.extend({
		width: "fill",
		height: "auto",
		autoUpdate : true
	}, options);
	var filler = 30;
	
	function onEachIframe(){
		var frame = jQuery(this);
		var body = frame.contents().find("body");
				
		frame.css("overflow", "hidden");
		if (settings.autoUpdate) {
			if (jQuery.browser.msie) {
				frame.attr("scrolling", "auto");
				//setInterval(immediateResize, 1000);
			}
			else {
				body.bind("DOMSubtreeModified", {
					frame: frame
				}, resizeIframe);
			}
		}
		immediateResize();
		
		function immediateResize(){
			var e = jQuery.Event();
			e.data = {};
			e.data.frame = frame;
			resizeIframe.call(body, e);
		}
	}
	
	function resizeIframe(event){
		var body = jQuery(this);
		event.data.frame.css("width",  settings.width  == "fill" ? "100%" : parseInt(settings.height));
		event.data.frame.css("height", settings.height == "auto" ? body.outerHeight(true) + filler : parseInt(settings.height));
<!--		alert(body.outerHeight(true) + filler );-->
	}
	
	jQuery(this).children("iframe").each(onEachIframe);
};
var options = {
        width: "fill",          // width options are :
                                // 'fill' (default, equivalent to 100%),
                                // any valid CSS unit : '90%', '230px', '12em'
        height: "auto",         // height options are :
                                // 'auto' (default, will adapt iframe height to
								// its content, the more content, the higher)
                                // any valid CSS unit : '90%', '230px', '12em'
        autoUpdate : true       // 'true' (default, automatically update iframe
								// height on content changes in the future) or
								// 'false'

};
$(document).ready(function() {
	iframeRes = $("#framebox").iframeResize(options);
});
function hIframe(){
	var frame = jQuery('#siteContent');
	var body = frame.contents().find("body");
	// Creating custom :external selector
// $.expr[':'].external = function(obj){
// return !obj.href.match(/^mailto\:/)
// && (obj.hostname != location.hostname);
// };  
	frame.contents().find('a:not([href^="http://"])').click(function(){
        $('html, body').animate({scrollTop:520}, 'slow');
//        this.scrollTo( '#siteContent', 800, {easing:'elasout'} );
//        return false;
    });

	frame.contents().find('a[href^="http://"]')
	  .attr({
	    target: "_blank", 
	    title: "Opens in a new window"
	  });
// .append(' [^]');
	// Add 'external' CSS class to all external links
// frame.contents().find('a:external').css('background-color', 'yellow');
}
