function ImageGalleryXML() {
	
	this.list = function(sectionId, type, callback) {
		me.listCallback = callback;
		var xml = new XMLTransferHelper();
		var doc = xml.createDocument();
		var root = doc.createElement("request");
		
		var e = doc.createElement("requesttype");
		e.appendChild(doc.createTextNode("listimages"));
		root.appendChild(e);
		
		e = doc.createElement("sectionid");
		e.appendChild(doc.createTextNode(sectionId));
		root.appendChild(e);
		
		e = doc.createElement("type");
		e.appendChild(doc.createTextNode(type));
		root.appendChild(e);
		
		doc.appendChild(root);
		xml.sendDocument("/lib/image_gallery/xml/image_gallery.xml.php", doc, me.listResponse);
	};
	
	this.listResponse = function(doc) {
		if(!me.testDoc(doc)) {
			me.listCallback(null);
		} else {
			var nodes = doc.getElementsByTagName("image");
			var images = new Array();
			for(var i=0; i<nodes.length; i++) {
				images[i] = me.toNode(nodes[i]);
			}
			var response = new Object();
			response.images = images;
			response.total = doc.documentElement.getAttribute("total");
			me.listCallback(response);
		}
	};
	
	this.toNode = function(node) {
		var image = new Image();
		for(var i=0; i<node.childNodes.length; i++) {
			switch(node.childNodes[i].nodeName) {
				case "id": image.id = me.nodeVal(node.childNodes[i]);
				case "img_path": image.img_path = me.nodeVal(node.childNodes[i]);
				case "title": image.title = me.nodeVal(node.childNodes[i]);
				case "description": image.description = me.nodeVal(node.childNodes[i]);
				case "sectionId": image.sectionId = me.nodeVal(node.childNodes[i]);
			}
		}
		return image;
	};
	
	this.testDoc = function(doc) {
		if(!doc || !doc.documentElement) {
			return false;
		}
		if(doc.documentElement.nodeName == "exception") {
			if(doc.documentElement.firstChild)
				throw doc.documentElement.firstChild.nodeValue;
			throw "an exception occurred during xml transaction";
		}
		return true;
	};
	
	this.nodeVal = function(node) {
		if(!node || !node.firstChild || !node.firstChild.nodeValue) return "";
		return node.firstChild.nodeValue;
	};
	
	var me = this;
	
	this.listCallback = null;
}

function Image() {
	this.id;
	this.img_path;
}