function GisGasAPI() {}
GisGasAPI.prototype.invokeFunction = function(sClass, sFunction, callback, params) {
	var head;
	var script;

	if (!params) 
		params = new Array();
		
	params['random'] = Math.random();

	var url = "http://www.gisgas.hu?load=api&class=" + sClass + "&function=" + sFunction + "&callback=" + callback;
	// var url = "http://test.gisgas.hu?load=api&class=" + sClass + "&function=" + sFunction + "&callback=" + callback;
	// var url = "http://localhost/devel/gisgas/web/?load=api&class=" + sClass + "&function=" + sFunction + "&callback=" + callback;
	// var url = "http://192.168.5.10/devel/gisgas/web/?load=api&class=" + sClass + "&function=" + sFunction + "&callback=" + callback;
	// var url = "http://195.70.45.170:8080/web/?load=api&class=" + sClass + "&function=" + sFunction + "&callback=" + callback;
	
	for(key in params) {
		url += "&" + key + "=" + params[key];
	}

	// window.document.write(url + "<br/>");

	script = window.document.createElement("script");
	script.src = url;

	head = window.document.getElementsByTagName("head")[0];
	head.appendChild(script);
}

// API class for Post
function GisGasPost() {}
GisGasPost.prototype.getListForUser = function (userId, count, callbackName) {
	GisGasAPI.prototype.invokeFunction("post", "getListForUser", callbackName, {userId:userId, count:count});
}
GisGasPost.prototype.getRandomPhoto = function (width, height, callbackName) {
	GisGasAPI.prototype.invokeFunction("post", "getRandomPhoto", callbackName, {width:width, height:height});
}

// API class for User
function GisGasUser() {}
GisGasUser.prototype.get = function (userId, callbackName) {
	GisGasAPI.prototype.invokeFunction("user", "get", callbackName, {userId:userId});
}

// API class for Templates
function GisGasTemplates() {}
GisGasTemplates.prototype.getUserBox = function (prefix, callbackName) {
	GisGasAPI.prototype.invokeFunction("templates", "getUserBox", callbackName, {prefix:prefix});
}
GisGasTemplates.prototype.loadXMLString = function (txt) {
	try { //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc); 
	} catch(e) {
		try { //Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			return(xmlDoc);
		} catch(e) {alert(e.message)}
	}
	return(null);
}
