function getFlashMovieObject(movieName)	{
 	if (window.document[movieName])
      	return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName])
      		return document.embeds[movieName]; 
	}
	else
		return document.getElementById(movieName);
}
		
//API äîáàâëåíèÿ ðåçóëüòàòà
function addResult(module, result, maxResult) {
	function _afterAddResult(data) {
		flashMovie = getFlashMovieObject("sb-content");
		if (data.result == "success") {
			
		}
		else {
			
		};
		flashMovie.addResult(data.result);
	}

	var params = {};
	params["module"] = module;
	params["result"] = result;
	$.post("do.php?action=addResult", params, _afterAddResult, 'json');
}
		
function toggleFavourite(module) {
	function _afterToggleFavourite(data) {
		returnHandler(data, "none");
	}
	var params = {};
	params["module"] = module;
	$.post("do.php?action=toggleFavourite", params, _afterToggleFavourite, 'json');
}
		
function getModuleState(module) {
	function _afterGetModuleState(data) {
		flashMovie = getFlashMovieObject("sb-content");
		flashMovie.getModuleState(data.lastResult, data.isFavourite);
	}
			
	var params = {};
	params["module"] = module;
	$.post("do.php?action=getModuleState", params, _afterGetModuleState, 'json');
}

function closeWindow() {
	Shadowbox.close();
}

function returnHandler(data, redirect) {
	redirect = redirect || "";

	switch (data.result) {
		case "normal": color = "green"; textColor = "white"; break;
		case "info": color = "yellow"; textColor = "black"; break;
		case "fatal": color = "red"; textColor = "white"; break;
	};

	$.jnotifica(data.text, {
		margin : 10,
		width  : 400,
		effect : 'fade',
		color : textColor,
		background: color,
		padding: 25,
		msgCss : {
			textAlign : 'center',
			fontWeight: 'bold'
		},
		close : {
			text: '[X]',
			css : {
				position: 'absolute',
				top: 5,
				right: 10,
				color: textColor,
				cursor: 'pointer'
			}
		},
		onClose : function() {
			if (data.result != "fatal") {
				switch (redirect) {
					case "none":
						break;
					case "": 
						window.location.reload(true);
						break;
					default:
						window.location.replace(redirect);
				};
			};
		}
	});
}

function logout() {
	$.get("do.php?action=logout", function (data) {
		returnHandler(data, "index.php");
	}, 'json');
}
