var abimodal = {
    modal:"<div class='modal'>&nbsp;</div>",
    conteudo:"<div class='modal_conteudo'></div>",
	fechar:"<div class='close'>X</div>",
	boxHeight:"",
	classe:"",
	link:"",
    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.1"});
			
			if(this.classe.length != -1)
			  jQuery('.modal').addClass(this.classe);
			if(true){
	            jQuery('body').prepend(this.fechar);
				jQuery('.modal').click(function() { abimodal.end(); });
				jQuery('.close').css({"background":"#FFF","color":"#000","border":"#AAA","float":"right","left":"100%","margin-left":"-32px","margin-top":"5px","padding":"5px 8px","position":"absolute","text-align":"center","z-index":"2147483649","cursor":"pointer"})
				.click(function(){ abimodal.end(); });				
			}
			
			jQuery('.modal').fadeIn()
			

        }
    },
    end:function(){
        if(jQuery('.modal').get()!=""){
            jQuery('.modal,.modal_conteudo, .close').fadeOut(function(){
                jQuery(this).remove();
            });
        }
    },
	addIMG:function(caminho){
		img = new Image(); 
		img.src = caminho;
		img.onload = function(){
			abimodal.add(this);
		}
		
    },	
    add:function(objeto){
		
		if(this.link.length != -1)
	        jQuery('.modal_conteudo')
			.css({"cursor":"pointer"})
			.click(function(){ abimodal.end();})
			.prepend(objeto);
		else
	        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_conteudo').animate({
			top:(jQuery(window).height()/2)+jQuery(document).scrollTop()+"px",
			left:(jQuery(window).width()/2)+jQuery(document).scrollLeft()+"px"
			},{duration:500,queue:false}
		);
	}	
}
