var prefix, currently_displayed = new String();
prefix="pic_container";
currently_displayed=1;

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}

function loadGallery(){
	// parse gallery.xml and display gallery
	
	//alert('parse gallery.xml and display gallery');	
	ajo.sendRequest(arguments[0], 'x=' + arguments[2], arguments[1]);
	
}


/*START AJAX OBJECT*/

function ZuAjax (onload,onerror){
	this.req=null;
	this.onload=onload;
	this.onerror = this.defaultError;
	this.READY_STATE_UNINITIALIZED=0;
	this.READY_STATE_LOADING=1;
	this.READY_STATE_LOADED=2;
	this.READY_STATE_INTERACTIVE=3;
	this.READY_STATE_COMPLETE=4;

	this.onReadyState = function () {
		var ready=this.req.readyState;
		if (ready==this.READY_STATE_COMPLETE){
			var httpStatus=this.req.status;
			if (httpStatus==200 || httpStatus==0){ // status okay, or client aborted
				this.onload.call(this);
			}else{
				this.onerror.call(this);
			}
		}
	}

	this.initXMLHTTPRequest = function () {
		if (window.XMLHttpRequest){
			this.req=new XMLHttpRequest();
		} else if (window.ActiveXObject){
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	// initialize this object
	this.initXMLHTTPRequest();

	this.sendRequest = function (url, params, httpMethod) {
	//this.sendRequest = function (url, params) {
		if (this.req){
			try{
				var loader=this;
				
				this.req.onreadystatechange=function(){
					loader.onReadyState.call(loader);
				}
				this.req.open(httpMethod, url);
				this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				this.req.send(params);
			}catch (err){
				this.onerror.call(this);
			}
		}
	}

	this.defaultError = function () {
		alert("error fetching data!" +"\n\nreadyState:"+this.req.readyState +"\nstatus: "+this.req.status +"\nheaders: "+this.req.getAllResponseHeaders());
	}

	this.setHandler = function(handler) {
		this.onload	= handler;
	}


	/*
	 * Define Accessor Methods
	 */
	this.getResponseXMLDocumentElement = function () {
		return this.req.responseXML.documentElement;
	}

	this.getResponseXML = function () {
		return this.req.responseXML;
	}

	this.getResponseText = function () {
		return this.req.responseText;
	}
}

/*END AJAX OBJECT*/

function handleXMLResponse () {
data = ajo.getResponseXMLDocumentElement();	

	if(data.getElementsByTagName('src0')[0]){
		
		handleGalleryResponse(data);
	}
}

function handleGalleryResponse(data){


first_photo=document.getElementById('photo-container');
first_photo_src=data.getElementsByTagName('bigsrc0')[0].firstChild.nodeValue;

first_photo.innerHTML="<img src="+first_photo_src+" id='pic_container1' height='245' width='375' /> ";


	total_num_photos = data.getElementsByTagName('numimages')[0].firstChild.nodeValue;
	alert(total_num_photos);
	

	

	
}


function getPreviousPhoto(){
	current_photo=document.getElementById('photo-container');
	current_photo.innerHTML="hello";
	
}
function getNextPhoto(){
	current_photo=document.getElementById('photo-container');	
	current_photo.innerHTML="hello";
}






ajo=new ZuAjax(handleXMLResponse, false);
