/**
 * 
 * Creates an Yritystele customized OpenLayers-popup.
 * 
 * @param content
 * @param size
 * @param lonlat
 * @returns an OpenLayers popup with custom look and feel.
 */
function popupFactory(content, size, lonlat) {
    size = typeof (size) != 'undefined' ? size : new OpenLayers.Size(200, 240);
    xy = map.getPixelFromLonLat(lonlat);
    popup = new OpenLayers.Popup.Framed(
	    "featurePopup",
	    lonlat,
	    size,
	    content,
	    anchor=null,
	    closeButtonX=true,
	    null
    );
    popup.imageSrc = "/Bisnode/lib/img/cloud-popup-relative_gimp.png";
    popup.imageSize = new OpenLayers.Size(1276, 736);
    centerX = map.getSize().w / 2;
    locationY = map.getSize().h - size.h / 2;
    dx = xy.x - centerX;
    dy = xy.y - locationY;
    popup.panMapIfOutOfView = false;
    map.pan(dx, dy);
    //map.panTo(lonlat);
    popup.autoSize = false;
    popup.calculateRelativePosition = function () { return 'tl'; };
    popup.positionBlocks = {
        "tl": {
            'offset': new OpenLayers.Pixel(115, -10),
            'padding': new OpenLayers.Bounds(6, 40, 8, 9),
            'blocks': [
	        	{ // top-left
	        		size: new OpenLayers.Size('auto', 'auto'),
	        		anchor: new OpenLayers.Bounds(0, 51, 22, 0),
	        		position: new OpenLayers.Pixel(0, 0)
	        	},
	        	{ //top-right
	        		size: new OpenLayers.Size(24, 'auto'),
	        		anchor: new OpenLayers.Bounds(null, 50, 0, 0),
	        		position: new OpenLayers.Pixel(-1238, 0)
	        	},
	        	{ //bottom-left
	        		size: new OpenLayers.Size('auto', 19),
	        		anchor: new OpenLayers.Bounds(0, 32, 22, null),
	        		position: new OpenLayers.Pixel(0, -631)
	        	},
	        	{ //bottom-right
	        		size: new OpenLayers.Size(24, 18),
	        		anchor: new OpenLayers.Bounds(null, 32, 0, null),
	        		position: new OpenLayers.Pixel(-1238, -632)
	        	},
	        	{ // stem
	        		size: new OpenLayers.Size(32, 33),
	        		anchor: new OpenLayers.Bounds(null, 0, 100, null),
	        		position: new OpenLayers.Pixel(-434, -679)
	        	}
	        ]
        },
        "tr": {
            'offset': new OpenLayers.Pixel(-45, 0),
            'padding': new OpenLayers.Bounds(8, 40, 8, 9),
            'blocks': [
	        	{ // top-left
	        		size: new OpenLayers.Size('auto', 'auto'),
	        		anchor: new OpenLayers.Bounds(0, 51, 22, 0),
	        		position: new OpenLayers.Pixel(0, 0)
	        	},
	        	{ //top-right
	        		size: new OpenLayers.Size(22, 'auto'),
	        		anchor: new OpenLayers.Bounds(null, 50, 0, 0),
	        		position: new OpenLayers.Pixel(-1238, 0)
	        	},
	        	{ //bottom-left
	        		size: new OpenLayers.Size('auto', 19),
	        		anchor: new OpenLayers.Bounds(0, 32, 22, null),
	        		position: new OpenLayers.Pixel(0, -631)
	        	},
	        	{ //bottom-right
	        		size: new OpenLayers.Size(22, 19),
	        		anchor: new OpenLayers.Bounds(null, 32, 0, null),
	        		position: new OpenLayers.Pixel(-1238, -631)
	        	},
	        	{ // stem
	        		size: new OpenLayers.Size(81, 35),
	        		anchor: new OpenLayers.Bounds(0, 0, null, null),
	        		position: new OpenLayers.Pixel(-215, -687)
	        	}
	        ]
        },
        "bl": {
            'offset': new OpenLayers.Pixel(45, 0),
            'padding': new OpenLayers.Bounds(8, 9, 8, 40),
            'blocks': [
	        	{ // top-left
	        		size: new OpenLayers.Size('auto', 'auto'),
	        		anchor: new OpenLayers.Bounds(0, 21, 22, 32),
	        		position: new OpenLayers.Pixel(0, 0)
	        	},
	        	{ //top-right
	        		size: new OpenLayers.Size(22, 'auto'),
	        		anchor: new OpenLayers.Bounds(null, 21, 0, 32),
	        		position: new OpenLayers.Pixel(-1238, 0)
	        	},
	        	{ //bottom-left
	        		size: new OpenLayers.Size('auto', 21),
	        		anchor: new OpenLayers.Bounds(0, 0, 22, null),
	        		position: new OpenLayers.Pixel(0, -629)
	        	},
	        	{ //bottom-right
	        		size: new OpenLayers.Size(22, 21),
	        		anchor: new OpenLayers.Bounds(null, 0, 0, null),
	        		position: new OpenLayers.Pixel(-1238, -629)
	        	},
	        	{ // stem
	        		size: new OpenLayers.Size(81, 33),
	        		anchor: new OpenLayers.Bounds(null, null, 0, 0),
	        		position: new OpenLayers.Pixel(-101, -674)
	        	}
	        ]
        },
        "br": {
            'offset': new OpenLayers.Pixel(-44, 0),
            'padding': new OpenLayers.Bounds(8, 9, 8, 40),
            'blocks': [
	        	{ // top-left
	        		size: new OpenLayers.Size('auto', 'auto'),
	        		anchor: new OpenLayers.Bounds(0, 21, 22, 32),
	        		position: new OpenLayers.Pixel(0, 0)
	        	},
	        	{ //top-right
	        		size: new OpenLayers.Size(22, 'auto'),
	        		anchor: new OpenLayers.Bounds(null, 21, 0, 32),
	        		position: new OpenLayers.Pixel(-1238, 0)
	        	},
	        	{ //bottom-left
	        		size: new OpenLayers.Size('auto', 21),
	        		anchor: new OpenLayers.Bounds(0, 0, 22, null),
	        		position: new OpenLayers.Pixel(0, -629)
	        	},
	        	{ //bottom-right
	        		size: new OpenLayers.Size(22, 21),
	        		anchor: new OpenLayers.Bounds(null, 0, 0, null),
	        		position: new OpenLayers.Pixel(-1238, -629)
	        	},
	        	{ // stem
	        		size: new OpenLayers.Size(81, 33),
	        		anchor: new OpenLayers.Bounds(0, null, null, 0),
	        		position: new OpenLayers.Pixel(-311, -674)
	        	}
	        ]
        }
    };
    return popup;
}
