function makeProp(wdo,hgo,wd,hg){
	if(wd==undefined){
		wd= document.documentElement.clientWidth;
		hg= document.documentElement.clientHeight;
	}
	var nwd=wdo-wd;
	var nhg=hgo-hg;
	if(nwd<0 && nhg<0){ return {'width':wdo,'height':hgo} } 
	else {
		if (nwd>=nhg){return {'width':wd,'height':(wd/wdo)*hgo}} 
		else {return new Hash({'width':(hg/hgo)*wdo,'height':hg})}
	}
}
function wheelOn(){ FW=new Fx.Tween($("lbW")).start('opacity', 1) }
function wheelOff(){ FW=new Fx.Tween($("lbW")).start('opacity', 0) }
function overlayOn(){ $("lbO").setStyle("display",""); FO=new Fx.Tween($("lbO")).start('opacity', 0.75) }
function overlayOff(){ new Fx.Tween($("lbO")).start('opacity', 0).chain(function(){$("lbO").setStyle("display","none");$("lbM").setStyle("display","none");$("lbM").empty()}) }

function lbClose(){
	var F=new Fx.Tween($("lbM")).start('opacity',0).chain(function(){
		FW=new Fx.Tween($("lbW")).start('opacity', 0)
		overlayOff()
	})
}

function res1(I,M){
	M.setStyle("display","")
	var prop=makeProp(I.width,I.height,window.innerWidth,window.innerHeight-82)
	M.setStyles(prop);
	I.setStyles(prop);
	I.inject($("lbX"),"after")
	M.setStyles({
		'margin-left':-(prop.width)/2,
		'margin-top':(-(prop.height)/2),
		'margin-bottom':"7px",
		"padding-top":"20px",
		"background-color":"#fff",
		"border":"solid 10px #fff"
	});
	wheelOff()
	var F = new Fx.Tween(M).start('opacity', 1)
}


function boxer(){
	overlayOn()
	wheelOn()

	var M=$("lbM")
	var X=new Element('div', {
		"id":"lbX",
		"styles":{
			"position":"absolute",
			"background":"url(../js/img_ajax_close.gif)",
			"right":"0px",
			"top":"-5px",
			"width":"20px",
			"height":"20px",
			"display":"block",
			'cursor':'pointer',
			'color':'#000000'			
		}
	});
	X.addEvent("click", lbClose)
	M.adopt(X)
   	var I = new Element('img', { 'id':'lbI','src': this.href});
	if (I.complete){
		res1(I,M)
	} else {
		I.addEvent("load", function(){
			res1(I,M)
		})
	}
	return false
}


function kickbox(){
	var W=new Element('div', { 
		'id':'lbW', 
		'opacity':0
	});
	var M=new Element('div', { 
		'id':'lbM', 
		'opacity':0, 
		'styles':{
			'z-index':9999,
			'position':'fixed',
			'top':'50%',
			'left':'50%'
		} 
	});
	var O=new Element('div', {
		'opacity':0,
		'id':'lbO'
	});
	$$("body").adopt(O,M,W);
	O.addEvent("click", lbClose)
	if ($$(window.location.hash)!="" && window.location.hash!=""){
		if (window.location.hash!="#topo" && window.location.hash!="#ilustracao" && window.location.hash!="#internet" && window.location.hash!="#logotipo" && window.location.hash!="#print")
		boxer(window.location.hash)
	}
	$$(".lb a").addEvent("click", boxer);
	$$('a.adicionar,a.modificar').removeEvents();
}
