/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var _Popup = {
	on : function (title,content) {
		$('popupBg').show();
		$('popupBg').style.zIndex = 1000;		
		$('popupWin').show();
		$('popupWin').style.zIndex = 1005;		
		this.updTitle(title);
		this.updContent(content);
		this.resize();
		$('popupClose').focus();
	},
	resize : function () {
		var w = $('popupWin').offsetWidth;
		var h = $('popupWin').offsetHeight;
		// don't work on IE without DOCTYPE...
		// use screen.width or screen.height to avoid...
		var dw = document.viewport.getWidth();
		var dh = document.viewport.getHeight();
//console.log(dw+'x'+dh+' '+w+'x'+h);
		//var z = 0.5;
		//if (w>parseInt(dw*z)) {
			//w = parseInt(dw*z);
			//$('popupWin').style.width = w+'px';
			//var h = $('popupWin').offsetHeight;
		//}
		$('popupWin').style.left = parseInt(dw/2-w/2)+'px';
		$('popupWin').style.top = parseInt(dh/2-h/2)+'px';		
	},
	img : function (src,alt) {
		this.on('Image','<img class="auto photo" src="'+src+'" alt="'+alt+'"/>');
		var c = $('popupContent');
		c.style.width = c.select('img')[0].offsetWidth+'px';
		c.style.height = c.select('img')[0].offsetHeight+'px';
		this.resize();
	},
	off : function () {
		$('popupWin').hide();
		$('popupBg').hide();
		this.updTitle('');
		this.updContent('');
	},
	updTitle : function (title) {
		$('popupTitle').update(title.toString());
	},
	updContent : function (content) {
		var re = new RegExp('\\r?\\n','g');
		$('popupContent').update(content.toString().replace(/\n/g,'<br/>'));
	},
	initTpl : function () {
		var div = E('div').update('\
		<div id="popupBg" style="display:none"></div>\
		<div id="popupWin" class="boxradius10 shadow10" style="display:none">\
			<table id="popupHeader" class="boxradiustop10">\
				<tbody>\
					<tr>\
						<td><span id="popupTitle">?</span></td>\
						<td align="right"><img src="/mod/js/Popup/img/stop.png" alt="'+_Lang.tr('CloseWindow')+'" title="'+_Lang.tr('CloseWindow')+'" onclick="_Popup.off()"/></td>\
					</tr>\
				</tbody>\
			</table>\
			<div id="popupContent">\
			</div>\
			<div id="popupFooter" class="boxradiusbottom10">\
				<a href="javascript:_Popup.off()" id="popupClose"><img src="/mod/js/Popup/img/close.'+lang+'.png" alt="'+_Lang.tr('Close')+'"/></a>\
			</div>\
		</div>\
		');
		A(document.body,div);	
	}
};

Event.observe(window,'load',_Popup.initTpl);
Event.observe(window,'resize',_Popup.resize);


