//REDRAW ELEMENTS
function redrawElement(selector) {
    $(selector).addClass("redraw").removeClass("redraw");
}

//SELECT NEWS FUNCTION
function selectNews(num) {
    var foto = news[num];

    var share = "<br/><div class=\"addthis_toolbox\"> <a href=\"#\" class=\"addthis_button_compact addthis-news\" style=\"float:left;\" addthis:url=\"\" addthis:title=\"\" addthis:description=\"\"> Compartilhe </a> <a class=\"addthis_button_facebook_like\" fb:like:layout=\"button_count\"></a></div>";

    $('#image_small').attr('src', foto.img);
    $('#legend').html(foto.legenda);
    $('#date').html(foto.date);
    $('#title').html(foto.title);
    $('#content').html(foto.content + share);

      var url = 'http://www.raulboesel.com.br/home/senderFB/'+foto.ID;
            //var  url = null;
            var title = foto.title;
            var caption = foto.caption;

    $('.addthis-news').attr('addthis:url',url);
    $('.addthis-news').attr('addthis:title', title);
    $('.addthis-news').attr('addthis:description', caption);
            
            

    var newHash = '#!/dj/aba-news';
    window.location.hash = newHash+'/'+foto.ID; 
}

//SELECT PHOTOS FUNCTION
function selectPhotos(num){
    var foto = fotos[num];
    $('#large-fotos').attr('src', foto.img);
    $('#legend-ft').empty();
    $('#legend-ft').html(foto.legend);
    $('#link-foto').attr('href', foto.imglarge);
    $('#link-foto').attr('pos', num);
    $('#link-foto').attr('title', foto.legend);
}

//FUNCTION PLAY THUMB VIDEOS
function playThumbVideo(url){

    var html  = '';

    html += '<object width="392" height="272">';
    html += '<param name="movie" value="'+url+'"></param>';
    html += '<param name="autoplay" value="1">';
    html += '<param name="wmode" value="transparent">';
    html += '<param allowfullscreen="true" name="wmode" value="transparent"></param>';
    html += '<embed src="'+url+'" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" width="392" height="272" ></embed>';
    html += '</object>';
    return html;
}

//CARROSEL VIDEOS
function carroselVideos(){
    $(".limites").carouFredSel({
        delay:10,
        circular:true,
        auto: false,
        items: 4,
        direction: "down",
        scroll: 1

    });

    $(".limites").parent().css('height','200px');
    $(".limites").css('height','200px');

    $("#videos-prev").live('click',function(){
        $(".limites").trigger("prev",1);
        return false;
    });

    $("#videos-next").live('click',function(){
        $(".limites").trigger("next",1);
        return false;
    });

//console.log('Carregou Corretamente Videos' );
}

function carroselFotos(){
    $(".limites-fotos").carouFredSel({
        delay:10,
        circular:true,
        auto: false,
        items: 4,
        direction: "down",
        scroll: 1

    });

    $(".limites-fotos").parent().css('height','200px');
    $(".limites-fotos").css('height','200px');

    $("#fotos-prev").live('click',function(){
        $(".limites-fotos").trigger("prev",1);
        return false;
    });

    $("#fotos-next").live('click',function(){
        $(".limites-fotos").trigger("next",1);
        return false;
    });
}

//SELECT PHOTOS PILOT
function selectPhotosPilot(thumb,legend,path,num){    
    $('#large-fotos').attr('src', thumb);   
    $('#legend-ft').html(legend);
    $('#link-foto').attr('href', path);
    $('#link-foto').attr('pos', num);
    $('#link-foto').attr('title',legend);    
    return false;
}

function checkHomeNews(currentOpenTabID){
    if(currentOpenTabID == 'aba-news'){
        $('#open-title').fadeOut(200);
        $('#closed-title' ).fadeIn(200);

    }else{
        $('#closed-title' ).fadeOut(200);
        $('#open-title').fadeIn(200);

    }
}

function setLoading(div){
    $(div).html('<span class=\'img-loading\'> Carregando... </span>').fadeIn();
}

function setIdle(div){
    $(div).fadeOut(200);
}

function setLoadingVideos(div){
    $(div).html('<span class=\'img-loading-videos\'> </span>').fadeIn();
}

function Paginate_Ajax(url,page){
    $.post(url, {
        page: page
    }, function(data){
        $("#aba-agenda").html('');
        $("#aba-agenda").html(data);  
        $('.flyer').fancybox();
    });
}

function viewAllNews() {
    $("#loadnews").html('');
    $("#loadnews").load('home/news_view_all');
}

function buscaLive(){
    
    //addthis.counter("#atcounter");

    $("#more_news").live('click', function(){
        return false;
    });
    
    $('#busca').live('submit', function(){

        clickedButton = $('#aba-news');
        var tabID = $(clickedButton).attr('tabID');

        if(currentOpenTab != null && tabID != currentOpenTabID) {
            $(currentOpenTab).slideUp('slow');
        }

        $('#aba-news').slideDown('slow');
        $('.tabLink').removeClass('active');
        $('#aba-news').addClass('active');

        currentOpenTab = $('#aba-news');
        currentOpenTabID = tabID;

        $("#loadnews").html('');

        $.post('home/buscar', {
            search: $('#search').val()
        }, function(data){
            $('#loadnews').html(data);
        });

    });
}

function activeBio(){
    $('#aba-biografia article').jScrollPane({            
        showArrows: true,
        autoReinitialise: true
    });     
}

function validaForm(){
    //Validate contact form
    $("#contact").validate();
    //Hidden sucess message
    $('.sucess-contact').fadeOut(5000);
}

function validaFormPressKit(){
    //Validate contact form
    $("#contact-p").validate();
    //Hidden sucess message
    $('.sucess-contact').fadeOut(5000);
}



function loadVideoPhotos(){
    
    $('.thumbVideo').live('click', function() {
        setLoadingVideos('.loadingBasic');
        var url = $(this).attr('href');
        $("#media").attr('src',url).fadeIn('slow');
        setIdle('.loadingBasic');
        return false;
    });
        
    $('#link-foto').click(function(){
        var pos = $('#link-foto').attr('pos');
        $.fancybox(fotos2,{
            type  : 'image',
            index: pos,
            padding: 0
        });
    })

    carroselFotos();
    carroselVideos();
    selectPhotos(0);
}
function habilitaScrool(){
        $('#aba-carreira article').jScrollPane({
        showArrows: true,
        autoReinitialise: true
    });
}

function linkFoto(){
        $('#link-foto').click(function(){
        var pos = $('#link-foto').attr('pos');
        $.fancybox(gallery_photos,{
            type  : 'image',
            index: pos,
            padding: 0
        });
    });
}
function LoadCarreira(){
    
    var scriptContents = $('#scriptLoad_galleryPhotos').html();
    eval(scriptContents);
    
    habilitaScrool();

    linkFoto();

    $('.exibeGaleria').live('click', function(){
        var id = $(this).attr('galeryID');
        $('.loading').ajaxStart(function(){
            $('.loading').show();
        });
        $('.loading').ajaxStop(function(){
            $('.loading').hide();
        });

        $.post('home/listGalleryPiloto', {
            id: id
        }, function(data){
            $('#replaceGalery').html(data);
            
            var scriptContents = $('#scriptLoad_galleryPhotos').html();
            eval(scriptContents);
                
            $('#link-foto').click(function(){
                var pos = $('#link-foto').attr('pos');
                $.fancybox(gallery_photos,{
                    type  : 'image',
                    index: pos,
                    padding: 0
                });
            });
                   
           habilitaScrool();
           linkFoto();

            carroselFotos();

        });       
        return false;
    });


}

function verifyBrowser(){
      if($.browser.version == "7.0"){
            $('#aba-video-fotos ul .caroufredsel_wrapper').css({"margin-left":"0"});
            $('#aba-video-fotos ul .caroufredsel_wrapper .limites-fotos').css({"width":"50px !important"});
        }    
}


