/*
 * 
 * Scripts gerais do site "Agora Sistema de Ensino" by PubDesign
 *
*/

/* jCarousel initCallback */
function initCallback(carousel) {      
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

      $('#next').bind('click', function() {
          carousel.next();
          return false;
      });

      $('#prev').bind('click', function() {
          carousel.prev();
          return false;
      });
    
};

$(document).ready(function () {

    /* esconde e mostra texto dos inputs de busca e login */
    if ($.hoverInputText) {
        $("#forms input[type='text']").hoverInputText();
    }


    /* barras de rolagem da home */

    if ($.jScrollPane) {
        $('.add_scroll').jScrollPane({ scrollbarWidth: 14, scrollbarMargin: 0 });
    }


    /* carousel home */
    if ($.jcarousel) {
        $("#slides_content").jcarousel({
            initCallback: initCallback,
            auto: 5,
            scroll: 4,
            wrap: 'last',
            buttonNextHTML: null,
            buttonPrevHTML: null,
            animation: 1000
        });
    }


    /*  nav ações e estilos */

    $('.nav_item').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item2').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item2').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item2').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item3').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item3').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item3').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item4').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item4').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item4').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item5').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item5').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item5').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item6').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item6').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item6').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });
    $('.nav_item7').find(' a:first').bind('mouseover', function () {
        $(this).addClass($(this).attr('className').split(' ')[0] + '_hover');
    });

    $('.nav_item7').find(' a:first').bind('mouseout', function () {
        if (!$(this).hasClass('clicked')) {
            $(this).removeClass($(this).attr('className').split(' ')[0] + '_hover');
        }
    });

    $('.nav_item7').find('a:first').bind('click', function () {
        if (!$(this).hasClass('clicked') && $(this).next().length > 0) {
            $(this).next().slideDown();
            $(this).addClass('clicked');
            return false;
        } else if ($(this).hasClass('clicked')) {
            $(this).next().slideUp();
            $(this).removeClass('clicked');
            return false;
        }
    });


    $('.nav_sub_item span').parent('a').bind('click', function () {
        if (!$(this).hasClass('over') && $(this).next().length > 0) {
            $(this).next('ul').slideDown();
            $(this).addClass('over');
            return false;
        } else if ($(this).hasClass('over')) {
            $(this).next('ul').slideUp();
            $(this).removeClass('over');
            return false;
        }
    });


    /* @css fixes */

    // slides
    $('.slide_item').hover(function () {
        $(this).find('p a').css('color', '#253442');
    }, function () {
        $(this).find('p a').css('color', '#787878');
    });

    //Lista Alunos

    $("#lista_alunos .more, #interna .more").each(function (index) {
        $(this).height($(this).parent().parent().innerHeight());
    });


    $("#lista_alunos .more, #interna .more").hover(function (event) {
        $(this).parent().parent().addClass('article_hover');
    },
    function () {
        $(this).parent().parent().removeClass('article_hover');
    });

    // scrollbars
    function track_hover() {
        $('.jScrollPaneDrag').addClass('jScrollPaneDragHover');
        $('.jScrollPaneDragTop').addClass('jScrollPaneDragTopHover');
        $('.jScrollPaneDragBottom').addClass('jScrollPaneDragBottomHover');
    }

    function track_out() {
        $('.jScrollPaneDrag').removeClass('jScrollPaneDragHover');
        $('.jScrollPaneDragTop').removeClass('jScrollPaneDragTopHover');
        $('.jScrollPaneDragBottom').removeClass('jScrollPaneDragBottomHover');
    }

    $('.jScrollPaneDrag').hover(function () {
        track_hover();
    }, function () {
        track_out();
    });

    /* flash content */
    /*
    $(".home #banner_wrapper").flash({ swf: 'media/swf/banner_home.swf',
        width: '751',
        height: '210',
        params: { wmode: 'transparent' }
    });
    */
});
