var _url = "";
var _text = "";
var _playerOpen = false;
var _playerInit = false;
var _popup = null;

$(document).ready(function(){		
	initPageFlash();		
});

function addPlayer(){	
	var flashvars = {};
	var params = {allowfullscreen:"true", allowscriptaccess:"always",  allownetworking:"all"};
	var attributes = {id:"SignThisPlayerFlash"};
	
	$("#SignThisPlayer").append("<div id='SignThisPlayerInner'></div>");
		
	swfobject.embedSWF("/flash/generalpopup.swf?v="+playerVersion, "SignThisPlayerInner", "775", "390", "9.0.0","/flash/expressInstall.swf", flashvars, params, attributes);	         
}
function removePlayer(){
	swfobject.removeSWF("SignThisPlayerFlash");
}

function playSignThis(url, text, serverurl){
	var leftDistance = 0;
	var topDistance  = 0;
	
	_url = url;
	_text = text;
	_cdnserver = serverurl
	
	$("#SignThisPlayer").show();

	if(!_playerOpen) addPlayer();
	
	leftDistance = ($(window).width() - $('#SignThisPlayer').width())/2;
	topDistance = $(window).scrollTop() +  ($(window).height()-$('#SignThisPlayer').height())/2;
	
	$('#SignThisPlayer').css({position:"absolute",top:topDistance,left:leftDistance});	

	if(_playerOpen){
		getFlashMovie("SignThisPlayerFlash").init([_url, _text,_cdnserver]);
	}
	else{								
		hidePageFlash();									
		_playerOpen = true;			
	}
		
	return false;
}

function close(){	
	//retore flash
	removePlayer();	
	initPageFlash();			
	_playerOpen = false;
	$("#SignThisPlayer").hide();
}

function flashIsReady(){
	getFlashMovie("SignThisPlayerFlash").init([_url, _text,_cdnserver]);
}

function sendToJavaScript(value) {		
	if(value == "close"){
		close();
	}
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function initPageFlash(){
	// it's up to the page to have this functions defined	
	try{
		initFlash();
	}
	catch(e){}	
}

function hidePageFlash(){
	// it's up to the page to have this functions defined
	try{
		removeFlash();
	}
	catch(e){}		
}
