﻿(function ($) {
    $.fn.hypeFunctions = function (status) {

        // COMPONENTES DE TELA
        var _root = $('#main');
        var _modalWrapp = _root.find('.modal-wrapp');
        var _palestrantes = _root.find('.palestrantes-wrapp');
        var _menu = _root.find('#menu-top');

        // VARIÁVEIS DE CONFIGURAÇÃO
        var pageLoaded = false;
        var movimentoAtivo = false;
        var menuAtivo;
        var pageWidth;
        var pageHeight;

        // LISTENER DE RESIZE NO BROWSER
        $(window).resize(function () {
            pageWidth = $(window).width();
            pageHeight = $(window).height();
        });

        function configuraTelaByStatus(_status) {

            var posXLogo;

            if (status != "False") {
                _root.find('iframe#frmCadastro').height(320);
                posXLogo = 55;
            }
            else {
                var _target = _root.find('#modal-welcome');
                //var _target = _root.find('#modal-encerramento');
                showModal(_target);
                posXLogo = 30;
            }

            _logo.find('img').last().one('load', function () {
                _logo.animate({ top: posXLogo }, "medium", "easeOutExpo");
            }).each(function () { if (this.complete) $(this).load(); });

        }

        inicializaEstrutura = function () {
            // TAMANHO DO STAGE
            pageWidth = $(window).width();
            pageHeight = $(window).height();

            pageLoaded = true;
        }

        // INICIALIZAÇÃO DO COMPONENTE
        function init() {
			
			_root.find('#bt-en').fadeTo('fast', 0.3);

        };
        init();

		// ÂNCORA PARA O TOPO
		$('.back-top-bar a').click(function () {
     		$('html,body').animate({scrollTop:0 }, 'medium');
			return false;
        });

		// BOTÃO INSCREVA-SE
		_root.find('.bt-inscreva-se').mouseenter(function () {
			//$(this).find('img').stop();
			//$(this).find('img').animate({ marginTop: -30 }, "fast", "easeOutExpo", function () { });
        });

		_root.find('.bt-inscreva-se').mouseleave(function () {
			//$(this).find('img').stop();
			//$(this).find('img').animate({ marginTop: 0 }, "medium", "easeOutBounce", function () { });
        });

        /************************************************************************************/
        /*[ MENU PRINCIPAL ]*****************************************************************/

        _menu.find('li').mouseenter(function () {
            if (!$(this).hasClass('ativo')) {
                $(this).find('a').animate({ marginRight: 15 }, "fast", "easeOutExpo", function () { });
            }
        });

        _menu.find('li').mouseleave(function () {
            $(this).find('a').animate({ marginRight: 0 }, "fast", "easeOutExpo", function () { });
        });
		

        /************************************************************************************/
        /*[ CARROSSEL DE PALESTRANTES ]******************************************************/

        var palestrantesIndice = 0;
        var cursorOut = false;

        _palestrantes.find('.gallery-nav .nav-bt').click(function () {
            if (!movimentoAtivo) {
                movimentoAtivo = true;

                var palestrantesPaginas = _palestrantes.find('.gallery-left .scroll-content ul').length;
                var distancia = _palestrantes.find('.gallery-left .scroll-content ul').width();
                var sentido = $(this).attr('id');
                var posFinal = 0;

                switch (sentido) {
                    case "prev":
                        if (palestrantesIndice > 0)
                            palestrantesIndice--;
                        break;
                    case "next":
                        if (palestrantesIndice < (palestrantesPaginas - 1))
                            palestrantesIndice++;
                        break;
                }

                posFinal = (palestrantesIndice * distancia) * -1;
                _palestrantes.find('li.pagina span').html((palestrantesIndice + 1) + " de " + palestrantesPaginas);

                _palestrantes.find('.gallery-left .scroll-content').animate({ left: posFinal }, "medium", "easeInOutExpo", function () {
                    movimentoAtivo = false;
                });
            }
        });

        _palestrantes.find('.gallery-left .scroll-content ul img').mouseenter(function () {

            cursorOut = false;

            if (!movimentoAtivo) {
                movimentoAtivo = true;

                var _this = $(this);
                _palestrantes.find('.gallery-left .scroll-content ul img').each(function () {
                    if ($(this).attr('rel') != _this.attr('rel')) {
                        $(this).fadeTo('fast', 0.4, function () {
                            movimentoAtivo = false;
                            if (cursorOut) {
                                clearCarrossel();
                            }
                        });
                    }
                });
            }

            _palestrantes.find('.gallery-right ul li#' + _this.attr('rel')).addClass('ativo');

        });

        _palestrantes.find('.gallery-left .scroll-content ul img').mouseleave(function () {
            cursorOut = true;
            clearCarrossel();
        });

        _palestrantes.find('.gallery-left .scroll-content ul img').mouseout(function () {
            cursorOut = true;
            clearCarrossel();
        });

        function clearCarrossel() {
            _palestrantes.find('.gallery-left .scroll-content ul img').css({ 'opacity': '1' });
            _palestrantes.find('.gallery-right ul li').removeClass('ativo');
        }

    };
})(jQuery);
