1;
var sVersion = '1.0.31';
var gbShowMessages = false;

if (gbShowMessages)
	alert('JS version: ' + sVersion);

/*********************************************************************
Function Name: resultError
Reason:
	Handles the error responses from the server.
Parameters:
	oHTML		-> XMLHttpRequest object.
	statusText	-> Status Message.
	oError		-> Error object with the javascript error.
Returns:
	N/A.
**********************************************************************/
function resultError(oHTML, statusText, oError)
{
	try
	{
		if (!gbShowMessages) return false;
		if (oHTML.status == 0) return false;
		if (oError)
			sError = '\n' + oError.message + '\n';

		sError += oHTML.responseText;

		alert('NOTICE:\nAn error has ocurred (2).' + sError);
	}
	catch(oError)
	{
		alert('Error (resultError): ' + oError);
	}
}

/*********************************************************************
Function Name: result
Reason:
	Handles the responses from the server.
Parameters:
	responseText -> Response from the server.
	statusText	-> Status Message.
Returns:
	N/A.
**********************************************************************/
function result(responseText, statusText)
{
    try
    {
		if (responseText.substring(0,1) == '[' || responseText.substring(0,1) == '{' )
		{
	    	var oResult = eval('(' + responseText + ')');
	    	if (oResult.Ok)
	    	{
//*
				var flashvars = {};
				var params = {};
				var attributes = {};

flashvars.flv = location.protocol + '//' + location.hostname + location.pathname.replace(/index.html/g, '') + oResult.VideoPathFile;
				flashvars.width = 240;
				flashvars.height = 160;
				flashvars.autoload = 1;
				flashvars.showstop = 1;
				flashvars.showvolume = 1;
				flashvars.bgcolor1 = 'ffffff';
				flashvars.bgcolor2 = 'ffffff';
				flashvars.margin = 0;

				params.loop = "false";
				params.menu = "true";
				params.quality = "best";
				params.allowfullscreen = "true";
				params.allowscriptaccess = "always";

				attributes.id = "mpl";
				attributes.style = 'width: 240px !important; height: 160px !important;';

				swfobject.embedSWF("videos/flv-player.net.swf", "player", "240", "160", "9.0.0", false, flashvars, params, attributes);
//*/
/*
				var so = new SWFObject("/videos/player.swf",'mpl','240','160','9');

				$('#player').css('width', '240');
				$('#player').css('heigh', '160');

				so.addParam('allowscriptaccess','always');
				so.addParam('allowfullscreen','true');
				so.addParam('heigh','160');
				so.addParam('width','240');
				so.addParam('style','width: 240px !important; height: 160px !important;');
				so.addParam('flashvars','showstop=1&amp;file=' + location.protocol + '//' + location.hostname + location.pathname.replace(/index.html/g, '') + oResult.VideoPathFile);
				so.write('player');
// */

	    	}
	    	else
	    	{
	    		if (gbShowMessages) alert('Error result:\n' + oResult.ErrorMessage);
	    	}
		}
		else
		{
	    	if (gbShowMessages) alert('Response with error:\n' + responseText);
		}
    }
	catch(e)
	{
		if (gbShowMessages) alert('Error: ' + e.message);
	}
}

/************************************************************************************************
Function Name: chooseRandomVideo
Reason:
	Consults the video filename for the player using AJAX.
Parameters:
	sPath 		-> The paths where the videos are.
	sExtensions	-> The file extension (can be several separated by comma).
Returns:
	N/A
*************************************************************************************************/
function chooseRandomVideo(sPath, sExtensions)
{
	var url = 'ajax_randomVideo.php';
	var pars = 'path=' + unescape(sPath) + '&amp;ext=' + unescape(sExtensions);
	$.ajax(
	{
		async: true,
		type: "post",
		url: url,
		data: pars,
		dataType: "html",
		success: result,
		error: resultError
	});

}
