
var sRayUrl = "http://loveme.eu/ray/";
/*if(window.location.href.match(/http:\/\/www./)==null)
	var sRayUrl = "http://thepurplerabbit.com/ray/";
else
	var sRayUrl = "http://www.thepurplerabbit.com/ray/";*/

	
var aRayApps = {};

var userId = getCookie("memberID");
updateRayUserStatus(userId);

function getCookie(name)
{		
	var leftPart = name + "=";
	var aCookies = document.cookie.split(";");

	for(var i=0; i<aCookies.length; i++)
	{
		var sCookie = aCookies[i];
		while(sCookie.charAt(0) == " ") sCookie = sCookie.substring(1, sCookie.length);
		if(sCookie.indexOf(leftPart) == 0) return sCookie.substring(leftPart.length, sCookie.length);
	}
	return "";
}


function updateRayUserStatus(sUserId)
{
	var XMLHttpRequestObject = false;		
	if(userId != "")
	{			
		var d = new Date();
		var url = sRayUrl + "XML.php?action=updateOnlineStatus&id=" + userId + "&_t=" + d.getTime();
		if(window.XMLHttpRequest)
		{
			XMLHttpRequestObject = new XMLHttpRequest();		
		}
		else if(window.ActiveXObject)
		{
			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");			
		}	
		if(XMLHttpRequestObject)
		{
			XMLHttpRequestObject.open("GET", url);		
			XMLHttpRequestObject.send(null);	
		}
	}
}


function openRayWidget(sModule, sApp)
{
	//global sRayUrl;
	
	
	window.aRayApps = {};
	
	
	//base begin
	aRayApps.global = {};
	aRayApps.global.admin = {"params": {0:'nick', 1:'password'}, "top": 0, "left": 0, "width": 800, "height": 600, "resizable": 0};
	//base end
	
	//chat begin
	aRayApps.chat = {};
	aRayApps.chat.user = {"params": {0:'id', 1:'password'}, "top": 0, "left": 0, "width": 730, "height": 515, "resizable": 1};
	//chat end
	
	//im begin
	aRayApps.im = {};
	aRayApps.im.user = {"params": {0:'sndId', 1:'password', 2:'rspId'}, "top": 0, "left": 0, "width": 490, "height": 610, "resizable": 1};
	//im end
	
	//video begin
	aRayApps.video = {};
	aRayApps.video.recorder = {"params": {0:'id', 1:'password'}, "top": 0, "left": 0, "width": 545, "height": 355, "resizable": 0};
	aRayApps.video.player = {"params": {0:'id'}, "top": 0, "left": 0, "width": 375, "height": 355, "resizable": 0};
	aRayApps.video.admin = {"params": {0:'nick', 1:'password'}, "top": 0, "left": 0, "width": 400, "height": 250, "resizable": 0};
	//video end
	
	//desktop begin
	aRayApps.desktop = {};
	//desktop end
	
	//mp3 begin
	aRayApps.mp3 = {};
	aRayApps.mp3.player = {"params": {0:'id', 1:'password', 2:'vId', 3:'song'}, "top": 0, "left": 0, "width": 350, "height": 310, "resizable" : 0 };
	aRayApps.mp3.editor = {"params": {0:'id', 1:'password'}, "top": 0, "left": 0, "width": 440, "height": 570, "resizable": 1};
	//mp3 end
	
	//presence begin
	aRayApps.presence = {};
	aRayApps.presence.user = {"params": {0:'id', 1:'password'}, "top": 0, "left": 0, "width": 240, "height": 600, "resizable": 1};
	//presence end
	
	//board begin
	aRayApps.board = {};
	aRayApps.board.user = {"params": {0:'id', 1:'password'}, "top": 0, "left": 0, "width": 750, "height": 760, "resizable": 0};
	//board end
	// finished by unnamed
	
	if(aRayApps[sModule][sApp] == undefined)
		return;
	
	var aInfo = aRayApps[sModule][sApp];
	var sUrl = sRayUrl + "index.php?module=" + sModule + "&app=" + sApp;			
	for(var i=0; i<arguments.length - 2; i++)
		sUrl += "&" + aInfo["params"][i] + "=" + arguments[i + 2];
		
	var popupWindow = window.open(sUrl, 'Ray_' + sModule + '_' + sApp + parseInt(Math.random()*100000), 'top=' + aInfo["top"] + ',left=' + aInfo["left"] + ',width=' + aInfo["width"] + ',height=' + aInfo["height"] + ',toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=' + aInfo["resizable"]);
	
	if( popupWindow == null )
		alert( "You should disable your popup blocker software" );
}
