/* (c) Kalamun 2009 - GPL 3 */

/* lightbuzz 0.2 */
kLightbuzz=function() {
	var container=document.body;
	this.setContainer=function(c) {
		container=document.getElementById(c);
		}

	this.init=function() {
		for(var i=0;container.getElementsByTagName('A')[i];i++) {
			var elm=container.getElementsByTagName('A')[i];
			if(elm.rel&&elm.rel=="lightbuzz") elm.onclick=this.onClickHandler;
			}
		}
	this.onClickHandler=function() {
		var w=false,h=false,alt='';
		if(this.getAttribute('alt')) alt=this.getAttribute('alt');
		if(this.getAttribute('fullwidth')) w=parseInt(this.getAttribute('fullwidth'));
		if(this.getAttribute('fullheight')) h=parseInt(this.getAttribute('fullheight'));
		if(w>kWindow.clientWidth()-50) {
			h=w/kWindow.clientWidth-50*h;
			w=kWindow.clientWidth()-50;
			}
		if(h>kWindow.clientHeight()-50) {
			w=h/kWindow.clientHeight-50*w;
			h=kWindow.clientHeight()-50;
			}
		openIPopUp(this.href,w,h,alt);
		return false;
		}
	function openIPopUp(url,w,h,alt) {
		var msg=document.createElement('DIV');
		msg.id='lightBuzzIPopUp';
		msg.style.position='absolute';
		msg.style.top='-3000px';
		msg.style.left='-3000px';
		msg.style.zIndex='100';
		document.body.appendChild(msg);
		var img=document.createElement('IMG');
		msg.onclick=closeIPopUp;
		img.src=url;
		img.style.width=w+'px';
		img.style.height=h+'px';
		img.onload=centerIPopUpOnScreen;
		msg.appendChild(img);
		if(alt) {
			//img.alt=alt;
			var divalt=document.createElement('DIV');
			divalt.className='alt';
			divalt.appendChild(document.createTextNode(alt));
			msg.appendChild(divalt);
			}
		var bkg=document.createElement('DIV');
		bkg.id='lightBuzzIPopUpBkg';
		bkg.style.cssText='height:'+kWindow.pageHeight()+'px;';
		document.body.appendChild(bkg);
		bkg.onclick=closeIPopUp;
		}
	function centerIPopUpOnScreen() {
		msg=document.getElementById('lightBuzzIPopUp');
		bkg=document.getElementById('lightBuzzIPopUpBkg');
		bkg.style.backgroundImage="url('')";
		msg.style.top=((kWindow.clientHeight()-msg.offsetHeight)/2+kWindow.scrollTop())+'px';
		msg.style.left=(kWindow.clientWidth()-msg.offsetWidth)/2+'px';
		}
	function closeIPopUp() {
		if(document.getElementById('lightBuzzIPopUp')) {
			var msg=document.getElementById('lightBuzzIPopUp');
			msg.parentNode.removeChild(msg);
			}
		if(document.getElementById('lightBuzzIPopUpBkg')) {
			var bkg=document.getElementById('lightBuzzIPopUpBkg');
			bkg.parentNode.removeChild(bkg);
			};
		}
	}
function kLightbuzzInit() {
	var kLightbuzzTmp=new kLightbuzz;
	kLightbuzzTmp.init();
	}
kAddEvent(window,"onload",kLightbuzzInit);

