$(document).ready(function(){

    //Carrossel Anuncios Boletim
	$('.anuncios').cycle({ 
	    fx:     'fade', 
	    speed:   600, 
	    timeout: 4000
	});

    //Controle do Banner
//    $("#banner a, #banner").click( function(){
 //       $('#banner').css('display','none'); 
  //  });

    //Controle das galerias e videos do boletim
    $(".pool_controls span").click( function(){

        elem = $(this).parent('div').parent('div').attr('class').split(' ');
        frameset = '.frame_'+elem[1].substring( elem[1].length-1, elem[1].length );

        if( $(this).attr('class') == 'pool_video' ){
         if( $('.video').is(':hidden') ){
            $('.video').removeClass('hide');
            $( frameset ).removeClass('hide');
            $( frameset ).addClass('show');
            $('.carrossel').addClass('hide');
         }           
        }else{
            $('.video').addClass('hide');
            $( frameset ).removeClass('show');
            $( frameset ).addClass('hide');
            $('.carrossel').removeClass('hide');
        }

    });

    //Carrossel Boletim
	$('.carrossel').cycle({ 
	    fx:     'scrollLeft', 
	    speed:   300, 
	    timeout: 3000,
        prev: '.ante',
        next: '.prox'
	});

    function HideAll () {
        for(x = 1; x <= $(".video").length; x++) $( ".video" ).addClass('hide');
        for(x = 2; x <= $(".conteudo > div.pool_beach ").length; x++) $( ".chain_" + x ).addClass('hide');
    }

    HideAll();

    $("#pooler_beach_control").click( function(){

        beach_qtd = $(".conteudo > div.pool_beach ").length;

        var toshow = 0;

        for(x = 1; x <= beach_qtd; x++){

           if( $(" .chain_" + x).is(':visible') ){
              visivel = x;              
           }
            
           if( visivel == beach_qtd){ 
              toshow = 1; 
           }
        }

        if( toshow == 0 ){ toshow = visivel+1;};

        showHide( toshow, visivel );

    });

    function showHide( chain_show, chain_hide ){
        $( ".frame_" + chain_hide ).removeClass('show');
        $( ".frame_" + chain_hide ).addClass('hide');

        if( $('.video').is(':visible') ){//Video hide
            $( ".frame_" + chain_show ).removeClass('hide');
            $( ".frame_" + chain_show ).addClass('show');
        }

        $( '.chain_' + chain_hide ).stop().fadeOut(500, function(){ 
            $( ".chain_" + chain_hide ).addClass('hide');
            $( ".chain_" + chain_show ).removeClass('hide');
            $( ".chain_" + chain_show ).stop().fadeIn(500);
        });
    }
});

