function iframe_mouse(e) {
    $(e).prepend("<div style='background:none;height:100%;width:100%;position:absolute' class='iframe_mouseover'/>");
}

/*modo de usar: quando queremos modificar os links de uma div para serem abertos em outra div
$(div com os links).link_to(div que queremos (ou, janela)
*/
jQuery.fn.extend ({
     link_win : function (div, janela){
		links = $(this).find('a');
		for(i=0;i<links.length;i++) {
			$(links[i])
			    .attr('url', $(links[i]).attr('href'))
				.attr('href', '#')
				.click(function(){
					if(div!=undefined) {$(janela).janela($(this).attr('url'), $(this).html()); return }
					$(div).load($(this).attr('url'), function(data){
						$(div).html(data);
					})
				})
	
		}
		return this
	},
	
	
	
	 selection : function(state) {
        if(state) {
            document.onselectstart = new Function ('return true');
            if (window.sidebar) document.onmousedown = new Function('return true');
			return this
        } else {
            document.onselectstart = new Function ('return false');
            if (window.sidebar) document.onmousedown = new Function('return false');
			return this
        }
     },
	 
	 

     trans : function(opacity){
        this.css({
          'opacity': opacity,
          '-khtml-opacity': opacity,
          '-moz-opacity': opacity,
          'filter': 'alpha(opacity='+opacity*100+')'
        })
        return this
     },
	 

     // movimentacao de div
    // uso: $(id do obj que sera movido).movel(obj que ativara a movimentacao);
     movel : function (parametros){
         var default_vars = {
            ponteiro : '', // elemento que desencadeia o movimento
            iframe_mouseover : true,
            cursor: 'move'
        }
        var padrao = $.extend({}, default_vars, parametros);
        var elemento = $(this)
        var mover = false;

        $(padrao.ponteiro).mousedown(function(e) {
            $(this).css({ 'cursor':'default' });
			$(document).selection(false);
			
            mover = true;
            innerX = $(elemento).position().left;
            innerY = $(elemento).position().top;
			zx = e.clientX;
            zy = e.clientY;
            if(padrao.iframe_mouseover) iframe_mouse(elemento);
        })
		
        .mouseup(function() {
            mover = false;
            innerX = innerY = zy = zx = 0;
			$(document).selection(true);
        })
		
        .mouseover(function() {
            if(elemento.attr('max')!='true')
                $(this).css('cursor', padrao.cursor);
             else
                $(this).css('cursor', 'default');
        })
		
        $(document).mousemove(function(e) {
            if(!mover || elemento.attr('max')=='true') return;
            $(elemento).css('position', 'absolute');
            x = innerX-zx+e.clientX;
            y = innerY-zy+e.clientY;
            $(elemento).css({'top':y, 'left':x});
        })
		
        .mouseup(function() {
            mover=false;            
        })
		
        return this;
     },

     //uso: $(div).redimensionavel(obj que ativara o clique) a funcao pode não funcionar direito com classes, por via das duvidas, use id
     redimensionavel : function(parametros){
        var default_vars = {
            ponteiro: "#elemento",
            conteudo: "",
            evento: 'mousedown',
            topo_alt: 22,
            width : true,
            height : true,
            width_min : 0,
            height_min : 0,
            cursor : 'w-resize',
            iframe_mouseover: false
        }
        var padrao = $.extend({}, default_vars, parametros);

        var elemento = $(this);
        var conteudo = padrao.conteudo;
        var resize_janela = false;
        var ini_resize = true;
        var innerX = 0;
        var innerY = 0;
        var tx=0;
        var ty=0;

        $(padrao.ponteiro).css({ 'cursor':padrao.cursor });
        $(padrao.ponteiro).bind(padrao.evento, function() {
            resize_janela = true;
			$(this).css({ 'cursor':'default' });
			$(document).selection(false);
			
            tx = elemento.width();
            ty = elemento.height();
            if(padrao.iframe_mouseover)iframe_mouse(elemento);
			
        }).bind('mouseup', function() {
            resize_janela = false;
            $(this).css({ 'cursor':padrao.cursor });
			$(document).selection(true);
        })

        $(document).mousemove(function(e) {
            if(!resize_janela) { ini_resize = true; return; }
            if(ini_resize){ zx = e.clientX; zy = e.clientY; }
            $(padrao.ponteiro).css({ 'cursor':'default' });

            x = e.clientX;
            y = e.clientY;
            w = (x-zx+tx<padrao.width_min)?padrao.width_min:x-zx+tx;
            h = (y-zy+ty<padrao.height_min)?padrao.height_min:y-zy+ty;

            if(padrao.width)elemento.width(w)
            if(padrao.height)elemento.height(h)

            $(conteudo).height(h-padrao.topo_alt)
            ini_resize = false;
			
        }).bind('mouseup', function() {
            resize_janela = false;
            $(padrao.ponteiro).css({ 'cursor':padrao.cursor });
        })
        return this;
     },
	 
     t_minimo : function(parametros){
        e = $(this);
        
        var default_vars = {
            altura:'auto'
        }
        var padrao = $.extend({}, default_vars, parametros);
        if($('body').width()<=padrao.largura)e.width(padrao.largura);
        if($('body').height()<=padrao.altura)e.height(padrao.altura);

        if(navigator.appName=="Microsoft Internet Explorer") {
            $(window).resize(function() {
                lar=($('body').width()<=padrao.largura)?padrao.largura:'100%';
                alt=($('body').height()<=padrao.altura)?padrao.altura:'100%';

                e.width(lar)
                e.height(alt)
            })
        } else {
            e.css({
              'min-width':padrao.largura,
              'min-height':padrao.altura
            })
        }
        return this;
     },
	 
	 jAtivar : function() {
		 $(this)
			.css('z-index', '999999999999')
			.trans(1) 
		return this
	 }, 
	 
	 jDesativar : function() {
		 $(this)
			.css('z-index', '5555')
			.trans(0.5) 
		return this
	 }
});
