OpenLayers.Feature.WFS.Pics = OpenLayers.Class.create();
OpenLayers.Feature.WFS.Pics.prototype = 
OpenLayers.Class.inherit( OpenLayers.Feature.WFS, {
    
    createMarker: function() {        

        this.marker = OpenLayers.Feature.prototype.createMarker.apply(this); 

        /*
        */
        if(this.marker != null) {
            this.marker.events.register("click", this, this.createPopup);
            if(this.layer.opacity && this.layer.opacity != 1) {
                this.marker.setOpacity(this.layer.opacity);
            }
        }

        return this.marker;
    },
    
    /*
    */
    createPopup: function() {
        
        if(this.popup == null) {
            this.popup = OpenLayers.Feature.prototype.createPopup.apply(this, [true]);

            if(this.popup != null) {
                var file = this.data.pic.file;
                var picurl = "http://frumin.net/rpa/trx/pics/fb2br/" + file;
                var thumb = "http://frumin.net/rpa/trx/pics/fb2br/thumbs/" + file;

                
                var dim = 275;
                var size;
                var aspect = this.data.pic.aspect;
                if(aspect > 1) {
                    size =  new OpenLayers.Size(dim, dim / aspect);
                    
                }
                else {
                    size =  new OpenLayers.Size(dim * aspect, dim);
                }
                
                var html = '<a target="' + picurl + '" href="' + picurl + '">'
                    + file + '<BR>' 
                    + '<img width="' + size.w + '" height="' + size.h + '" src="' + thumb + '"><BR>Full Size Image</a>'


                this.popup.setContentHTML(html);
		var s = new OpenLayers.Size(size.w + 15, size.h + 55);
                this.layer.map.addPopup(this.popup);
                this.popup.setSize(s);
                this.popup.setBackgroundColor("#CCCCCC");




            }

            return this.popup;
        }
        else {
            this.layer.map.removePopup(this.popup);
            this.popup.destroy();
            this.popup = null;
        }
    },
    
    processXMLNode: function(xmlNode) {
        var data = OpenLayers.Feature.WFS.prototype.processXMLNode.apply(this, arguments);

        var file = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.frumin.net", "frumin", "file")[0]);
        var width = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.frumin.net", "frumin", "width")[0]);
        var height = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.frumin.net", "frumin", "height")[0]);

        /*
        var file = OpenLayers.Util.getXmlNodeValue(xmlNode.getElementsByTagName('file')[0]);
        var width = OpenLayers.Util.getXmlNodeValue(xmlNode.getElementsByTagName('width')[0]);
        var height = OpenLayers.Util.getXmlNodeValue(xmlNode.getElementsByTagName('height')[0]);
        */

        var aspect = width / height;
        
        var pic = { file: file, width: width, height: height, aspect: aspect};

        var isize;
        var dim = 100;
        if(aspect > 1) {
            isize = new OpenLayers.Size(dim, dim / aspect);
        }
        else {
            isize = new OpenLayers.Size(dim * aspect, dim);
        }            
    

        data.pic = pic;
        data.icon = new OpenLayers.Icon("http://frumin.net/rpa/trx/pics/fb2br/icons/" + file, isize);

        return data;
        
    },
     
    CLASS_NAME: "OpenLayers.Feature.WFS.Pics"
    
    
    
});
