$(document).ready( function(){							
	//prevent survey box from flashing
	$(".box").css(
		{
			position:"absolute",
			top:-1000,
			left:-1000,
			display:"none",
			visibility:"hidden"

		}
	);
	$(window).resize(function(){resize($(".box_content").width(),$(".box_content").height(),10);});
	//$("iframe").css({"backgroundColor":"white",border:0,overflow:"hidden", opacity:1, padding:0, margin:0});
	$("iframe").css({"backgroundColor":"white",border:0,overflow:"hidden", padding:0, margin:0});
	//Set style without stylesheet
	$("table.box").css({
				"border-collapse":"collapse",
				border:0
			});
	$("table.box *").css({
				border:"none",
				padding:0,
				margin:0
			});
	
	
	scrolled = $("html").scrollTop();
	height = $(window).height();
	width = $(window).width();	
	bw = $(".box").width();
	bh = $(".box").height();
	
	starth = (height + scrolled)/2-($(".box").height()/2);
	startw = width/2-($(".box").width()/2);
	$(".box").css(
		{
			position:"absolute",
			top:starth,
			left:-1000,
			display:"",
			visibility:"hidden"

		}
	);
	$(".box_content").css({width:300, height:100, "backgroundColor":"white",position:"relative"}).parent().css("backgroundColor","white");
	$("#iframe_content").load( function(e){												
		if ($("#iframe_content").attr("src") != "")
		{
		resize($("#iframe_content").contents().find("body").width(),$("#iframe_content").contents().find("body").height()+15);
		$(".box").css({"visibility":""});
		}
	}).change(function(){
		if ($("#iframe_content").attr("src") != "")
		{
		resize($("#iframe_content").contents().find("body").width(),$("#iframe_content").contents().find("body").height()+15);
		$(".box").css({"visibility":""});
		}
	}).css("overflow","hidden");		

	
});








function show_box()
{
	//$(".box").css({display:"",opacity:1});	
}

function resize(w,h,t)
{	
	$("#iframe_content").contents().find("body").css({visibility:"visible",opacity:0});
	if (!t)	
		t = 2000;
	w = ($(window).width()-76 < w )? $(window).width()-76 : w;
	h = ($(window).height()-66 < h )? $(window).height()-66 : h;												 
	
	tp = (($(window).height() -h)/2 + $("html").scrollTop() - 28 > 10 )? ($(window).height() -h)/2 + $("html").scrollTop() - 28: 10;
	l = (($(window).width() -w)/2 - 28 > 10)? ($(window).width() -w)/2 - 28: 10;
	$("#iframe_content").css("overflow","auto")
	$(".box_content").animate({height:h,width:w},t,function()																{
			if ($("#iframe_content").contents().find("body").width() + 15 < w  ||  $("#iframe_content").contents().find("body").width() > w + 15)
			{
				//alert("Original W = " + w + "\n New W = " + $("#iframe_content").contents().find("body").width());
				resize($("#iframe_content").contents().find("body").width(),h,100);
			}
			else if ($("#iframe_content").contents().find("body").height() + 15 < h ||  $("#iframe_content").contents().find("body").height() > h + 15)
			{
				//alert("Original H = " + h + "\n New H = " + $("#iframe_content").contents().find("body").height());
				resize(w,$("#iframe_content").contents().find("body").height(),100);
			}
			else
			{
				$(".box").animate({top:tp,left:l},100,function(){$("#iframe_content").css({"overflow":"hidden"}).contents().find("body").css({visibility:"visible",opacity:0}).animate({opacity:1},500);});

			}
	});
	$(".box").animate({top:tp,left:l},t)

}
function close_box()
{
		$(".box").css({display:"none",opacity:1}).css("left",-($(".box").width()+30));
}

function survey(url)
{
	show_box();
	$("#iframe_content").attr("src" , url);
}
