jQuery(document).ready(function(){
	jQuery(".hand_replay").click(function(){
		var serverName = "http://www.pokersavvy.com";
		var linkClass = this.id;
		var handId = linkClass.split('_')[1];

		// waiting...
		loadPopup();
		centerPopup();
		
		// ajax call to replace waiting
		jQuery("#popupContent").html("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='800' height='550' id='pokersavy_8' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='"+serverName+"/pokersavy_8.swf?file="+serverName+"/plus/hand/" + handId + "/hanzo.xml?single=1' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+serverName+"/pokersavy_8.swf?file="+serverName+"/plus/hand/" + handId + "/hanzo.xml?single=1' quality='high' bgcolor='#ffffff' width='800' height='550' name='pokersavy_8' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");

		return false;
	});
	
	
	jQuery("<div id='backgroundPopup'><div id='popupReturn'><a href='#' id='popupClose'>Return to<br />Blog</a></div><div id='popupContent'>Loading replayer... (<a href='#' id='popupClose'>Cancel</a>)</div>	</div>").appendTo("body");

	jQuery("#popupClose").click(function(){
		disablePopup();
		return false;
	});

});

var popupStatus = 0; 

function loadPopup(){
	//loads popup only if it is disabled
	if (popupStatus==0) {
		jQuery("#backgroundPopup").css({
			"opacity": "1"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popupContent").fadeIn("slow");
		jQuery("#popupReturn").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1) {
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popupContent").fadeOut("slow");
		jQuery("#popupReturn").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	jQuery("#popupContent").css(
		{
		"position": "absolute",
		"left": windowWidth/2 - 800/2 + 'px',
		"top": windowHeight/2 - 550/2 + 'px'
		}
	);
	jQuery("#popupReturn").css(
		{
		"position": "absolute",
		"left": '0px',
		"top": '0px'
		}
	);
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});

}
