var show_big_img = {
    top : 0,
    left : 0,
/* ============= main window functions ============= */
    init : function(links, winWr)
	{
	    this.links = links;
	    this.winWr  = winWr ? winWr : _wrapper;

	    this.winWr.setOnloadListener(this);
		this.winWr.setOnUnloadListener(this, "close_popup");
	},
    onload : function(evtWr)
    {
    	var link;
    	this.winWr.removeOnloadListener(this);

    	for(var i =0; i<this.links.length; i++) {
    		link = this.winWr.getElement(this.links[i].id);
    		if (link.elm) {
    		    this.links[i].wr = link;
    			link.addListener(this, "onclick").num = i;
    		}
    	}
    },

    onclick : function(evtWr, par)
    {
        evtWr.eventDrop();
        var linkWr = this.links[par.num].wr;
        this.w = this.links[par.num].w;
        this.h = this.links[par.num].h;
		this.imgSrc = this.links[par.num].src;
        linkWr.elm.blur();
        if(this.popupWr && this.popupWr.win) {
        	try {
	    		this.popupWr.win.focus();
	            this.requestImage();
        	} catch (e) {
        		this.popupWr = null;
        	}
        }
        if(!this.popupWr) {
            open(linkWr.elm.href + "?js=1", "photo", "width=" + this.w + ",height=" + this.h + ",top=" + (window.screen.availHeight - this.h)/2 + ",left=" + (window.screen.availWidth - this.w)/2);
        }
    },
/* ============= Pop-Up window functions ============= */
	popup_init : function(popupWin)
	{
		this.popupWr = new winWrapper(popupWin);
		this.popupWr.setOnloadListener(this, "onload_popup");
		this.popupWr.setOnUnloadListener(this, "onUnload_popup");
	},
	onload_popup : function()
	{
	    this.big_img   = this.popupWr.getElement("big_img");
		this.caption   = this.popupWr.getElement("caption");
		this.error_msg = this.popupWr.getElement("error_msg");

		this.big_img.addListener(this, "onload", "onloadImage");
		this.big_img.addListener(this, "onerror", "onErrorImage");

		this.requestImage();
	},
	close_popup : function()
	{
		try {
	      this.popupWr.win.close();
	    } catch (e) {}
	    this.onUnload_popup();
	},
	onUnload_popup: function()
	{

		this.popupWr = null;
	},
	requestImage : function()
	{
		if(this.big_img.elm.src != this.imgSrc) {
     	    if ((this.popupWr.getWindowTop()==this.top) && (this.popupWr.getWindowLeft()==this.left)) {
	            this.popupWr.win.moveTo((window.screen.availWidth - this.w)/2,(window.screen.availHeight - this.h)/2);
    	    }
    		this.top = this.popupWr.getWindowTop();
    		this.left = this.popupWr.getWindowLeft();
		    this.caption.show();
    	    this.big_img.hide();
    	    this.popupWr.win.resizeTo(this.w, this.h);
    	    this.big_img.elm.src = this.imgSrc;
    	    var delta_x=this.w-this.popupWr.getWindowWidth();
			var delta_y=this.h-this.popupWr.getWindowHeight();
    	    if (delta_x || delta_y) this.popupWr.win.resizeBy(delta_x, delta_y);
		}
	},
	onloadImage : function()
	{
  	    this.caption.hide();
		this.big_img.show();
	},
	onErrorImage : function()
	{
  	    this.caption.hide();
		this.error_msg.show();
		this.big_img.elm.src = "";
	}
}
