// JavaScript Document
/**
	@plugin AbiModal
	@autor Kleber Oliveira
	@date 2010-02-10
	@version 0.5	
**/

var abimodal = {
    modal:"<div class='modal'>&nbsp;</div>",
    conteudo:"<div class='modal_conteudo'></div>",
    start:function(){
        if(jQuery('.modal').get()==""){
            jQuery('body').prepend(this.modal);
            jQuery('body').prepend(this.conteudo);
            jQuery('.modal').css({"height":jQuery(document).height()+"px","opacity":"0.8"}).click(function() { abimodal.end(); }).fadeIn();

        }
    },
    end:function(){
        if(jQuery('.modal').get()!=""){
            jQuery('.modal,.modal_conteudo').fadeOut(function(){
                jQuery(this).remove();
            });
        }
    },
    add:function(objeto){
        jQuery('.modal_conteudo').prepend(objeto);
        jQuery('.modal_conteudo').fadeIn();
        var Mwidth = jQuery('.modal_conteudo').width();
        var Mheight = jQuery('.modal_conteudo').height();

        jQuery('.modal_conteudo').css({
			top:(jQuery(window).height()/2)+jQuery(document).scrollTop()+"px",
			left:(jQuery(window).width()/2),
			"margin-left":-(Mwidth/2)+"px",
			"margin-top":-(Mheight/2)+"px"
        });
	    jQuery(window)
			.scroll(this.window_action)	
			.bind('resize',this.window_action);
		
    },
	window_action:function(){
		jQuery('.modal').css({"height":jQuery(document).height()+"px"})
		jQuery('.modal_conteudo').animate({
			top:(jQuery(window).height()/2)+jQuery(document).scrollTop()+"px",
			left:(jQuery(window).width()/2)+jQuery(document).scrollLeft()+"px"
			},{duration:500,queue:false}
		);
	}	
}
