/*
 *   Leobox Plugin 1.0 - Easy and simple div box absoluted centered on the screen
 *   author: Leonardo Majowka
 *   date: 2010-07-18
 *
 *   using: jquery and center plugin1.0
 *
 *
 * Center Plugin 1.0 - Easy cross-browser centering a div!
 * Version 1.0.1
 * @requires jQuery v1.3.0
 * 
 * Copyright (c) 2010 Matthias Isler
 * Licensed under the GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 * 
 *
 * EXAMPLE:
 
<SCRIPT LANGUAGE="JavaScript" SRC="jquery.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="leobox.js"></SCRIPT>

<input type="button" value="open" onclick='$("#divtest").openBox();'>

<div id="divtest" class="dialog"><input type="button" value="close" style="" onClick='$("#divtest").closeBox();'></div>

<style>
.dialog
{
	width:300Px;
	position:absolute;
	background:#FFF;
	border:2Px solid red;
	z-index:2;
	display:none;
	top:0;
	left:0;
	height:100Px;
	padding:20Px;
}
</style>
 */


jQuery.fn.openBox = function(init)
{
	
	var cinza = document.getElementById("cinzaBox");
	
	if (cinza == null)
	{
		var divstr = '<div id="cinzaBox" style="position:absolute;top:0Px;left:0Px;width:2000Px;height:2000Px;background:#1E1E1E;/* for IE */  filter:alpha(opacity=60);  /* CSS3 standard */  opacity:0.6;"></div>';
		$('body').append(divstr);
	}
	else
	{
		$('#cinzaBox').show();
	}
	
	document.body.style.overflow='hidden';
	this.show();
	this.center();
	
}


jQuery.fn.closeBox = function(init)
{
	var cinza = document.getElementById("cinzaBox");
	if (cinza != null)
	{
		$('#cinzaBox').hide();
	}
	
	document.body.style.overflow='visible';
	this.hide();
}




jQuery.fn.center = function(init) {
		
	var object = this;
		
	if(!init) {
			
		object.css('margin-top', 0);
		object.css('margin-left', 0);
			
		$(window).resize(function() {
			object.center(!init);
		});
		
	} else {
			
		var marginTop = 0;
		var marginLeft = 0;
			
		marginTop = (marginTop < 0) ? 0 : marginTop;
		marginLeft = (marginLeft < 0) ? 0 : marginLeft;

		object.stop();
		object.animate(
			{
				marginTop: marginTop, 
				marginLeft: marginLeft
			}, 
			150, 
			'linear'
		);
		
	}
}






