﻿$(document).ready(function() {
    if ($(".faq").length > 0) {
        $(".faq").find("li h4").each(function(e) {
            $(this).bind("click", function(e) {
                if ($(this).hasClass("active")) {
                    $(".faq").find("div.reply").removeClass("show");
                    $(".faq").parent().find("h4").removeClass("active");
                } else {
                    $(".faq").find("div.reply").removeClass("show");
                    $(this).parent().find("div.reply").addClass("show");
                    $(".faq").parent().find("h4").removeClass("active");
                    $(this).parent().find("h4").addClass("active");
                }
            });
        });
    }

    if ($(".p-cadastro").length > 0) {
        $("#DtInicio").mask("99/9999");
        $("#DtFim").mask("99/9999");
        $("#DtInicioCurso").mask("99/9999");
        $("#DtFimCurso").mask("99/9999");
        $("#DataNascimento").mask("99/99/9999");
    }

    if ($("cancel .box-equipe").length > 0) {
        $(".box-equipe").find("a.equipe-nome").each(function(e) {
            $(this).bind("click", function(e) {
                $(this).parent().addClass("active");
            });
        });

        $(".box-equipe").find("a.equipe-foto").each(function(e) {
            $(this).bind("click", function(e) {
                $(this).parent().parent().addClass("active");
            });
        });

        $(".box-equipe").find("a.bt-close").each(function(e) {
            $(this).bind("click", function(e) {
                $(this).parent().parent().removeClass("active");
            });
        });

    }



    jQuery.preloadCssImages = function() {
        var allImgs = []; //new array for all the image urls  
        var k = 0; //iterator for adding images  
        var sheets = document.styleSheets; //array of stylesheets  

        for (var i = 0; i < sheets.length; i++) {//loop through each stylesheet
            var cssPile = ''; //create large string of all css rules in sheet
            var csshref = (sheets[i].href) ? sheets[i].href : 'window.location.href';
            var baseURLarr = csshref.split('/'); //split href at / to make array
            baseURLarr.pop(); //remove file path from baseURL array
            var baseURL = baseURLarr.join('/'); //create base url for the images in this sheet (css file's dir)
            if (baseURL != "") baseURL += '/'; //tack on a / if needed
            if (
            //((typeof document.styleSheets[i].href === "string" && !(new RegExp("https?://")).test(document.styleSheets[i].href)) || (document.styleSheets[i].href === null)) &&
            //document.styleSheets[i].cssRules
                false
            ) {//w3
                var thisSheetRules = document.styleSheets[i].cssRules; //w3
                for (var j = 0; j < thisSheetRules.length; j++) {
                    cssPile += thisSheetRules[j].cssText;
                }
            }
            else {
                cssPile += document.styleSheets[i].cssText;
            }

            //parse cssPile for image urls and load them into the DOM
            var imgUrls = cssPile.match(/[^\(]+\.(gif|jpg|jpeg|png)/g); //reg ex to get a string of between a "(" and a ".filename"
            if (imgUrls != null && imgUrls.length > 0 && imgUrls != '') {//loop array
                var arr = jQuery.makeArray(imgUrls); //create array from regex obj
                jQuery(arr).each(function() {
                    allImgs[k] = new Image(); //new img obj
                    allImgs[k].src = (this[0] == '/' || this.match('http://')) ? this : baseURL + this; //set src either absolute or rel to css dir
                    k++;
                });
            }
        } //loop
        return allImgs;
    }


    $.preloadCssImages();

    // MODAL //
    jQuery.fn.centerBox = function() {
        var that = this;
        function resize() {
            that.css("position", "absolute");
            that.css("height", ($(".box-lightbox > div").height()) + "px");
            that.css("width", ($(".box-lightbox > div").width()) + "px");
            that.css("margin-top", "-" + that.height() / 2 + "px");
            that.css("margin-left", "-" + that.width() / 2 + "px");
        }
        $(window).bind("resize", function(event) {
            resize();
        });
        resize();
        return this;
    };

    jQuery.fn.HeightFull = function() {
        var that = this;
        that.css("height", ($(document).height()) + "px");
        return this;
    };

    $(".box-lightbox").centerBox();
    $(".bg-lightbox").HeightFull();
    $(".l-big").HeightFull();


    // CENTRALIZAR TEXTO //
    jQuery.fn.centerText = function() {
        var that = this;
        function resize() {
            that.css("position", "absolute");
            that.css("top", "50%");
            that.css("height", ($(".texto-conselho p").height()) + "px");
            that.css("margin-top", "-" + that.height() / 2 + "px");
        }
        $(window).bind("resize", function(event) {
            resize();
        });
        resize();
        return this;
    };

    $(".texto-conselho p").centerText();

    //	LINHA DO TEMPO //
    $('cancel .linha-tempo-nav').find('li').each(function(e) {
        $(this).bind("click", function(e) {
            var $this = $(this),
                $linha_do_tempo_nav = $('.linha-tempo-nav'),
                $linha_do_tempo_main = $('.linha-tempo-main'),
                view_port = $linha_do_tempo_nav.width(),
                number_of_items = $('.linha-tempo-nav li').size(),
                width = $this.width(),
                items_in_viewport = Math.ceil(view_port / width),
                limit = Math.floor(items_in_viewport / Math.floor(items_in_viewport / 2)) * width,
                index = $this.index(),
                step = width * index,
                stepback = step - limit,
                margin_limit = (number_of_items - (Math.floor(items_in_viewport / 2))) * width - (limit + width),
                tmp = '.' + $this.attr('class').replace('nav', 'ano'),
                old_index = $linha_do_tempo_nav.find('li:has(a.active)').index(),
                multiplier = -1,
                $current_div = $linha_do_tempo_main.find('div.show'),
                current_div_width = $current_div.width(),
                $div_to_show = $linha_do_tempo_main.find(tmp);

            if (old_index === index) return false;

            if (step >= limit) {
                if (stepback > margin_limit) {
                    stepback = margin_limit;
                    step = step - ((number_of_items - items_in_viewport) * width);
                } else {
                    step = limit;
                }
                $linha_do_tempo_nav.find("ul").css("margin-left", -stepback);
            }
            $linha_do_tempo_nav.find('li a').removeClass('active');

            $this.find('a').addClass('active');

            if (old_index > index) {
                $div_to_show.css("margin-left", (current_div_width * -1) + "px").animate({
                    "margin-left": "0px"
                }, {
                    complete: function() {
                        var $this = $(this);
                        $current_div.removeClass("show");
                    }
                });
                multiplier = 1;
            } else {
                $current_div.animate({
                    "margin-left": (current_div_width * -1) + "px"
                }, {
                    complete: function() {
                        var $this = $(this);
                        $this.removeClass("show").css("margin-left", "0");
                    }
                });
            }

            $div_to_show.addClass('show');

            $linha_do_tempo_nav.find('.bar').find('.track').css('left', step + "px");

            return false;
        });
    });

    // TABS //
    $('.tabs .footer-main').hide(); // Hide all divs
    $('.tabs div:first').show(); // Show the first div
    $('.tabs ul li:first').addClass('active'); // Set the class of the first link to active
    $('.tabs ul.tab-nav li a').click(function() { //When any link is clicked
        $('.tabs ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('.tabs .footer-main').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });

    // TABS //
    $('.tabs-2 .redes-sociais').hide(); // Hide all divs
    $('.tabs-2 div:first').show(); // Show the first div
    $('.tabs-2 ul li:first').addClass('active'); // Set the class of the first link to active
    $('.tabs-2 ul.tab-nav li a').click(function() { //When any link is clicked
        $('.tabs-2 ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('.tabs-2 .redes-sociais').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        $('#scrollbar1').tinyscrollbar();
        return false;
    });

    // TABS //
    $('.tabs-3 .box-ranking').hide(); // Hide all divs
    $('.tabs-3 div:first').show(); // Show the first div
    $('.tabs-3 ul li:first').addClass('active'); // Set the class of the first link to active
    $('.tabs-3 ul.tab-nav li a').click(function() { //When any link is clicked
        $('.tabs-3 ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('.tabs-3 .box-ranking').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        $('#scrollbar1').tinyscrollbar();
        return false;
    });
    
    // TABS //
    $('.hotsite-abas .hotsite-abas-content').hide(); // Hide all divs
    $('.hotsite-abas .hotsite-abas-content:first').show(); // Show the first div
    $('.hotsite-abas > ul li:first').addClass('active'); // Set the class of the first link to active
    $('.hotsite-abas > ul li a').click(function() { //When any link is clicked
    $('.hotsite-abas > ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('.hotsite-abas .hotsite-abas-content').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });

    // TABS //
    $('.b-competicoes .hotsite-competicoes').hide(); // Hide all divs
    //$('.b-competicoes .hotsite-competicoes:first').show(); // Show the first div
    //$('.b-competicoes > ul li:first').addClass('active'); // Set the class of the first link to active
    $('.b-competicoes > ul li a').click(function() { //When any link is clicked
    $('.b-competicoes > ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('.b-competicoes .hotsite-competicoes').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });
        
    // DISPLAY FOOTER //
    $("#show-footer").toggle(function() {
        $(".acesso-footer span").html('-').removeClass('more').addClass('less')
        $(".footer-content").slideDown(function() {
            var x = $(window).scrollTop() + $(window).height();
            $('html, body').animate({ scrollTop: x }, 'slow');
        });
    },
	   function() {
	       $(".acesso-footer span").html('+').removeClass('less').addClass('more');
	       $(".footer-content").slideUp();
	   });

    // SLIDER //
    $(".slider-show").sliderHorizontal({ slideDuration: 200 });

    // LOGIN
    $(".box-minha-fe > a").toggle(function() {
        $(".box-login").addClass('show');
    },
	function() {
	    $(".box-login").removeClass('show');
	});

    // DISPLAY COMPARTILHAR VIDEO E-MAIL
    $(".share-mail > a").toggle(function() {
        $(".cp-share-mail").addClass('show');
    },
	function() {
	    $(".cp-share-mail").removeClass('show');
	});
    $(".close-share").click(function() {
        $(".cp-share-mail").removeClass('show');
    });
});

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

// SCROLL //
(function($) {
    $.fn.tinyscrollbar = function(options) {
        if (this.size() > 0) {
            var defaults = {
                axis: 'y',
                scroll: true,
                size: 'auto',
                sizethumb: 54
            };
            var options = $.extend(defaults, options);
            var oWrapper = $(this); var oViewport = {
                obj: $('.viewport', this)
            };
            var oContent = {
                obj: $('.overview', this)
            };
            var oScrollbar = {
                obj: $('.scrollbar', this)
            };
            var oTrack = {
                obj: $('.track', oScrollbar.obj)
            }; var oThumb = {
                obj: $('.thumb', oScrollbar.obj)
            };
            var sAxis = options.axis == 'x', sDirection = sAxis ? 'left' : 'top', sSize = sAxis ? 'Width' : 'Height';
            var iScroll, iPosition = {
                start: 0, now: 0
            }, iMouse = {};
            if (this.length > 1) {
                this.each(function() {
                    $(this).tinyscrollbar(options)
                });
                return this;
            }
            this.initialize = function() {
                this.update();
                setEvents();
            };
            this.update = function() {
                iScroll = 0;
                oViewport[options.axis] = oViewport.obj[0]['offset' + sSize];
                oContent[options.axis] = oContent.obj[0]['scroll' + sSize];
                oContent.ratio = oViewport[options.axis] / oContent[options.axis];
                oScrollbar.obj.toggleClass('disable', oContent.ratio >= 1);
                oTrack[options.axis] = options.size == 'auto' ? oViewport[options.axis] : options.size;
                oThumb[options.axis] = Math.min(oTrack[options.axis], Math.max(0, (options.sizethumb == 'auto' ? (oTrack[options.axis] * oContent.ratio) : options.sizethumb)));
                oScrollbar.ratio = options.sizethumb == 'auto' ? (oContent[options.axis] / oTrack[options.axis]) : (oContent[options.axis] - oViewport[options.axis]) / (oTrack[options.axis] - oThumb[options.axis]);
                oScrollbar.ratio = isNaN(oScrollbar.ratio) ? 0 : oScrollbar.ratio;
                setSize();
            }; function setSize() {
                oContent.obj.removeAttr('style');
                oThumb.obj.removeAttr('style');
                iMouse['start'] = oThumb.obj.offset()[sDirection];
                var sCssSize = sSize.toLowerCase();
                oScrollbar.obj.css(sCssSize, oTrack[options.axis]);
                oTrack.obj.css(sCssSize, oTrack[options.axis]);
                oThumb.obj.css(sCssSize, oThumb[options.axis]);
            };
            function setEvents() {
                oThumb.obj.bind('mousedown', start);
                oTrack.obj.bind('mouseup', drag);
                if (options.scroll && this.addEventListener) {
                    oWrapper[0].addEventListener('DOMMouseScroll', wheel, false);
                    oWrapper[0].addEventListener('mousewheel', wheel, false);
                }
                else if (options.scroll) {
                    oWrapper[0].onmousewheel = wheel;
                }
            };
            function start(oEvent) {
                iMouse.start = sAxis ? oEvent.pageX : oEvent.pageY;
                iPosition.start = parseInt(oThumb.obj.css(sDirection));
                $(document).bind('mousemove', drag);
                $(document).bind('mouseup', end);
                oThumb.obj.bind('mouseup', end);
                return false;
            }; function wheel(oEvent) {
                if (!(oContent.ratio >= 1)) {
                    oEvent = $.event.fix(oEvent || window.event);
                    var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta / 120 : -oEvent.detail / 3;
                    iScroll -= iDelta * options.wheel;
                    iScroll = Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll));
                    oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio);
                    oContent.obj.css(sDirection, -iScroll); oEvent.preventDefault();
                };
            };
            function end(oEvent) {
                $(document).unbind('mousemove', drag);
                $(document).unbind('mouseup', end);
                oThumb.obj.unbind('mouseup', end);
                return false;
            };
            function drag(oEvent) {
                if (!(oContent.ratio >= 1)) {
                    iPosition.now = Math.min((oTrack[options.axis] - oThumb[options.axis]), Math.max(0, (iPosition.start + ((sAxis ? oEvent.pageX : oEvent.pageY) - iMouse.start)))); iScroll = iPosition.now * oScrollbar.ratio; oContent.obj.css(sDirection, -iScroll);
                    oThumb.obj.css(sDirection, iPosition.now);
                    ;
                }
                return false;
            };
            return this.initialize();
        };
    }


})(jQuery);

// SLIDER //
//(function($) {
//    // plugin definition  
//    $.fn.sliderHorizontal = function(optionSent) {
//        // build main options before element iteration  
//        var opts = $.extend({}, $.fn.sliderHorizontal.defaults, optionSent);

//        return this.each(function() {
//            slideRunning = false;
//            $this = $(this);
//            $this.find(".slider > li:first").addClass("active");
//            // build element specific options  
//            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
//            // update element styles  
//            $this.find(".arrow").live("mouseup", function(e) {
//                if (slideRunning) return; //skip if animation is running  
//                slideRunning = true; //set animation state: running  
//                $parent = $(this).parent();

//                wid = $parent.find(".slider > li:first").width();
//                ind = $parent.parent().find(".slider-show").find(".arrow").index($(this));
//                sld = $parent.find(".slider-show").find(".slider > li").index($parent.find(".active"));
//                qtd = $parent.find(".slider > li").length;

//                if (ind == 0) {//go left  
//                    margin = 0;
//                    $parent.find(".slider").prepend($parent.find(".slider > li:last"));
//                    $parent.find(".slider").css("margin-left", (-wid) + "px");
//                } else {//go right  
//                    margin = (sld) * wid;
//                }
//                $parent.find(".slider").stop().animate(
//                        { marginLeft: margin + "px" },
//                        {
//                            duration: o.slideDuration,
//                            complete: function(p) {
//                                if (ind == 1) {
//                                    $parent.find(".slider").append($parent.find(".slider > li:first"));
//                                    $parent.find(".slider").css("margin-left", "0");
//                                }
//                                $parent.find(".active").removeClass("active");
//                                $parent.find(".slider > li:first").addClass("active");

//                                slideRunning = false; //set animation state: stopped  
//                            }
//                        });
//            });
//        });
//    };

//    // plugin defaults  
//    $.fn.sliderHorizontal.defaults = {
//        slideDuration: 150
//    };
//})(jQuery); // end of plugin

// SLIDER //
(function($) {
    // plugin definition  
    $.fn.sliderHorizontal = function(optionSent) {
        // build main options before element iteration  
        var opts = $.extend({}, $.fn.sliderHorizontal.defaults, optionSent);

        return this.each(function() {
            var $this = $(this),
                viewport_width = $this.find("div.slider-mask").width(),
                item_width = $this.find("li").outerWidth(true),
                item_length = $this.find("li").size(),
                items_in_viewport = Math.floor(viewport_width / item_width),
                $first = $this.find("li").first().addClass("first-element"),
                $last = $this.find("li").last().addClass("last-element");

            slideRunning = false;
            $this = $(this);
            $this.find(".slider > li:first").addClass("active");

            if (items_in_viewport === item_length) {
                $this.find(".arrow").addClass("hide");
            } else {
                $this.find(".arrow:first").addClass("hide");
            }
            // build element specific options  
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
            // update element styles  
            $this.find(".arrow").live("mouseup", function(e) {
                if (slideRunning) return; //skip if animation is running  
                slideRunning = true; //set animation state: running  
                $parent = $(this).parent();

                wid = $parent.find(".slider > li:first").width();
                ind = $parent.parent().find(".slider-show").find(".arrow").index($(this));
                sld = $parent.find(".slider-show").find(".slider > li").index($parent.find(".active"));
                //sld = $parent.find(".active").index();
                qtd = $parent.find(".slider > li").length;

                if (ind == 0) {//go left  
                    margin = 0;
                    $parent.find(".slider").css("margin-left", (-wid) + "px");
                    $parent.find(".slider").prepend($parent.find(".slider > li:last")); //
                } else {//go right  
                    margin = (sld) * wid;
                }
                $parent.find(".slider").stop().animate(
                        { marginLeft: margin + "px" },
                        {
                            duration: o.slideDuration,
                            complete: function(p) {
                                var $arrows = $parent.parent().find(".slider-show").find(".arrow"),
                                    x = $parent.find(".slider-mask").width(),
                                    y = $parent.find(".slider-mask li").outerWidth(true),
                                    z = Math.ceil(x / y) - 1;

                                $arrows.removeClass("hide");

                                if (ind == 1) {//go right  
                                    $parent.find(".slider").append($parent.find(".slider > li:first"));
                                    $parent.find(".slider").css("margin-left", "0");
                                    //if ($parent.find(".slider li").eq(z).is($last)) {
                                    if ($parent.find(".slider li").eq(z).hasClass("last-element")) {
                                        $arrows.filter(".right").addClass("hide");
                                    }
                                } else if (ind == 0) {//go left
                                    //$parent.find(".slider").prepend($parent.find(".slider > li:last"));
                                    //if ($parent.find(".slider > li:first").is($first)) {
                                    if ($parent.find(".slider > li:first").hasClass("first-element")) {
                                        $arrows.filter(".left").addClass("hide");
                                    }
                                }

                                $parent.find(".active").removeClass("active");
                                $parent.find(".slider > li:first").addClass("active");

                                slideRunning = false; //set animation state: stopped  
                            }
                        });
            });
        });
    };

    // plugin defaults  
    $.fn.sliderHorizontal.defaults = {
        slideDuration: 150
    };
})(jQuery);                 // end of plugin 

// FORMS //
(function(a) { a.uniform = { options: { selectClass: "selector", radioClass: "radio", checkboxClass: "checker", fileClass: "uploader", filenameClass: "filename", fileBtnClass: "action", fileDefaultText: "Nenhum arquivo selecionado", fileBtnText: "Upload", checkedClass: "checked", focusClass: "focus", disabledClass: "disabled", buttonClass: "button", activeClass: "active", hoverClass: "hover", useID: true, idPrefix: "uniform", resetSelector: false, autoHide: true }, elements: [] }; if (a.browser.msie && a.browser.version < 7) { a.support.selectOpacity = false } else { a.support.selectOpacity = true } a.fn.uniform = function(k) { k = a.extend(a.uniform.options, k); var d = this; if (k.resetSelector != false) { a(k.resetSelector).mouseup(function() { function l() { a.uniform.update(d) } setTimeout(l, 10) }) } function j(l) { $el = a(l); $el.addClass($el.attr("type")); b(l) } function g(l) { a(l).addClass("uniform"); b(l) } function i(o) { var m = a(o); var p = a("<div>"), l = a("<span>"); p.addClass(k.buttonClass); if (k.useID && m.attr("id") != "") { p.attr("id", k.idPrefix + "-" + m.attr("id")) } var n; if (m.is("a") || m.is("button")) { n = m.text() } else { if (m.is(":submit") || m.is(":reset") || m.is("input[type=button]")) { n = m.attr("value") } } n = n == "" ? m.is(":reset") ? "Reset" : "Submit" : n; l.html(n); m.css("opacity", 0); m.wrap(p); m.wrap(l); p = m.closest("div"); l = m.closest("span"); if (m.is(":disabled")) { p.addClass(k.disabledClass) } p.bind({ "mouseenter.uniform": function() { p.addClass(k.hoverClass) }, "mouseleave.uniform": function() { p.removeClass(k.hoverClass); p.removeClass(k.activeClass) }, "mousedown.uniform touchbegin.uniform": function() { p.addClass(k.activeClass) }, "mouseup.uniform touchend.uniform": function() { p.removeClass(k.activeClass) }, "click.uniform touchend.uniform": function(r) { if (a(r.target).is("span") || a(r.target).is("div")) { if (o[0].dispatchEvent) { var q = document.createEvent("MouseEvents"); q.initEvent("click", true, true); o[0].dispatchEvent(q) } else { o[0].click() } } } }); o.bind({ "focus.uniform": function() { p.addClass(k.focusClass) }, "blur.uniform": function() { p.removeClass(k.focusClass) } }); a.uniform.noSelect(p); b(o) } function e(o) { var m = a(o); var p = a("<div />"), l = a("<span />"); if (!m.css("display") == "none" && k.autoHide) { p.hide() } p.addClass(k.selectClass); if (k.useID && o.attr("id") != "") { p.attr("id", k.idPrefix + "-" + o.attr("id")) } var n = o.find(":selected:first"); if (n.length == 0) { n = o.find("option:first") } l.html(n.html()); o.css("opacity", 0); o.wrap(p); o.before(l); p = o.parent("div"); l = o.siblings("span"); o.bind({ "change.uniform": function() { l.text(o.find(":selected").html()); p.removeClass(k.activeClass) }, "focus.uniform": function() { p.addClass(k.focusClass) }, "blur.uniform": function() { p.removeClass(k.focusClass); p.removeClass(k.activeClass) }, "mousedown.uniform touchbegin.uniform": function() { p.addClass(k.activeClass) }, "mouseup.uniform touchend.uniform": function() { p.removeClass(k.activeClass) }, "click.uniform touchend.uniform": function() { p.removeClass(k.activeClass) }, "mouseenter.uniform": function() { p.addClass(k.hoverClass) }, "mouseleave.uniform": function() { p.removeClass(k.hoverClass); p.removeClass(k.activeClass) }, "keyup.uniform": function() { l.text(o.find(":selected").html()) } }); if (a(o).attr("disabled")) { p.addClass(k.disabledClass) } a.uniform.noSelect(l); b(o) } function f(n) { var m = a(n); var o = a("<div />"), l = a("<span />"); if (!m.css("display") == "none" && k.autoHide) { o.hide() } o.addClass(k.checkboxClass); if (k.useID && n.attr("id") != "") { o.attr("id", k.idPrefix + "-" + n.attr("id")) } a(n).wrap(o); a(n).wrap(l); l = n.parent(); o = l.parent(); a(n).css("opacity", 0).bind({ "focus.uniform": function() { o.addClass(k.focusClass) }, "blur.uniform": function() { o.removeClass(k.focusClass) }, "click.uniform touchend.uniform": function() { if (!a(n).attr("checked")) { l.removeClass(k.checkedClass) } else { l.addClass(k.checkedClass) } }, "mousedown.uniform touchbegin.uniform": function() { o.addClass(k.activeClass) }, "mouseup.uniform touchend.uniform": function() { o.removeClass(k.activeClass) }, "mouseenter.uniform": function() { o.addClass(k.hoverClass) }, "mouseleave.uniform": function() { o.removeClass(k.hoverClass); o.removeClass(k.activeClass) } }); if (a(n).attr("checked")) { l.addClass(k.checkedClass) } if (a(n).attr("disabled")) { o.addClass(k.disabledClass) } b(n) } function c(n) { var m = a(n); var o = a("<div />"), l = a("<span />"); if (!m.css("display") == "none" && k.autoHide) { o.hide() } o.addClass(k.radioClass); if (k.useID && n.attr("id") != "") { o.attr("id", k.idPrefix + "-" + n.attr("id")) } a(n).wrap(o); a(n).wrap(l); l = n.parent(); o = l.parent(); a(n).css("opacity", 0).bind({ "focus.uniform": function() { o.addClass(k.focusClass) }, "blur.uniform": function() { o.removeClass(k.focusClass) }, "click.uniform touchend.uniform": function() { if (!a(n).attr("checked")) { l.removeClass(k.checkedClass) } else { var p = k.radioClass.split(" ")[0]; a("." + p + " span." + k.checkedClass + ":has([name='" + a(n).attr("name") + "'])").removeClass(k.checkedClass); l.addClass(k.checkedClass) } }, "mousedown.uniform touchend.uniform": function() { if (!a(n).is(":disabled")) { o.addClass(k.activeClass) } }, "mouseup.uniform touchbegin.uniform": function() { o.removeClass(k.activeClass) }, "mouseenter.uniform touchend.uniform": function() { o.addClass(k.hoverClass) }, "mouseleave.uniform": function() { o.removeClass(k.hoverClass); o.removeClass(k.activeClass) } }); if (a(n).attr("checked")) { l.addClass(k.checkedClass) } if (a(n).attr("disabled")) { o.addClass(k.disabledClass) } b(n) } function h(q) { var o = a(q); var r = a("<div />"), p = a("<span>" + k.fileDefaultText + "</span>"), m = a("<span>" + k.fileBtnText + "</span>"); if (!o.css("display") == "none" && k.autoHide) { r.hide() } r.addClass(k.fileClass); p.addClass(k.filenameClass); m.addClass(k.fileBtnClass); if (k.useID && o.attr("id") != "") { r.attr("id", k.idPrefix + "-" + o.attr("id")) } o.wrap(r); o.after(m); o.after(p); r = o.closest("div"); p = o.siblings("." + k.filenameClass); m = o.siblings("." + k.fileBtnClass); if (!o.attr("size")) { var l = r.width(); o.attr("size", l / 10) } var n = function() { var s = o.val(); if (s === "") { s = k.fileDefaultText } else { s = s.split(/[\/\\]+/); s = s[(s.length - 1)] } p.text(s) }; n(); o.css("opacity", 0).bind({ "focus.uniform": function() { r.addClass(k.focusClass) }, "blur.uniform": function() { r.removeClass(k.focusClass) }, "mousedown.uniform": function() { if (!a(q).is(":disabled")) { r.addClass(k.activeClass) } }, "mouseup.uniform": function() { r.removeClass(k.activeClass) }, "mouseenter.uniform": function() { r.addClass(k.hoverClass) }, "mouseleave.uniform": function() { r.removeClass(k.hoverClass); r.removeClass(k.activeClass) } }); if (a.browser.msie) { o.bind("click.uniform.ie7", function() { setTimeout(n, 0) }) } else { o.bind("change.uniform", n) } if (o.attr("disabled")) { r.addClass(k.disabledClass) } a.uniform.noSelect(p); a.uniform.noSelect(m); b(q) } a.uniform.restore = function(l) { if (l == undefined) { l = a(a.uniform.elements) } a(l).each(function() { if (a(this).is(":checkbox")) { a(this).unwrap().unwrap() } else { if (a(this).is("select")) { a(this).siblings("span").remove(); a(this).unwrap() } else { if (a(this).is(":radio")) { a(this).unwrap().unwrap() } else { if (a(this).is(":file")) { a(this).siblings("span").remove(); a(this).unwrap() } else { if (a(this).is("button, :submit, :reset, a, input[type='button']")) { a(this).unwrap().unwrap() } } } } } a(this).unbind(".uniform"); a(this).css("opacity", "1"); var m = a.inArray(a(l), a.uniform.elements); a.uniform.elements.splice(m, 1) }) }; function b(l) { l = a(l).get(); if (l.length > 1) { a.each(l, function(m, n) { a.uniform.elements.push(n) }) } else { a.uniform.elements.push(l) } } a.uniform.noSelect = function(l) { function m() { return false } a(l).each(function() { this.onselectstart = this.ondragstart = m; a(this).mousedown(m).css({ MozUserSelect: "none" }) }) }; a.uniform.update = function(l) { if (l == undefined) { l = a(a.uniform.elements) } l = a(l); l.each(function() { var n = a(this); if (n.is("select")) { var m = n.siblings("span"); var p = n.parent("div"); p.removeClass(k.hoverClass + " " + k.focusClass + " " + k.activeClass); m.html(n.find(":selected").html()); if (n.is(":disabled")) { p.addClass(k.disabledClass) } else { p.removeClass(k.disabledClass) } } else { if (n.is(":checkbox")) { var m = n.closest("span"); var p = n.closest("div"); p.removeClass(k.hoverClass + " " + k.focusClass + " " + k.activeClass); m.removeClass(k.checkedClass); if (n.is(":checked")) { m.addClass(k.checkedClass) } if (n.is(":disabled")) { p.addClass(k.disabledClass) } else { p.removeClass(k.disabledClass) } } else { if (n.is(":radio")) { var m = n.closest("span"); var p = n.closest("div"); p.removeClass(k.hoverClass + " " + k.focusClass + " " + k.activeClass); m.removeClass(k.checkedClass); if (n.is(":checked")) { m.addClass(k.checkedClass) } if (n.is(":disabled")) { p.addClass(k.disabledClass) } else { p.removeClass(k.disabledClass) } } else { if (n.is(":file")) { var p = n.parent("div"); var o = n.siblings(k.filenameClass); btnTag = n.siblings(k.fileBtnClass); p.removeClass(k.hoverClass + " " + k.focusClass + " " + k.activeClass); o.text(n.val()); if (n.is(":disabled")) { p.addClass(k.disabledClass) } else { p.removeClass(k.disabledClass) } } else { if (n.is(":submit") || n.is(":reset") || n.is("button") || n.is("a") || l.is("input[type=button]")) { var p = n.closest("div"); p.removeClass(k.hoverClass + " " + k.focusClass + " " + k.activeClass); if (n.is(":disabled")) { p.addClass(k.disabledClass) } else { p.removeClass(k.disabledClass) } } } } } } }) }; return this.each(function() { if (a.support.selectOpacity) { var l = a(this); if (l.is("select")) { if (l.attr("multiple") != true) { if (l.attr("size") == undefined || l.attr("size") <= 1) { e(l) } } } else { if (l.is(":checkbox")) { f(l) } else { if (l.is(":radio")) { c(l) } else { if (l.is(":file")) { h(l) } else { if (l.is(":text, :password, input[type='email']")) { j(l) } else { if (l.is("textarea")) { g(l) } else { if (l.is("a") || l.is(":submit") || l.is(":reset") || l.is("button") || l.is("input[type=button]")) { i(l) } } } } } } } } }) } })(jQuery);

$(function() {
    //$("input:radio, select").uniform();
});

$.fn.linhaDoTempo = function() {
    $(this).each(function(index, element) {
        var $this = $(this),
                    duracao_animacao = 200,
                    $linha_do_tempo = $this, //$("div.caixa"),
                    $textos = $linha_do_tempo.find("div.textos").children("div"),
                    $lista_opcoes = $linha_do_tempo.find("div.opcoes").find("ul"),
                    $opcoes = $lista_opcoes.find("li"),
                    $bar_track = $linha_do_tempo.find("div.bar div.track"),
                    quantidade = $opcoes.size(),
                    tamanho_individual = $opcoes.eq(0).outerWidth(true),
                    tamanho_texto = $textos.eq(0).outerWidth(true),
                    quantidade_porta_visao = Math.ceil($linha_do_tempo.find("div.opcoes").width() / tamanho_individual),
                    antes_do_meio = Math.floor(quantidade_porta_visao / 2),
                    tamanho_total = quantidade * tamanho_individual,
                    margem_limite_inicial = 0,
                    margem_limite_final = tamanho_total - (quantidade_porta_visao * tamanho_individual);

        $opcoes.bind("click", function(event) {
            var $this = $(this),
                        margem_esquerda_antiga = cssToInt($lista_opcoes.css("margin-left")),
                        indice = $this.index(),
                        indice_antigo = $opcoes.has("a.active").index(),
                        $texto_exibir = $textos.eq(indice),
                        $texto_ao_lado = $textos.eq(indice_antigo),
                        margem_mover = (indice - antes_do_meio) * tamanho_individual,
                        posicao_atual,
                        indice_relativo,
                        margem_esquerda;

            if (indice === indice_antigo) return false;

            if (margem_mover > margem_limite_final) margem_mover = margem_limite_final;
            if (margem_mover < margem_limite_inicial) margem_mover = margem_limite_inicial;

            margem_mover = -margem_mover;

            margem_esquerda = margem_mover;

            posicao_atual = (tamanho_total - margem_esquerda) - tamanho_total;
            indice_relativo = indice + (margem_esquerda / tamanho_individual);

            $lista_opcoes.animate({
                "margin-left": margem_mover + "px"
            }, {
                queue: false,
                duration: duracao_animacao,
                complete: function() {
                    var $this = $(this);
                }
            });

            $bar_track.animate({
                "left": (indice_relativo * tamanho_individual) + "px"
            }, {
                queue: false,
                duration: duracao_animacao,
                complete: function() {
                    var $this = $(this);
                }
            });

            $texto_exibir.addClass("show").css("margin-left", "0");
            $texto_ao_lado.addClass("show").css("margin-left", "0");
            $texto_exibir.data("indice_antigo", indice_antigo);
            $texto_ao_lado.data("indice", indice);
            if (indice > indice_antigo) { //>>>
                $texto_ao_lado.animate({
                    "margin-left": (-tamanho_texto) + "px"
                }, {
                    queue: false,
                    duration: duracao_animacao,
                    complete: function() {
                        var $this = $(this),
                                    $texto_exibir = $textos.eq(parseInt($this.data("indice"), 10));
                        $this.removeClass("show").css("margin-left", "0");
                        $texto_exibir.addClass("show");
                    }
                });
            } else if (indice_antigo > indice) { //<<<
                $texto_exibir.css("margin-left", (-tamanho_texto) + "px").animate({
                    "margin-left": "0"
                }, {
                    queue: false,
                    duration: duracao_animacao,
                    complete: function() {
                        var $this = $(this),
                                    $texto_ao_lado = $textos.eq(parseInt($this.data("indice_antigo"), 10));
                        $texto_ao_lado.removeClass("show");
                        $this.addClass("show");
                    }
                });
            }

            $opcoes.find("a").removeClass("active");
            $this.find("a").addClass("active");
        });
    });
};

//$.fn.rotacaoPerfis = function() {
//    $(this).each(function(index, element) {
//        var $this = $(this),
//                        duracao_animacao = 200,
//                        $box_equipe = $this,
//                        $lista_caixas = $box_equipe.find("ul"),
//                        $caixas = $box_equipe.find("li"),
//                        $nomes = $caixas.find("a.equipe-nome"),
//                        $fotos = $caixas.find("a.equipe-foto"),
//                        $botoes_fechar = $caixas.find("a.bt-close"),
//                        $bar_track = $box_equipe.find("div.bar div.track"),
//                        quantidade = $caixas.size(),
//                        tamanho_individual = $caixas.eq(0).outerWidth(true),
//                        quantidade_porta_visao = Math.ceil($box_equipe.width() / tamanho_individual),
//                        antes_do_meio = Math.floor(quantidade_porta_visao / 2),
//                        tamanho_total = quantidade * tamanho_individual,
//                        margem_limite_inicial = 0,
//                        margem_limite_final = tamanho_total - (quantidade_porta_visao * tamanho_individual),
//                        fotos_click = function(event) {
//                            var $this = $(this),
//                                $caixa_atual = $this.parents("li"),
//                                $foto_atual = $caixa_atual.find(".img img"),
//                                $outras_caixas = $caixas.not($caixa_atual[0]),
//                                indice = $caixa_atual.index(),
//                                margem_esquerda = cssToInt($lista_caixas.css("margin-left")),
//                                indice_relativo,
//                                deslocamento_para_esquerda,
//                                elementos_escondidos_a_esquerda,
//                                posicao_relativa;

//                            $fotos.unbind("click");
//                            $nomes.unbind("click");

//                            indice_relativo = indice + (margem_esquerda / tamanho_individual);

//                            elementos_escondidos_a_esquerda = indice - indice_relativo;

//                            posicao_relativa = elementos_escondidos_a_esquerda * tamanho_individual;

//                            deslocamento_para_esquerda = (indice_relativo + elementos_escondidos_a_esquerda) * tamanho_individual;

//                            $outras_caixas.removeClass("active");

//                            $foto_atual.addClass("big");

//                            $outras_caixas.animate({
//                                "opacity": "0"
//                            }, {
//                                queue: false,
//                                duration: duracao_animacao,
//                                complete: function() {
//                                    var $this = $(this);
//                                    $caixa_atual.addClass("absolute").css("left", deslocamento_para_esquerda + "px").animate({
//                                        "left": (posicao_relativa) + "px"
//                                    }, {
//                                        queue: false,
//                                        complete: function() {
//                                            var $this = $(this);
//                                            $this.addClass("active");
//                                            $foto_atual.removeClass("big");
//                                        }
//                                    });
//                                }
//                            });

//                            return false;
//                        },
//                        nomes_click = function(event) {
//                            var $this = $(this),
//                                margem_esquerda_antiga = cssToInt($lista_caixas.css("margin-left")),
//                                $caixa_atual = $this.parents("li"),
//                                indice = $caixa_atual.index(),
//                                indice_antigo = $caixas.filter("li.active").index(),
//                                margem_mover = (indice - antes_do_meio) * tamanho_individual,
//                                posicao_atual,
//                                indice_relativo,
//                                margem_esquerda;

//                            if (indice === indice_antigo) return false;

//                            $nomes.unbind("click");

//                            if (margem_mover > margem_limite_final) margem_mover = margem_limite_final;
//                            if (margem_mover < margem_limite_inicial) margem_mover = margem_limite_inicial;

//                            margem_mover = -margem_mover;

//                            margem_esquerda = margem_mover;

//                            posicao_atual = (tamanho_total - margem_esquerda) - tamanho_total;
//                            indice_relativo = indice + (margem_esquerda / tamanho_individual);

//                            $lista_caixas.animate({
//                                "margin-left": margem_mover + "px"
//                            }, {
//                                queue: false,
//                                duration: duracao_animacao,
//                                complete: function() {
//                                    var $this = $(this);
//                                }
//                            });

//                            $bar_track.animate({
//                                "left": (indice_relativo * tamanho_individual) + "px"
//                            }, {
//                                queue: false,
//                                duration: duracao_animacao,
//                                complete: function() {
//                                    var $this = $(this);
//                                    $nomes.bind("click", nomes_click);
//                                }
//                            });

//                            return false;
//                        };

//        $nomes.bind("click", nomes_click);

//        $fotos.bind("click", fotos_click);

//        $botoes_fechar.bind("click", function(event) {
//            var $this = $(this),
//                            $caixa_atual = $this.parents("li"),
//                            $foto_atual = $caixa_atual.find(".img img"),
//                            $outras_caixas = $caixas.not($caixa_atual[0]),
//                            indice = $caixa_atual.index(),
//                            margem_esquerda = cssToInt($lista_caixas.css("margin-left")),
//                            indice_relativo,
//                            deslocamento_para_esquerda,
//                            elementos_escondidos_a_esquerda;

//            indice_relativo = indice + (margem_esquerda / tamanho_individual);

//            elementos_escondidos_a_esquerda = indice - indice_relativo;

//            deslocamento_para_esquerda = (indice_relativo + elementos_escondidos_a_esquerda) * tamanho_individual;

//            console.log({
//                indice_relativo: indice_relativo,
//                elementos_escondidos_a_esquerda: elementos_escondidos_a_esquerda,
//                tamanho_individual: tamanho_individual,
//                indice: indice
//            });

//            $foto_atual.addClass("big");

//            $caixa_atual.removeClass("active").animate({
//                "left": deslocamento_para_esquerda + "px"
//            }, {
//                queue: false,
//                duration: duracao_animacao,
//                complete: function() {
//                    var $this = $(this);
//                    $foto_atual.removeClass("big");
//                    $caixa_atual.removeClass("absolute").css("left", "auto");
//                    $caixas.removeClass("active").animate({
//                        "opacity": "1"
//                    }, {
//                        queue: false,
//                        complete: function() {
//                            var $this = $(this);
//                            $fotos.bind("click", fotos_click);
//                            $nomes.bind("click", nomes_click);
//                        }
//                    });
//                }
//            });

//            return false;
//        });
//    });
//};

$.fn.rotacaoPerfis = function() {
    $(this).each(function(index, element) {
        var $this = $(this),
                        duracao_animacao = 200,
                        $box_equipe = $this,
                        $lista_caixas = $box_equipe.find("ul"),
                        $caixas = $box_equipe.find("li"),
                        $nomes = $caixas.find("a.equipe-nome"),
                        $fotos = $caixas.find("a.equipe-foto"),
                        $botoes_fechar = $caixas.find("a.bt-close"),
                        $bar_track = $box_equipe.find("div.bar div.track"),
                        quantidade = $caixas.size(),
                        tamanho_individual = $caixas.eq(0).outerWidth(true),
                        quantidade_porta_visao = Math.ceil($box_equipe.width() / tamanho_individual),
                        antes_do_meio = Math.floor(quantidade_porta_visao / 2),
                        tamanho_total = quantidade * tamanho_individual,
                        margem_limite_inicial = 0,
                        margem_limite_final = tamanho_total - (quantidade_porta_visao * tamanho_individual),
                        fotos_click = function(event) {
                            var $this = $(this),
                                $caixa_atual = $this.parents("li"),
                                $foto_atual = $caixa_atual.find(".img img"),
                                $outras_caixas = $caixas.not($caixa_atual[0]),
                                indice = $caixa_atual.index(),
                                margem_esquerda = cssToInt($lista_caixas.css("margin-left")),
                                indice_relativo,
                                deslocamento_para_esquerda,
                                elementos_escondidos_a_esquerda,
                                posicao_relativa;

                            $fotos.unbind("click");
                            $nomes.unbind("click");

                            indice_relativo = indice + (margem_esquerda / tamanho_individual);

                            elementos_escondidos_a_esquerda = indice - indice_relativo;

                            posicao_relativa = elementos_escondidos_a_esquerda * tamanho_individual;

                            deslocamento_para_esquerda = (indice_relativo + elementos_escondidos_a_esquerda) * tamanho_individual;

                            $outras_caixas.removeClass("active");

                            $foto_atual.addClass("big");

                            $outras_caixas.animate({
                                "opacity": "0"
                            }, {
                                queue: false,
                                duration: duracao_animacao,
                                complete: function() {
                                    var $this = $(this);
                                    $caixa_atual.addClass("absolute").css("left", deslocamento_para_esquerda + "px").animate({
                                        "left": (posicao_relativa) + "px"
                                    }, {
                                        queue: false,
                                        complete: function() {
                                            var $this = $(this);
                                            $this.addClass("active");
                                            $foto_atual.removeClass("big");
                                        }
                                    });
                                }
                            });

                            return false;
                        },
                        nomes_click = function(event) {
                            var $this = $(this),
                                margem_esquerda_antiga = cssToInt($lista_caixas.css("margin-left")),
                                $caixa_atual = $this.parents("li"),
                                indice = $caixa_atual.index(),
                                indice_antigo = $caixas.filter("li.active").index(),
                                margem_mover = (indice - antes_do_meio) * tamanho_individual,
                                posicao_atual,
                                indice_relativo,
                                margem_esquerda;

                            if (indice === indice_antigo) return false;

                            $nomes.unbind("click");

                            if (margem_mover > margem_limite_final) margem_mover = margem_limite_final;
                            if (margem_mover < margem_limite_inicial) margem_mover = margem_limite_inicial;

                            margem_mover = -margem_mover;

                            margem_esquerda = margem_mover;

                            posicao_atual = (tamanho_total - margem_esquerda) - tamanho_total;
                            indice_relativo = indice + (margem_esquerda / tamanho_individual);

                            $lista_caixas.animate({
                                "margin-left": margem_mover + "px"
                            }, {
                                queue: false,
                                duration: duracao_animacao,
                                complete: function() {
                                    var $this = $(this);
                                }
                            });

                            $bar_track.animate({
                                "left": (indice_relativo * tamanho_individual) + "px"
                            }, {
                                queue: false,
                                duration: duracao_animacao,
                                complete: function() {
                                    var $this = $(this);
                                    $nomes.bind("click", nomes_click);
                                }
                            });

                            return false;
                        };

        $nomes.bind("click", nomes_click);

        $fotos.bind("click", fotos_click);

        $botoes_fechar.bind("click", function(event) {
            var $this = $(this),
                            $caixa_atual = $this.parents("li"),
                            $foto_atual = $caixa_atual.find(".img img"),
                            $outras_caixas = $caixas.not($caixa_atual[0]),
                            indice = $caixa_atual.index(),
                            margem_esquerda = cssToInt($lista_caixas.css("margin-left")),
                            indice_relativo,
                            deslocamento_para_esquerda,
                            elementos_escondidos_a_esquerda;

            indice_relativo = indice + (margem_esquerda / tamanho_individual);

            elementos_escondidos_a_esquerda = indice - indice_relativo;

            deslocamento_para_esquerda = (indice_relativo + elementos_escondidos_a_esquerda) * tamanho_individual;

            console.log({
                indice_relativo: indice_relativo,
                elementos_escondidos_a_esquerda: elementos_escondidos_a_esquerda,
                tamanho_individual: tamanho_individual,
                indice: indice
            });

            $foto_atual.addClass("big");

            $caixa_atual.removeClass("active").animate({
                "left": deslocamento_para_esquerda + "px"
            }, {
                queue: false,
                duration: duracao_animacao,
                complete: function() {
                    var $this = $(this);
                    $foto_atual.removeClass("big");
                    $caixa_atual.removeClass("absolute").css("left", "auto");
                    $caixas.removeClass("active").animate({
                        "opacity": "1"
                    }, {
                        queue: false,
                        complete: function() {
                            var $this = $(this);
                            $fotos.bind("click", fotos_click);
                            $nomes.bind("click", nomes_click);
                        }
                    });
                }
            });

            return false;
        });
    });
};

$.fn.exibirConselhos = function() {
    $(this).each(function(index, element) {
        var $this = $(this),
                        duracao_animacao = 200,
                        $box_conselho = $this,
                        $textos = $box_conselho.find("div.textos").children("p"),
                        $view_port = $box_conselho.find("div.nomes"),
                        $lista_nomes = $view_port.find("ul"),
                        $nomes = $lista_nomes.find("li"),
                        $bar_track = $box_conselho.find("div.bar div.track"),
                        quantidade = $nomes.size(),
                        tamanho_individual = $nomes.eq(0).outerWidth(true),
                        tamanho_texto = $textos.eq(0).outerWidth(true),
                        quantidade_porta_visao = Math.ceil($view_port.width() / tamanho_individual),
                        antes_do_meio = Math.floor(quantidade_porta_visao / 2),
                        tamanho_total = quantidade * tamanho_individual,
                        margem_limite_inicial = 0,
                        margem_limite_final = tamanho_total - (quantidade_porta_visao * tamanho_individual);

        $nomes.bind("click", function(event) {
            var $this = $(this),
                            margem_esquerda_antiga = cssToInt($lista_nomes.css("margin-left")),
                            $nome_atual = $this,
                            indice = $nome_atual.index(),
                            indice_antigo = $nomes.filter("li:has(a.active)").index(),
                            margem_mover = (indice - antes_do_meio) * tamanho_individual,
                            posicao_atual,
                            indice_relativo,
                            margem_esquerda;

            if (indice === indice_antigo) return false;

            if (margem_mover > margem_limite_final) margem_mover = margem_limite_final;
            if (margem_mover < margem_limite_inicial) margem_mover = margem_limite_inicial;

            margem_mover = -margem_mover;

            margem_esquerda = margem_mover;

            posicao_atual = (tamanho_total - margem_esquerda) - tamanho_total;
            indice_relativo = indice + (margem_esquerda / tamanho_individual);

            $lista_nomes.animate({
                "margin-left": margem_mover + "px"
            }, {
                queue: false,
                duration: duracao_animacao,
                complete: function() {
                    var $this = $(this);
                    $textos.removeClass("active");
                    $textos.eq(indice).addClass("active");
                }
            });

            $bar_track.animate({
                "left": (indice_relativo * tamanho_individual) + "px"
            }, {
                queue: false,
                duration: duracao_animacao,
                complete: function() {
                    var $this = $(this);
                }
            });

            $nomes.find("a").removeClass("active");
            $this.find("a").addClass("active");

            return false;
        });

    });
};

$(document).ready(function() {
    $("div.conselho-nav ul.menu-conselho li").width($("div.conselho-nav ul.menu-conselho li").getWider().width());
    $("div.valores-fe-nav ul li").width($("div.valores-fe-nav ul li").getWider().width());
    $("div.caixa.home-box-content:has(div.linha-tempo-main)").linhaDoTempo();
    $("div.caixa.home-box-content:has(div.valores-fe-main)").linhaDoTempo();
    $("div.caixa.box-equipe:has(div.info)").rotacaoPerfis();
    $("div.conselho.caixa").exibirConselhos();
});

$.fn.getWider = function() {
    var $wider = $(this).eq(0);

    $(this).each(function(index, element) {
        var $this = $(this),
                            width = $this.width();
        if (width > $wider.width()) {
            $wider = $this;
        }
    });

    return $wider;
};

function cssToInt(css) {
    if (isNaN(parseInt(css))) {
        return paseInt("0");
    } else {
        return parseInt(css);
    }
}

function email_valido(email) { return email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); }

function Verificar_Email_Repetido(Email, callback) {
    $.ajax({
        url: webpath + "Util/VerificarEmailRepetido",
        type: "POST",
        data: {
            Email: Email
        },
        success: function(data, status, jxhr) {
            (typeof callback === "function" && callback.call(this, data));
        },
        error: function(jxhr, status, error) {
            console.log(jxhr);
        }
    });
}

(function($)
{
	$(document).ready(function()
	{
		$(".cadastro-minha-fe fieldset").data("habilitado", false);

		$(".cadastro-minha-fe fieldset:first").data("habilitado", true);

		$(".cadastro-minha-fe fieldset").hide();
		$(".cadastro-minha-fe fieldset:first").show();

		$(".cadastro-minha-fe .btn.passo-1").click(function()
		{
			var $this = $(this);

			Verificar_Email_Repetido($("#Email").val(), function(repetido)
			{
				$("#Email").removeClass("erro");

				if (ValidaPasso1() && repetido !== true)
				{
					$(".nav-cadastro li").removeClass("active");
					$(".nav-cadastro li.it-2").addClass("active");

					$(".cadastro-minha-fe fieldset").hide();
					$(".cadastro-minha-fe fieldset#passo-2").show();

					$(".cadastro-minha-fe fieldset#passo-2").data("habilitado", true);
				}

				if (repetido === true)
				{
					$("#Email").addClass("erro");
					alert("O e-mail digitado já está cadastrado.");
				}
			});

			return false;
		});



		$(".cadastro-minha-fe .btn.passo-2").click(function()
		{
			if (ValidaPasso2())
			{
				$(".nav-cadastro li").removeClass("active");
				$(".nav-cadastro li.it-3").addClass("active");

				$(".cadastro-minha-fe fieldset").hide();
				$(".cadastro-minha-fe fieldset#passo-3").show();

				$(".cadastro-minha-fe fieldset#passo-3").data("habilitado", true);
			}

			return false;
		});



		$(".cadastro-minha-fe .btn.passo-3").click(function()
		{
			return ValidaPasso3();
		});

		$(".nav-cadastro li").click(function()
		{
			var passo = $(".nav-cadastro li").index(this);
			var passoAnterior = $(".nav-cadastro li").index($(".nav-cadastro li.active"));

			if ($(".cadastro-minha-fe fieldset").eq(passo).data("habilitado") === true)
			{
				switch (passoAnterior)
				{
					case 0:
						Verificar_Email_Repetido($("#Email").val(), function(repetido)
						{
							if (repetido === true || $("#Email").hasClass("erro"))
							{
								$("#Email").addClass("erro");
							}
							else
							{
								$("#Email").removeClass("erro");
							}

							if (!ValidaPasso1() || repetido === true)
							{
								return false;
							}
						});

						break;
					case 1:
						if (!ValidaPasso2())
						{
							return false;
						}

						break;
					case 2:
						if (!ValidaPasso3())
						{
							return false;
						}

						break;
				}

				$(".nav-cadastro li").removeClass("active");
				$(this).addClass("active");

				$(".cadastro-minha-fe fieldset").hide();
				$(".cadastro-minha-fe fieldset").eq(passo).show();
			}
		});
	});
} (jQuery));

function ValidaPasso1()
{
	var ret = true;

	$("#Nome").removeClass("erro");
	$("#Senha").removeClass("erro");
	$("#SenhaConfirmacao").removeClass("erro");
	$("#DataNascimento").removeClass("erro");
	$("#Sexo").parent().find("div.rad").removeClass("erro");
	$("#Email").removeClass("erro");
	$("#Pais").removeClass("erro");
	$("#Estado").removeClass("erro");
	$("#Cidade").removeClass("erro");

	if ($("#Nome").val().length <= 0)
	{
		$("#Nome").addClass("erro");
		ret = false;
	}
	if ($("#Senha").val().length <= 0)
	{
		$("#Senha").addClass("erro");
		ret = false;
	}
	if ($("#SenhaConfirmacao").val().length <= 0)
	{
		$("#SenhaConfirmacao").addClass("erro");
		ret = false;
	}
	if ($("#Senha").val().length > 0 && $("#SenhaConfirmacao").val().length > 0)
	{
		if ($("#Senha").val() != $("#SenhaConfirmacao").val())
		{
			ret = false;
			$("#Senha").addClass("erro");
			$("#SenhaConfirmacao").addClass("erro");
		}
	}
	if ($("#DataNascimento").val().length <= 0)
	{
		$("#DataNascimento").addClass("erro");
		ret = false;
	}
	else if (!data_valida($("#DataNascimento").val()))
	{
		$("#DataNascimento").addClass("erro");
		ret = false;
	}

	if ($("#Sexo").val().length <= 0)
	{
		$("#Sexo").parent().find("div.rad").addClass("erro");
		ret = false;
	}
	if ($("#Email").val().length <= 0)
	{
		$("#Email").addClass("erro");
		ret = false;
	} else if (!email_valido($("#Email").val()))
	{
		$("#Email").addClass("erro");
		ret = false;
	}

	if ($("#Estado").val().length <= 0)
	{
		$("#Estado").addClass("erro");
		ret = false;
	}

	return ret;
}

function ValidaPasso2() {
    var ret = true;

    $("#Empresa").removeClass("erro");
    $("#Segmento").removeClass("erro");
    $("#Cargo").removeClass("erro");
    $("#DtInicio").removeClass("erro");
    $("#DtFim").removeClass("erro");

    if ($("#Empresa").val().length <= 0) {
        $("#Empresa").addClass("erro");
        ret = false;
    }
    if ($("#Segmento").val().length <= 0) {
        $("#Segmento").addClass("erro");
        ret = false;
    }
    if ($("#Cargo").val().length <= 0) {
        $("#Cargo").addClass("erro");
        ret = false;
    }
    if ($("#DtInicio").val().length <= 0) {
        $("#DtInicio").addClass("erro");
        ret = false;
    }
    else if (!data_valida('01/' + $("#DtInicio").val())) {
        $("#DtInicio").addClass("erro");
        ret = false;
    }

    if ($("#DtFim").val().length <= 0) {
        $("#DtFim").addClass("erro");
        ret = false;
    }
    else if (!data_valida('01/' + $("#DtFim").val())) {
        $("#DtFim").addClass("erro");
        ret = false;
    }

    return ret;
}
function ValidaPasso3() {
    var ret = true;
    $("#Formacao").removeClass("erro");
    $("#InstEnsino").removeClass("erro");
    $("#Curso").removeClass("erro");
    $("#DtFimCurso").removeClass("erro");
    $("#DtInicioCurso").removeClass("erro");

    if ($("#Formacao").val().length <= 0) {
        $("#Formacao").addClass("erro");
        ret = false;
    }
    if ($("#InstEnsino").val().length <= 0) {
        $("#InstEnsino").addClass("erro");
        ret = false;
    }
    if ($("#Curso").val().length <= 0) {
        $("#Curso").addClass("erro");
        ret = false;
    }
    if ($("#DtInicioCurso").val().length <= 0) {
        $("#DtInicioCurso").addClass("erro");
        ret = false;
    } else if (!data_valida('01/' + $("#DtInicioCurso").val())) {
        $("#DtInicioCurso").addClass("erro");
        ret = false;
    }
    if ($("#DtFimCurso").val().length <= 0) {
        $("#DtFimCurso").addClass("erro");
        ret = false;
    } else if (!data_valida('01/' + $("#DtFimCurso").val())) {
        $("#DtFimCurso").addClass("erro");
        ret = false;
    }

    return ret;
}


function ValidaData(data) {
    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    if ((data.match(expReg)) && (data != '')) {
        var dia = data.substring(0, 2);
        var mes = data.substring(3, 5);
        var ano = data.substring(6, 10);
        if (mes == 4 || mes == 6 || mes == 9 || mes == 11 && dia > 30) {
            return false;
        } else {
            if (ano % 4 != 0 && mes == 2 && dia > 28) {
                return false;
            } else {
                if (ano % 4 == 0 && mes == 2 && dia > 29) {
                    return false;
                }
                return true;
            }
        }
    }
    return false;
}

(function(global, $) {
    global.trendi = {
        login: function(user, password, remember, callback) {
            $.ajax({
                url: webpath + "Util/Login",
                type: "POST",
                data: {
                    email: user,
                    senha: password,
                    lembrar: remember
                },
                success: function(data, status, jxhr) {
                    (typeof callback === "function" && callback.call(this, data));
                },
                error: function(jxhr, status, error) {
                    console.log(jxhr);
                }
            });
        },
        logout: function(callback) {
            $.ajax({
                url: webpath + "Util/Logout",
                type: "POST",
                success: function(data, status, jxhr) {
                    (typeof callback === "function" && callback.call(this, data));
                },
                error: function(jxhr, status, error) {
                    console.log(jxhr);
                }
            });
        },
        email_valido: function(email) {
            return email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
        }
    };
} (this, jQuery));

function gerarCalendario(ano, mes) {
    var inicio = new Date(ano, mes, 1);
    var fim = new Date(ano, mes + 1, 0);
    var dayOfWeek = inicio.getDay();
    var hoje = new Date();
    var meses = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
    var contador = 0;

    var calendario = '<table class="calendar-small" cellspacing="0"><thead><td>D</td><td>S</td><td>T</td><td>Q</td><td>Q</td><td>S</td><td>S</td></tr></thead><tr>';

    if (dayOfWeek > 0) {
        for (var i = 0; i < dayOfWeek; i++) {
            calendario += '<td><a class="none" href="javascript:void(0);" title="">&nbsp;</a></td>';
            contador++;
        }
    }


    for (var i = 1; i < fim.getDate() + 1; i++) {
        var tmp = webpath + 'Util/CalendarioData/?data=' + inicio.getFullYear() + '-' + (inicio.getMonth() + 1) + '-' + i;
        if (hoje.getFullYear() == inicio.getFullYear() && hoje.getMonth() == inicio.getMonth() && hoje.getDate() == i)
            calendario += '<td><a href="' + tmp + '" class="active" title="' + i + '">' + i + '</a></td>';
        else
            calendario += '<td><a href="' + tmp + '" title="' + i + '">' + i + '</a></td>';

        contador++;
        if (contador > 6) {
            calendario += '</tr><tr>';
            contador = 0;
        }
    }

    if (contador != 0) {
        for (var i = contador; i < 7; i++) {
            calendario += '<td><a class="none" href="javascript:void(0);" title="">&nbsp;</a></td>';
        }
    }

    calendario += '</table>';

    $('div.small-calendario h4').html(meses[inicio.getMonth()] + ' de ' + inicio.getFullYear());
    $('#MiniCalendario').html(calendario);
    anoA = inicio.getFullYear();
    mesA = inicio.getMonth();
}

function data_valida(ano, mes, dia) {

    if (typeof mes === "undefined" && typeof dia === "undefined") {
        dia = ano.split("/")[0];
        mes = ano.split("/")[1];
        ano = ano.split("/")[2];
    }

    if (parseInt("0" + ano, 10) === 0 || isNaN(parseInt("0" + ano, 10))) {
        return false;
    }

    if (parseInt("0" + mes, 10) === 0 || isNaN(parseInt("0" + mes, 10))) {
        return false;
    }

    if (parseInt("0" + dia, 10) === 0 || isNaN(parseInt("0" + dia, 10))) {
        return false;
    }

    if (isNaN(new Date(
            parseInt("0" + ano, 10),
            parseInt("0" + mes, 10) - 1,
            parseInt("0" + dia, 10)).getTime()
    )) {
        return false;
    }

    return true;
}

