/**
 * Yahonza popup
 */

var __activePopup= "none";

var YahPopup = Class.create
({

  initialize: function(target, url, close, width, height)
  {
    this.target=target;
    this.url=url;
    this.close=close;
    this.width=width;
    this.height=height;
  },


  render: function()
  {
    __activePopup=this;
    new Ajax.Request(this.url, {asynchronous: true,
                                method: 'get',
                                onSuccess: this.renderPopup,
                                onFailure: this.renderPopupFail});
  },


  renderPopup: function(response)
  {
    var html = "";
    var content = response.responseText;
    var target = __activePopup.target;
    var close = __activePopup.close;
    var width = __activePopup.width;
    var height = __activePopup.height;

    html = "<div class=\"popup_block\" style=\"width: " + width + "; height: " + height + "px\">";
		html += "<div class=\"popup\" style=\"height: 350px\">";
	  html += "<a href=\"javascript:" + close + "()\"><img src=\"/new/public/components/yahpopup/icon_close.png\" class=\"cntrl\" title=\"Close\"></a>"
    html += content;
		html += "</div>";
    html += "</div>";
    $(target).innerHTML = html;
    $(target).appear({duration : 0.5});
  },


  renderPopupFail: function(response)
  {
    alert("failed to get popup content");
  },


  destroy: function()
  {
    $(this.target).fade({duration : 0.5});
  }
});

