var sendBox;

function sendBox_onLoad()
{

	sendBox = $("div#sendbox");
	sendBox.background = $("#lightbox_background");
	
    sendBox.realign = function()
    {
        var left = ($(window).width() - sendBox.width()) / 2;
        var top = ($(window).height() - sendBox.height()) / 2;
        sendBox.css({left:left, top:top});
		
		sendBox.background.realign();
    }
	
	sendBox.background.realign = function()
	{
		/*var left = ($(window).width() - sendBox.width()) / 2;
        var top = ($(window).height() - sendBox.height()) / 2;*/
		var width = $(document).width();
		var height = $(document).height();
		
        sendBox.background.css({left:0, top:0, width:width, height:height});
	}
	
	sendBox.background.show = function()
	{
		sendBox.background.fadeIn("normal");
		
		sendBox.background.realign();
	}
	
	sendBox.background.hide = function()
	{
		sendBox.background.fadeOut("normal");
	}
	
    sendBox.show = function(title)
    {
       sendBox.find("div.header div.title").html(title);
       sendBox.find("div.content div.msg").html("");
       sendBox.realign();
       sendBox.fadeIn("normal");
	   
	   //background	   
	   //sendBox.background.fadeTo("fast", 0.5);
	   sendBox.background.show();
    }
	
    sendBox.hide = function()
    {
       sendBox.fadeOut("normal");
	   sendBox.background.hide();
    }
    
    sendBox.hideButton = function()
    {
        sendBox.find("img.button").fadeOut("fast");
    }
	
    sendBox.showButton = function()
    {
        sendBox.find("img.button").fadeIn("fast");
    }
	
	sendBox.showPreloader = function()
	{
		sendBox.find(".preloader").fadeIn("fast");
	}
	
	sendBox.hidePreloader = function()
	{
		sendBox.find(".preloader").fadeOut("fast");
	}
	
	sendBox.sendAndReceive = function(url, data, method)
	{
		sendBox.show("Enviando");
		$.ajax({
		type: method,
		url: url,
		data: data,
		beforeSubmit: function() {sendBox.showPreloader()},
		success: function(msg)
			{
				sendBox.hidePreloader();
				sendBox.find("div.content div.msg").html(msg);
			}
		});
	}
    
    sendBox.find("img.button").click(function() {sendBox.hide();});
}

$(document).ready(sendBox_onLoad);
$(window).resize(function() {sendBox.realign();});


