// 6/2/2008 HanaDaddy  hanadaddy at gmail.com
 

function SarahAjax(url,actionfunc,errorfunc){
	this.url=url;
	this.reqobj ; 
	this.method="GET";
	this.async= true;
	
	if ( actionfunc ){
		this.action=actionfunc;
	}else if (!this.action) {
		//alert("Missing Action Function. It will be executed when we receive the reply");
		
	}
	if ( errorfunc ){ 
		this.error = errorfunc;
	}
	
	this.sendRequest = function() {
		if(this.reqobj == null){
    		if (window.XMLHttpRequest) {
				this.reqobj = new XMLHttpRequest();
    		} else if (window.ActiveXObject) {
    			this.reqobj = new ActiveXObject("Microsoft.XMLHTTP");
    		}
		}

		this.reqobj.open(this.method, this.url, this.async);

		var sajaxreq = this; // this is necessary to access myself in the callback function
		this.reqobj.onreadystatechange = function() { sajaxreq.callback(); }

		this.reqobj.send(null);
	}

	this.callback = function () {
 	 
		if (this.reqobj.readyState == 4) {
			if (this.reqobj.status == 200) {
				//alert("reply is back?"+this.reqobj.responseText);
				this.action(this.reqobj);
			}else{
			 	//alert("There was a problem retrieving data:\n" + this.reqobj.statusText);
			 	if (this.error){
			 		this.error(this.reqobj);
			 	}
			}
		}		
	}	
}


 
 
//SarahAjax.prototype.ExtraFunction = function () {
//}

function HanaRandomImage(url,period){
	this.inheritFrom = SarahAjax;
    this.inheritFrom(url);
  
	this.url=url;
	this.period=period;
	this.timerid = 0;
	this.target_id ="hanasarah";
	this.progress_id="hanari_progress";
	 
	this.count=0;
	this.start = function () {

		if (this.timerid){
			clearTimeout(this.timerid);
		}
		if (this.count > 5) {
  			return ;
		} 
  		progress=document.getElementById(this.progress_id);
        	if (progress) {
        		progress.style.display="block";
       		}
        
  		this.count++;
		this.sendRequest();
	}
  	
	this.action = function (obj) {
		//obj.responseText
		//obj.statusText
		//obj.responseXML
		var div=document.getElementById(this.target_id);
		if (obj && div){
			//alert(obj.responseText);
			div.innerHTML = obj.responseText;
		}
		//Check to see if you have lightbox enabled.
		if ( window.myLightbox  ) {
			myLightbox.updateImageList();
		}
 		var _self= this; 
		this.timerid = setTimeout( function () { _self.start(); } , this.period );
	}
} 
 
