// 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>",
    start:function(opacity,closeClick){
        if(jQuery('.modal').get()==""){
            jQuery('body').prepend(this.modal);
			jQuery('body').prepend(this.conteudo); 
			jQuery('.modal').css({
				"opacity":opacity,
				"width":$('body').width(),
				"height":$('body').height()				
			})
			if(closeClick){
	            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":"-30px","margin-top":"5px","padding":"5px 8px","position":"absolute","text-align":"center","z-index":"99999999999999999999999","cursor":"pointer"})
				.stop().animate({
					top:jQuery(document).scrollTop()+"px",			
				})				
				.click(function(){ abimodal.end(); });				
			}
			jQuery('.modal').fadeIn()
			

        }
    },
    end:function(){
		jQuery("#galeria").remove();
        if(jQuery('.modal').get()!=""){
            jQuery('.modal,.modal_conteudo, .close').fadeOut(function(){
                jQuery(this).remove();
            });
        }
    },
    add:function(objeto){
        jQuery('.modal_conteudo').empty().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').stop().animate({
			top:(jQuery(window).height()/2)+jQuery(document).scrollTop()+"px",
			left:(jQuery(window).width()/2)+jQuery(document).scrollLeft()+"px"
			},{duration:500,queue:false}
		);
		jQuery('.close').animate({
			top:jQuery(document).scrollTop()+"px",			
		});
	},
	addimg:function(imagem){
		var img = new Image();
		img.src = imagem;
		img.onload = function(){
		   abimodal.add("<img src='"+imagem+"' />");
		}
		  
	}
}

