﻿/**
* @name				Linha Framework
* @version			1.2
* 
* @author			Mateus Souza
* @author-email		mateussouzaweb@gmail.com
* @author-website	http://www.mateussouza.com | http://www.linhaframework.com
* @copyright		(c) 2010 Mateus Souza
* @license			MIT and GPL License - http://www.opensource.org/licenses/mit-license.php || http://www.gnu.org/licenses/gpl.html
* 
*/
(function ($) {
    //Linha Acord 1.1
    $.fn.acord = function (options) { return new $.acord(options, this); }; $.acord = function (options, elem) {
        var padrao = { seletor: '.accordion', pai: 'h2', filho: 'div', classePaiAtual: 'accordion-pai-atual', classeFilhoAtual: 'accordion-filho-atual', classeAjax: 'ajax', atributoUrl: 'url', evento: 'click', inicial: 1, sempreUm: true, autoHeight: false, tempoIn: 'normal', tempoOut: 'normal', easingIn: 'swing', easingOut: 'swing', onAcord: null, live: false, liveTempo: 100 }; var o = $.extend(padrao, options), $d = $(document), ap = o.classePaiAtual, af = o.classeFilhoAtual; if (elem === undefined) { elem = $(o.seletor); }
        elem.elements = []; $d.delegate(elem.selector, 'iniciaAcord', function () {
            var elems = elem.elements, els = $(elem.selector, elem.context), nEls = els.not(elems); elem.elements = els; nEls.each(function () {
                var $t = $(this); $(o.filho, this).each(function () { $(this).css('height', $(this).height() + 'px').hide(); }); if (o.sempreUm) { $(o.filho, this).eq(o.inicial - 1).addClass(af).show().prev(o.pai).addClass(ap); }
                if (o.autoHeight) { var h = 0; $(o.filho, this).each(function () { h = Math.max(h, $(this).outerHeight()); }).height(h); $t.height($t.height()).css({ overflow: 'hidden' }); }
                $(o.pai, this).bind(o.evento, function () {
                    if ($(this).hasClass(o.classeAjax)) { return ajaxAcord($t, $(this), $(this).next()); }
                    return animaAcord($t, $(this), $(this).next());
                }); if (o.sempreUm && $('.' + ap, this).hasClass(o.classeAjax)) { $('.' + ap, this).trigger(o.evento); }
            });
        }); if (o.live) { setInterval(function () { $(elem.selector).trigger('iniciaAcord'); }, o.liveTempo); } else { if (elem.length) { elem.trigger('iniciaAcord'); } }
        function ajaxAcord($acord, $pai, $filho) { $.ajax({ type: "POST", url: $pai.attr(o.atributoUrl), success: function (data) { $filho.html(data); } }); $filho.height('auto'); $acord.height('auto'); return animaAcord($acord, $pai, $filho); }
        function animaAcord($acord, $pai, $filho) {
            $(o.filho, $acord).removeClass(af); $(o.pai, $acord).removeClass(ap); $pai.addClass(ap); $filho.addClass(af); if ($.isFunction(o.onAcord)) { o.onAcord.apply($acord, new Array($acord, $pai, $filho, o)); }
            $(o.filho, $acord).not($filho).slideUp(o.tempoIn, o.easingIn); if (o.sempreUm) { $filho.slideDown(o.tempoOut, o.easingOut); } else { $filho.slideToggle(o.tempoIn, o.easingIn); }
            return false;
        };
    };

    //Linha Focuss 1.1
    $.fn.focuss = function (options) { return new $.focuss(options, this); }; $.focuss = function (options, elem) {
        var padrao = { seletor: 'input, textarea', evento: 'focus', eventoFim: 'blur', tempoIn: 'normal', tempoOut: 'normal', classe: 'focus', removeTexto: false, onInicia: null, onTermina: null, live: false, liveTempo: 100 }; var o = $.extend(padrao, options), $d = $(document); if (elem === undefined) { elem = $(o.seletor); }
        elem.elements = []; $d.delegate(elem.selector, 'iniciaFocuss', function () { var elems = elem.elements, els = $(elem.selector, elem.context), nEls = els.not(elems).not(':submit'); elem.elements = els; nEls.each(function () { var $t = $(this), texto = $(this).val(); $t.bind(o.evento, function () { return animaFocuss($t, texto); }); $t.bind(o.eventoFim, function () { return terminaFocuss($t, texto); }); }); }); if (o.live) { setInterval(function () { $(elem.selector).trigger('iniciaFocuss'); }, o.liveTempo); } else { if (elem.length) { elem.trigger('iniciaFocuss'); } }
        function animaFocuss($t, texto) {
            if (o.removeTexto) { if ($t.val() == texto) { $t.val(''); } }
            $t.addClass(o.classe); if ($.isFunction(o.onInicia)) { o.onInicia.apply($t, new Array($t, texto, o)); }
        }
        function terminaFocuss($t, texto) {
            if (o.removeTexto) { if ($t.val() == '') { $t.val(texto); } }
            $t.removeClass(o.classe); if ($.isFunction(o.onTermina)) { o.onTermina.apply($t, new Array($t, texto, o)); }
        }
    };

    //Linha Modal 1.1 MODIFICADO $.ajax por Load
    $.fn.modal = function (options) { return new $.modal(options, this); }; $.modal = function (options, elem) {
        var padrao = { seletor: '.modal', seletorImagem: 'imagem', seletorAjax: 'ajax', seletorIframe: 'iframe', seletorVideo: 'video', seletorCancela: 'fecha', seletorConfirma: 'confirma', classeModal: 'modal-area', classeTitulo: 'modal-titulo', classeConteudo: 'modal-conteudo', classeFecha: 'modal-fecha', classeLoad: 'modal-load', classeFundo: 'modal-fundo', fundoOpacidade: 0.7, zIndex: 1000, evento: 'click', eventoFecha: 'click', eventoFundo: 'click', eventoConfirma: 'click', eventoCancela: 'click', tempo: 'fast', tempoFundo: 'fast', tempoLoad: 'fast', fundo: true, fecha: true, titulo: null, conteudo: null, conteudoAntes: false, autoPosiciona: false, atributoLink: 'href', atributoTitulo: 'titulo', atributoConteudo: 'conteudo', atributoAltura: 'altura', atributoLargura: 'largura', atributoIframeLargura: 'iframelargura', atributoIframeAltura: 'iframealtura', atributoVideoLargura: 'videolargura', atributoVideoAltura: 'videoaltura', onCria: null, onExibe: null, onFecha: null, onConfirma: null, onCancela: null }; var o = $.extend(padrao, options), $d = $(document), $w = $(window), m = [], el = [], w = [], $t = ''; if (elem === undefined) { elem = $(o.seletor); }
        $d.delegate(elem.selector, o.evento, function () {
            if ($('.' + o.classeModal).length) { return false; }
            $t = $(this); el.titulo = $t.attr(o.atributoTitulo); el.conteudo = $t.attr(o.atributoConteudo); el.altura = $t.attr(o.atributoAltura); el.largura = $t.attr(o.atributoLargura); el.link = $t.attr(o.atributoLink); el.iframeLargura = $t.attr(o.atributoIframeLargura); el.iframeAltura = $t.attr(o.atributoIframeAltura); el.videoLargura = $t.attr(o.atributoVideoLargura); el.videoAltura = $t.attr(o.atributoVideoAltura); criaModal(); dataModal(); return false;
        }); function criaModal() {
            if (o.fundo) { m.fundo = $('<div></div>').addClass(o.classeFundo).css({ width: '100%', height: '100%', opacity: o.fundoOpacidade, position: 'fixed', top: 0, left: 0, zIndex: o.zIndex - 1, backgroundColor: '#000', display: 'none' }).appendTo('body').fadeIn(o.tempoFundo); }
            m.load = $('<div></div>').addClass(o.classeLoad).css({ position: 'fixed', top: '50%', left: '50%', zIndex: o.zIndex }); m.modal = $('<div></div>').addClass(o.classeModal).css({ width: el.largura, height: el.altura, position: 'absolute', zIndex: o.zIndex, display: 'none' }); if (o.autoPosiciona) { m.modal.css({ position: 'fixed', top: "50%", left: "50%" }); }
            m.fecha = $('<span>x</span>').addClass(o.classeFecha); if (o.classeTitulo != null && o.classeTitulo) { m.titulo = $('<div></div>').addClass(o.classeTitulo); }
            m.conteudo = $('<div></div>').addClass(o.classeConteudo); m.load.css({ marginTop: -(m.load.outerHeight() / 2), marginLeft: -(m.load.outerWidth() / 2) }); if ($.isFunction(o.onCria)) { o.onCria.apply(m.modal, new Array(m, el, $t, o)); }
        }
        function dataModal() {
            if (m.titulo) m.titulo.html(o.titulo).append(el.titulo); if ($t.hasClass(o.seletorVideo)) { el.link = el.link.replace(new RegExp("watch\\?v=", "i"), 'v/'); var data = '<object width="' + el.videoLargura + '" height="' + el.videoAltura + '" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" style="display: block">'; data += '<param name="movie" value="' + el.link + '"></param>'; data += '<embed type="application/x-shockwave-flash" src="' + el.link + '" width="' + el.videoLargura + '" height="' + el.videoAltura + '"></embed>'; data += '</object>'; m.conteudo.append(data); }
            else if ($t.hasClass(o.seletorIframe)) { var data = '<iframe src="' + el.link + '" height="' + el.iframeAltura + '" width="' + el.iframeLargura + '" style="border:0; display: block" frameBorder="0"></iframe>'; m.conteudo.append(data); }
            else if ($t.hasClass(o.seletorAjax)) {
                m.load.appendTo('body');
                m.conteudo.load(el.link, function (rt, ts, xhr) {
                    if (!xhr) {  //Use o ! porque Ã© feito o load 2 vezes e na segunda nÃ£o retorna o status
                        m.load.fadeOut(o.tempoFundo, function () { $(this).remove(); });
                        return mostraModal();
                    }
                });
            }
            else if ($t.hasClass(o.seletorImagem)) { m.load.appendTo('body'); var img = new Image(); $(img).load(function () { $(this).css({ display: 'none', height: this.height, width: this.width }); m.load.fadeOut(o.tempoFundo, function () { $(this).remove(); }); m.conteudo.append(img); $(this).fadeIn(); return redimensionaModal(this.width, this.height); }).attr('src', el.link); return; }
            else { m.conteudo.append(el.conteudo); }
            return mostraModal();
        }
        function redimensionaModal(w, h) { m.conteudo.css({ height: h, width: w }); mostraModal(); }
        function mostraModal() {
            if (!o.conteudoAntes) { m.conteudo.append(o.conteudo); } else { m.conteudo.prepend(o.conteudo); }
            if (m.titulo && m.titulo.html() !== undefined) { m.modal.append(m.titulo); }
            m.modal.append(m.conteudo).append(m.fecha).appendTo('body').hide(); if (o.autoPosiciona) { m.modal.css({ marginTop: -(m.modal.outerHeight() / 2), marginLeft: -(m.modal.outerWidth() / 2) }); } else { w.w = $w.width(); w.h = $w.height(); w.sl = $w.scrollLeft(); w.st = $w.scrollTop(); var mTop = w.h / 2 + (w.st) - (m.modal.outerHeight() / 2); var mLeft = (w.w / 2) + w.sl - (m.modal.outerWidth() / 2); m.modal.css({ top: mTop, left: mLeft }); } m.modal.fadeIn(o.tempo); if (o.fecha && m.fundo) { m.fundo[o.eventoFundo](function () { return deletaModal(); }); }
            m.fecha[o.eventoFecha](function () { return deletaModal(); }); $('.' + o.seletorCancela)[o.eventoCancela](function () {
                if ($.isFunction(o.onCancela)) { o.onCancela.apply(this, new Array(m, el, $t, o)); }
                return deletaModal();
            }); $('.' + o.seletorConfirma)[o.eventoConfirma](function () {
                if ($.isFunction(o.onConfirma)) { o.onConfirma.apply(this, new Array(m, el, $t, o)); }
                return deletaModal();
            }); if ($.isFunction(o.onExibe)) { o.onExibe.apply(m.modal, new Array(m, el, $t, o)); }
        }
        function deletaModal() {
            if (m.fundo) { m.fundo.fadeOut(o.tempo, function () { $(this).remove(); }); }
            if (m.load.length) { m.load.remove(); }
            m.modal.remove(); if ($.isFunction(o.onFecha)) { o.onFecha.apply(m.modal, new Array(m, el, $t, o)); }
            return false;
        }
    };

    //Linha Nav 1.1
    $.fn.nav = function (options) { return new $.nav(options, this); }; $.nav = function (options, elem) {
        var padrao = { seletor: '.menu li', seletorFilho: 'ul:first', classePaiAtual: 'nav-pai-atual', classeFilhoAtual: 'nav-filho-atual', evento: 'mouseenter', eventoFim: 'mouseleave', efeitoIn: 'slideDown', efeitoOut: 'slideUp', tempoIn: 'normal', tempoOut: 'normal', easingIn: 'swing', easingOut: 'swing', stopClearQueue: true, stopJumpToEnd: true, onExibe: null, onEsconde: null }; var o = $.extend(padrao, options), $d = $(document), np = o.classePaiAtual, nf = o.classeFilhoAtual; if (elem === undefined) { elem = $(o.seletor); }
        $d.delegate(elem.selector, o.evento, function (e) {
            var $f = $(this).children(o.seletorFilho); if (!$f.length) { return false; }
            exibeNav($(this), $f); $(this).unbind(o.eventoFim).bind(o.eventoFim, function () { return escondeNav($(this), $f); });
        }); function exibeNav($t, $f) {
            $t.addClass(np); if ($.isFunction(o.onExibe)) { o.onExibe.apply($t, new Array($t, $f, o)); }
            $f.stop(o.stopClearQueue, o.stopJumpToEnd).addClass(nf)[o.efeitoIn](o.tempoIn, o.easingIn);
        }; function escondeNav($t, $f) { $t.removeClass(np); $f.stop(o.stopClearQueue, o.stopJumpToEnd).removeClass(nf)[o.efeitoOut](o.tempoOut, o.easingOut); if ($.isFunction(o.onEsconde)) { o.onEsconde.apply($t, new Array($t, $f, o)); } };
    };

    //Linha Slidetabs 1.1
    $.fn.slideTabs = function (options) { return new $.slideTabs(options, this); }; $.slideTabs = function (options, elem) {
        var padrao = { seletor: '.slide', seletorAreaPainel: '.slide-conteudo', seletorPainel: '.painel', seletorMiniatura: '.miniatura', seletorAnterior: '.anterior', seletorProximo: '.proximo', classeMiniaturaAtual: 'slide-miniatura-atual', classePainelAtual: 'slide-painel-atual', classePainelPrimeiro: 'slide-painel-primeiro', classePainelUltimo: 'slide-painel-ultimo', classePainelConteudo: 'slide-painel-conteudo', eventoMiniatura: 'click', eventoSeta: 'click', inicial: 1, continuo: true, auto: false, pausa: 2000, tempo: 'normal', easing: 'swing', alturaAutomatica: false, margin: true, scroll: 1, visiveis: 1, direcao: 'x', onSlide: null, live: false, liveTempo: 100 }; var o = $.extend(padrao, options), $d = $(document); if (elem === undefined) { elem = $(o.seletor); }
        elem.elements = []; $d.delegate(elem.selector, 'iniciaSlideTabs', function () {
            var elems = elem.elements, els = $(elem.selector, elem.context), nEls = els.not(elems); elem.elements = els; nEls.each(function () {
                var $t = $(this), $sp = $(o.seletorPainel, $t), $sm = $(o.seletorMiniatura, $t), sma = o.classeMiniaturaAtual, spa = o.classePainelAtual, spp = o.classePainelPrimeiro, spu = o.classePainelUltimo, spcw = 0, ini = o.inicial - 1, timeout, dir = o.direcao == 'x', pos = {}; $t.children(o.seletorAreaPainel).wrapInner('<div class="' + o.classePainelConteudo + '"></div>'); var $spc = $('.' + o.classePainelConteudo, $t); $sp.each(function (i) { pos[i] = spcw; spcw += $(this)[dir ? 'outerWidth' : 'outerHeight'](o.margin); }); $spc.css(dir ? 'width' : 'height', spcw).css('overflow', 'hidden'); $spc.css(dir ? 'marginLeft' : 'marginTop', -pos[ini]); if (o.alturaAutomatica && dir) { $spc.css('height', ($sp.eq(ini).outerHeight(o.margin))); }
                $sp.eq(ini).addClass(spa); $sm.eq(ini).addClass(sma); if (ini == 0) { $sp.eq(0).addClass(spp); }
                if (ini == $sp.length - 1) { $sp.eq(-1).addClass(spu); }
                $sm.bind(o.eventoMiniatura, function () {
                    var l = $(this).prevAll(o.seletorMiniatura).length; $sm.removeClass(sma); $sp.removeClass(spa).removeClass(spp).removeClass(spu); $(this).addClass(sma); $sp.eq(l).addClass(spa); if (l == 0) { $sp.eq(0).addClass(spp); }
                    if (l == $sp.length - 1) { $sp.eq(-1).addClass(spu); }
                    return animaSlide($(this), l);
                }); $(o.seletorAnterior, $t).bind(o.eventoSeta, function () {
                    var l = $('.' + spa, $t).prevAll().length - o.scroll; $sp.removeClass(spu); if (l <= 0) {
                        if ($sp.eq(0).hasClass(spp)) {
                            $sp.removeClass(spp); if (o.continuo) { l = $sp.length - o.visiveis; $sp.eq(-1).addClass(spu); }
                            else { return false; }
                        } else { l = 0; $sp.eq(0).addClass(spp); }
                    }
                    $sp.removeClass(spa).eq(l).addClass(spa); $sm.removeClass(sma).eq(l).addClass(sma); return animaSlide($(this), l);
                }); $(o.seletorProximo, $t).bind(o.eventoSeta, function () { return proximoSlide($(this)); }); function proximoSlide($this) {
                    var l = $('.' + spa, $t).prevAll().length + o.scroll; $sp.removeClass(spp); if (($sp.length - l) <= o.visiveis) {
                        if ($sp.eq(-1).hasClass(spu)) {
                            $sp.removeClass(spu); if (o.continuo) { l = 0; $sp.eq(0).addClass(spp); }
                            else { return false; }
                        }
                        else { l = $sp.length - o.visiveis; $sp.eq(-1).addClass(spu); }
                    }
                    $sp.removeClass(spa).eq(l).addClass(spa); $sm.removeClass(sma).eq(l).addClass(sma); return animaSlide($this, l);
                }
                function animaSlide($this, l) {
                    if ($.isFunction(o.onSlide)) { o.onSlide.apply($t, new Array($t, $this, pos, l, o)); }
                    var h = $spc.height(); if (o.alturaAutomatica && dir) { h = $sp.eq(l).outerHeight(); }
                    var ani = {}; ani[dir ? 'marginLeft' : 'marginTop'] = -pos[l] + 'px'; ani['height'] = h; $spc.animate(ani, o.tempo, o.easing); clearInterval(timeout); if (o.auto) { timeout = setInterval(function () { return proximoSlide(null); }, o.pausa); }
                    return false;
                }
                if (o.auto) { timeout = setInterval(function () { return proximoSlide(null); }, o.pausa); };
            });
        }); if (o.live) { setInterval(function () { $(elem.selector).trigger('iniciaSlideTabs'); }, o.liveTempo); } else { if (elem.length) { elem.trigger('iniciaSlideTabs'); } }
    };

    //Linha Tooltip 1.2
    $.fn.tooltip = function (options) { return new $.tooltip(options, this); }; $.tooltip = function (options, elem) {
        var padrao = { seletor: '.tooltip', seletorImagem: 'imagem', seletorAjax: 'ajax', classeArea: 'tooltip-area', classeConteudo: 'tooltip-conteudo', classeLoad: 'tooltip-load', classeSeta: 'tooltip-seta', classePrefixoPosicao: 'tooltip-posicao', paddingTop: 0, paddingLeft: 0, posicao: 'top2', fixado: true, autoFix: true, tempo: 'fast', evento: 'mouseover', eventoFim: 'mouseout', atributo: 'rel', atributoAltura: 'altura', atributoLargura: 'largura', wrapperTooltip: null, mensagemErro: 'Erro no tooltip', onInicia: null, onPosiciona: null, onTermina: null }; var o = $.extend(padrao, options), tip = {}, atual, $d = $(document), $w = $(window); if (elem === undefined) { elem = $(o.seletor); }
        $d.delegate(elem.selector, o.evento, function (e) { return criaTooltip($(this), e); }); $d.delegate(elem.selector, o.eventoFim, function () { return removeTooltip($(this)); }); if (!o.fixado) { $d.delegate(elem.selector, 'mousemove', function (e) { return posicionaTooltip($(this), e); }); }
        $w.resize(function (e) { if (atual) { return posicionaTooltip(atual, e); } }).scroll(function (e) { if (atual) { return posicionaTooltip(atual, e); } }); function criaTooltip($t, e) {
            if ($.isFunction(o.onInicia)) { o.onInicia.apply($t, new Array($t, e, o)); }
            atual = $t; tip.conteudo = $t.attr(o.atributo), tip.largura = $t.attr(o.atributoLargura), tip.altura = $t.attr(o.atributoAltura); if (tip.conteudo === undefined) { return; }
            if (o.atributo == 'title') { $t.attr('title', ''); }
            tip.area = $('<div></div>').addClass(o.classeArea).css({ display: 'none', position: 'absolute', width: tip.largura, height: tip.altura }); tip.tip = $('<div></div>').addClass(o.classeConteudo).appendTo(tip.area); tip.load = $('<div></div>').addClass(o.classeLoad).css({ display: 'none', position: 'fixed', left: 0 }); if ($t.hasClass(o.seletorImagem)) { tip.load.appendTo('body').fadeIn(o.tempo); tip.load.css({ top: $w.height() - tip.load.outerHeight() }); var img = new Image(); $(img).load(function () { $(this).css({ display: 'none', height: this.height, width: this.width }); tip.tip.html(this).wrapInner(o.wrapperTooltip); tip.area.appendTo('body').fadeIn(o.tempo); tip.load.remove(); $(this).fadeIn(o.tempo); return posicionaTooltip($t, e); }).attr('src', tip.conteudo); return; }
            else if ($t.hasClass(o.seletorAjax)) { tip.load.appendTo('body').fadeIn(o.tempo); tip.load.css({ top: $w.height() - tip.load.outerHeight() }); $.ajax({ type: "POST", url: tip.conteudo, success: function (data) { tip.tip.html(data).wrapInner(o.wrapperTooltip); tip.area.appendTo('body').fadeIn(o.tempo); tip.load.fadeOut('fast', function () { $(this).remove(); }); return posicionaTooltip($t, e); }, error: function () { tip.tip.html(o.mensagemErro).wrapInner(o.wrapperTooltip); tip.area.appendTo('body').fadeIn(o.tempo); tip.load.fadeOut('fast', function () { $(this).remove(); }); return posicionaTooltip($t, e); } }); return; }
            else { tip.tip.html(tip.conteudo).wrapInner(o.wrapperTooltip); tip.area.appendTo('body').fadeIn(o.tempo); return posicionaTooltip($t, e); }
        }
        function removeTooltip($t) {
            if ($.isFunction(o.onTermina)) { o.onTermina.apply($t, new Array($t, o)); }
            if (o.atributo == 'title') { $t.attr('title', tip.conteudo); }
            atual = null; if (tip.area.length) tip.area.remove(); $('.' + o.classeArea).remove(); tip.load.remove();
        }
        function posicionaTooltip($t, e) {
            var ww = $w.width(), wh = $w.height(), wsl = $w.scrollLeft(), wst = $w.scrollTop(), w = $t.outerWidth(), h = $t.outerHeight(), tpos = $t.offset(), left = tpos.left + o.paddingLeft, topo = tpos.top + o.paddingTop, tipw = tip.area.outerWidth(), tiph = tip.area.outerHeight(), pos = o.posicao, y = topo, x = left, a = o.autoFix, c = o.classePrefixoPosicao; if (o.fixado) {
                switch (pos) {
                    case 'esquerda': case 'direita': if (a && (wst + wh) <= (topo + tiph / 2 + 15)) { y += -tiph - 10; c += '-rodape'; } else if (a && (topo - wst) < (tiph / 2 + 15)) { y += h + 10; c += '-topo'; } else { y += -(tiph / 2) + (h / 2); c += '-centro'; }
                        break; case 'top1': case 'top2': case 'top3': case 'top4': case 'top5': if (a && (topo - wst) < (tiph + 15)) { y += h + 10; c += '-topo'; } else { y += -tiph - 10; c += '-rodape'; }
                        break; case 'rod1': case 'rod2': case 'rod3': case 'rod4': case 'rod5': if (a && (wst + wh) <= (topo + tiph + 15)) { y += -tiph - 10; c += '-rodape'; } else { y += h + 10; c += '-topo'; }
                        break;
                }
                switch (pos) {
                    case 'esquerda': if (a && left <= (tipw + 35)) { x += w + 10; c += '-direita'; } else { x += -tipw - 10; c += '-esquerda'; }
                        break; case 'direita': if (a && ww <= (left + tipw + 35)) { x += -tipw - 10; c += '-esquerda'; } else { x += w + 10; c += '-direita'; }
                        break; case 'top1': case 'rod1': if (a && left <= (tipw + 30)) { c += '-lateral-esquerda'; } else { x += -tipw; c += '-esquerda'; }
                        break; case 'top2': case 'rod2': if (a && left <= (tipw / 2 + 30)) { c += '-lateral-esquerda'; } else if (a && ww <= (left + tipw / 2 + 30)) { x += -tipw + w; c += '-lateral-direita'; } else { x += (w / 2) - (tipw / 2); c += '-centro'; }
                        break; case 'top3': case 'rod3': if (a && ww <= (left + tipw + 30)) { x += -tipw + w; c += '-lateral-direita'; } else { x += w; c += '-direita'; }
                        break; case 'top4': case 'rod4': if (a && ww <= (left + tipw + 30)) { x += -tipw + w; c += '-lateral-direita'; } else { c += '-lateral-esquerda'; }
                        break; case 'top5': case 'rod5': if (a && left <= (tipw + 30)) { c += '-lateral-esquerda'; } else { x += -tipw + w; c += '-lateral-direita'; }
                        break; default: y += -tiph - 5, x += (w / 2) - (tipw / 2); break;
                }
            }
            else {
                if ((e.pageY - tiph - wst - 15) <= 0) { y = e.pageY + 15; c += '-rodape'; } else { y = e.pageY - tiph - 15; c += '-topo'; }
                if ((ww + wsl - e.pageX) <= tipw) { x = e.pageX - tipw - 15; c += '-lateral-esquerda'; } else { x = e.pageX + 15; c += '-lateral-direita'; }
            }
            tip.area.css({ 'top': y, 'left': x }); $('.' + o.classeSeta, tip.area).remove(); tip.area.append('<div class="' + o.classeSeta + '"><div class="' + c + '"></div></div>'); if ($.isFunction(o.onPosiciona)) { o.onPosiciona.apply(tip.area, new Array($t, e, o)); }
            e.preventDefault();
        }
    };

    //Linha Valida 1.1
    $.fn.valida = function (options) { return new $.valida(options, this); }; $.valida = function (options, elem) {
        var padrao = { seletor: '.formulario', classeValidacao: 'valida', classeEmail: 'email', classeUrl: 'url', classeNumero: 'numero', classeRegex: 'regex', atributoRegex: 'regex', ValorSelectPadrao: 0, redireciona: true, onValida: null, onErro: null, onPassa: null, onNaoPassa: null, live: false, liveTempo: 100 }; var o = $.extend(padrao, options), $d = $(document); if (elem === undefined) { elem = $(o.seletor); }
        elem.elements = []; $d.delegate(elem.selector, 'iniciaValida', function () {
            var elems = elem.elements, els = $(elem.selector, elem.context), nEls = els.not(elems); elem.elements = els; nEls.each(function () {
                var $form = $(this); if (!$(this).is('form')) { return false; }
                $(this).find('input, button').filter(':submit').click(function () {
                    var resultado = $.valida.form(o, nEls); if (resultado) {
                        if (!o.redireciona) {
                            if ($.isFunction(o.onPassa)) { o.onPassa.apply($form, new Array($form, o)); }
                            return false;
                        } else { return resultado; }
                    } else {
                        if ($.isFunction(o.onNaoPassa)) { o.onNaoPassa.apply($form, new Array($form, o)); }
                        return false;
                    }
                });
            });
        }); if (o.live) { setInterval(function () { $(elem.selector).trigger('iniciaValida'); }, o.liveTempo); } else { if (elem.length) { elem.trigger('iniciaValida'); } }
    }; $.valida.form = function (o, elem) {
        var passa = true; elem.each(function () {
            $(this).find('input, textarea, select, checkbox, radio').not(':submit').each(function () {
                var $t = $(this); if ($t.hasClass(o.classeValidacao)) {
                    if ($.isFunction(o.onValida)) { o.onValida.apply(this, new Array($t, o)); }
                    if ($t.is('select')) { var tValido = validaSelect($t, o); }
                    else if ($t.is(':checkbox')) { var tValido = validaCheckboxRadio($t, o); }
                    else if ($t.is(':radio')) { var tValido = validaCheckboxRadio($t, o); }
                    else { var tValido = validaInput($t, o); }
                    passa = passa && tValido; if (!tValido) { if ($.isFunction(o.onErro)) { o.onErro.apply(this, new Array($t, o)); } }
                }
            });
        }); return passa;
    }; function validaInput($t, o) {
        var val = $t.val(); ret = true; if ($t.hasClass(o.classeEmail)) { var tmp = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/); if (!tmp.test(val) || val == '') { ret = false; } }
        else if ($t.hasClass(o.classeUrl)) { var tmp = new RegExp(/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/); if (!tmp.test(val) || val == '') { ret = false; } }
        if ($t.hasClass(o.classeNumero)) { var tmp = new RegExp(/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)|(^-?\d*$)/); if (!tmp.test(val) || val == '') { ret = false; } }
        if ($t.hasClass(o.classeRegex)) { var regex = $t.attr(o.atributoRegex); var tmp = new RegExp(regex); if (!tmp.test(val) || val == '') { ret = false; } }
        else { if (val == '') { ret = false; }; }
        return ret;
    }
    function validaSelect($t, o) {
        if (!$t.val() || $t.val() == o.ValorSelectPadrao) { return false; }
        return true;
    }
    function validaCheckboxRadio($t, o) {
        var inputName = $t.attr('name'); var checked = $("input[name=" + inputName + "]:checked").length; if (checked == 0) { return false; }
        return true;
    }
})(jQuery);
