jQuery.noConflict();

jQuery(document).ready(function() {

    if(jQuery.cookie("background") != '') {
        jQuery('body').removeAttr('class');
        jQuery('body').addClass(jQuery.cookie("background"));
    }

    //jQuery('#frmSearch').inputHintOverlay(10, 5);
    // buscador
    jQuery('#frmSearch input[type="text"]').focus(function() {
        if(jQuery(this).val() == 'Realize sua busca') {
            jQuery(this).val('');
        }
    });
    jQuery('#frmSearch input[type="text"]').blur(function() {
        if(jQuery(this).val() == '') {
            jQuery(this).val('Realize sua busca');
        }
    });

    // change bg
    jQuery('#change_background li a').click(function() {
        jQuery('body').removeAttr('class');
        jQuery('body').addClass(jQuery(this).attr('class'));

        jQuery.cookie("background", jQuery(this).attr('class'));

        return false;
    });

    // accordion that open many items at once
    jQuery('#accordion li a.head').click(function() {
        jQuery(this).next().slideToggle('slow');
        jQuery(this).toggleClass('active');

        return false;
    }).next().hide();
    jQuery('#accordion li:first a.head').addClass('acitve');
    jQuery('#accordion li:first a.head').next().slideToggle('slow');

    // accordion-internal that open many items at once
    jQuery('#accordion-internal li a.head').click(function() {
        jQuery(this).next().slideToggle('slow');
        jQuery(this).toggleClass('active');

        return false;
    }).next().hide();

    // banner
    var sudoSlider = jQuery("#slider").sudoSlider({
        continuous: true,
        controlsShow: false,
        customLink: '#controls a',
        speed: 800,
        auto: true,
        pause: 5000
    });
    jQuery('#slider ul li img').mouseover(function() {
        if(jQuery(this).attr('title').length > 1)
        {
            jQuery('#controls #title').html(jQuery(this).attr('title'));
        }

        sudoSlider.adjust(50000);
    });
    jQuery('#slider ul li img').mouseout(function() {
        jQuery('#controls #title').html('&nbsp;');
        sudoSlider.adjust(5000);
    });

    // featured_news
    jQuery('#news_images li:first img').show(); // show first
    jQuery('#news_titles ul li').mouseover(function() {
        jQuery('#news_images li img').hide();
        rel = eval(jQuery(this).attr('rel') + "-" + 1);
        jQuery('#news_images li:eq('+rel+') img').show();
    });

    // videos carousel
    jQuery('#carousel-videos').jcarousel({
        visible: 4,
        scroll: 4
    });

    // tabs events and agend
    jQuery('#tabs li a').click(function(e) {
        e.preventDefault();
        rel = jQuery(this).attr('rel');

        if(jQuery('#'+rel).css('display') == 'none') {
            jQuery('.content-tab').hide();
            jQuery('#tabs li a').removeClass('active');
            jQuery(this).addClass('active');
            jQuery('#'+rel).fadeIn('slow');
        }

        return false;
    }).next().hide();

    // informativos
    jQuery("#informativos-slider").sudoSlider({
        continuous:   true,
        controlsShow: false,
        customLink:   '#informativos-controls a'
    });

    jQuery('a.showPlayer').click(function() {
        // add overlay
        jQuery("body").append("<div id='overlayPlayer'></div>");

        // ajust height
        jQuery("#overlayPlayer").height(jQuery(document).height());

        // show player
        player = jQuery(this).parent().parent().children('.player');
        iframe = jQuery(jQuery(this).parent().parent().children('iframe'));

        jQuery(player).show();

        // hide overlay and player
        jQuery('.cerrar').click(function() {
            jQuery(player).hide();
            jQuery(iframe).hide();
            jQuery('#overlayPlayer').remove();
        });

        return false;
    });

    jQuery('.popup .close').click(function() {
        jQuery('.popup').hide();
    });
});
