
if (!obj) { var obj = new Object(); };


obj.AJAX = {
	request	:	null,
	
	httpRequest	:	function(reqType, url, asynch, respHandle){
		if (window.XMLHttpRequest)
			this.request = new XMLHttpRequest;
		else if(window.ActiveXObject){
			this.request = new ActiveXObject("Msxml2.XMLHTTP");
			if(!this.request)
				this.request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(this.request){
			if(reqType.toLowerCase() != "post")
				this.initReq(reqType, url, asynch, respHandle);
			else{
				var args = arguments[4];
				if(args!=null && args.length > 0)
					this.initReq(reqType, url, asynch, respHandle, args);
			}
		}
		else
			alert("XMLHTTP not present!");
	},

	initReq	:	function(reqType, url, bool, respHandle){
		try{
			this.request.onreadystatechange = respHandle;
			this.request.open(reqType, url, bool);
			if(reqType.toLowerCase() == "post"){
				this.request.setRequestHeader("Content-Type",
					"application/x-www-form-urlencoded; charset=UTF-8");
				this.request.send(arguments[4]);
			}	
			else
				this.request.send(null);
		}
		catch(errv){
			alert("the application cannot connect to the server right now!\n"+
				  "Error detail : " + errv.message);
		}
	}
}


obj.slideshow = {
	
	show	:	function(id){
		try{
			if ("" == id) throw new Error("id CANNOT BE EMPTY");
			var url = "/pages/slideshow.php?id=" + id;
			obj.AJAX.httpRequest("GET", url, true, obj.slideshow.handleRequest);
		}
		catch(err){
			alert("An error occured!\n"+
				  "Error detail : " + err.message);
		}
	},

	
	handleRequest	:	function(){
		if(obj.AJAX.request.readyState == 4){
			if(obj.AJAX.request.status == 200){
				var resp = obj.AJAX.request.responseText;
				var func = new Function("return "+resp);
				var objt = func();
				obj.slideshow.output(objt);
			}
		}
	},
	
	output	:	function(o){
		var action = o.action;
		var img = $("gallery_img");
		img.src = "/uploaded/gallery/" + o.image;
		var caption = $("gallery_caption");
		caption.innerHTML = o.caption;
	}
}
