var NEF = window.NEF || {};

NEF.AjaxEvent = function() {
  return this;
}

NEF.AjaxEvent.prototype = {

  subscribe: function(fn, oScope) {
    if (!this.oEvent) {
      this.oEvent = new YAHOO.util.CustomEvent("ajaxevent", this, false, YAHOO.util.CustomEvent.FLAT);
    }
    if (oScope) {
      this.oEvent.subscribe(fn, oScope, true);
    } else {
      this.oEvent.subscribe(fn);
    }
  },

  connect: function(sUri) {
    if (!sUri && !this.sUri) {
      return false;
    } else {
      this.sUri = (!sUri) ? this.sUri : sUri;
      this.dt = new Date().valueOf();
      this.sUri = (this.sUri.indexOf("?") === -1) ? this.sUri + "?yaetime=" + this.dt : ((this.sUri.indexOf("yaetime") === -1) ? this.sUri + "&yaetime=" + this.dt : this.sUri.replace(/yaetime=[0-9]+/i, "yaetime=" + this.dt));
      YAHOO.util.Connect.asyncRequest('GET', this.sUri, {
        success: function (o) {
          this.oEvent.fire(o.responseText);
        },
				failure: function(o) {
					;
				},
        scope: this
      });
    }
  }
}


// custom object
function RotatedImage(name, src, oImage) {
    this.name = name;
		this.src = src;
		this.o = document.getElementById(this.name);
		
		this.html = function(){
			var re = /(\d+)/;
			var id = this.src.toString().match(re);
			if(id){
				id = id[1];
				var link = 'http://fvsm.info/main.php?g2_view=html.HtmlChickbot&g2_chickid='+id;
				var html = '<a href="'+link+'"><img src="'+this.src+'" width="75" height="75"></a>';
//				var html = this.src;
				return html;
			}
			return "";
		}

		this.o.innerHTML = this.html();		
		
		//this.link = 'main.php?g2_view=html.ChickbotCallback&g2_chickid='+this.id;
		//this.html = '<a href="'+this.link+'"><img id="'+this.name+'" src="'+this.src+'"></a>';
		
		
    // define a custom event
    this.change = new YAHOO.util.CustomEvent("change", this);
		if(oImage){
			this.oImage = oImage;
			this.oImage.change.subscribe(this.onChange, this);
		}
}

RotatedImage.prototype.onChange = function(type, args, observer) {
	observer.o.innerHTML = this.html();
	this.src = args;
	this.o.innerHTML = this.html();
	//alert(this.html());
	
}
