// 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>",
	fechar:"<div class='close'>X</div>",
	boxHeight:"",
    start:function(opacity,closeClick,boxHeight){
        if(jQuery('.modal').get()==""){
            jQuery('body').prepend(this.modal);
			jQuery('body').prepend(this.conteudo); 
			jQuery('.modal').css({"height":jQuery(document).height()+"px","opacity":opacity})
			if(true){
	            jQuery('body').prepend(this.fechar);
				jQuery('.modal').click(function() { abimodal.end(); });
				jQuery('.close').css({"background":"#000","color":"#FFF","border":"#AAA","float":"right","left":"100%","margin-left":"-26px","margin-top":"5px","padding":"5px 8px","position":"absolute","text-align":"center","z-index":"9999","cursor":"pointer"})
				.click(function(){ abimodal.end(); });				
			}
			this.boxHeight = boxHeight!=undefined?boxHeight:false;
			jQuery('.modal').fadeIn()
			

        }
    },
    end:function(){
        if(jQuery('.modal').get()!=""){
            jQuery('.modal,.modal_conteudo, .close').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();
        
	
		if(1==2 ){
		jQuery('.modal_conteudo').css({
			left:(jQuery(window).width()/2),
			"margin-left":-(Mwidth/2)+"px",
			height:$(window).height()
        });
		}else{
        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_conteudo').animate({
			top:(jQuery(window).height()/2)+jQuery(document).scrollTop()+"px",
			left:(jQuery(window).width()/2)+jQuery(document).scrollLeft()+"px"
			},{duration:500,queue:false}
		);
	}	
}
