(function($) {
    var aretha = {
        init : function() {
            $("a[rel=external]").attr("target", "_blank");
            
            $("#container").fadeIn(800);
                
            charInit = location.href.lastIndexOf("/")+1;
            charEnd = (location.href.lastIndexOf(".php")+4) - charInit;
            $("nav.menu ul li a[href='"+location.href.substr(charInit,charEnd)+"']").addClass("selected");
        },
        
        showcase : function() {

            //carregar primeiro item da vitrine
            $("#showcase_1").fadeIn(500);
            
            //total de itens
            countShowcase = $("#banner").find(".showcase").size();
            
            //item que está sendo exibindo
            currentShowcase = 1;            
            
            
            //exibir próximo item
            $("#next").bind("click", function() {
                
                //ocultar todos os itens
                $("#banner").find(".showcase").each(function(){
                    $(".showcase").css("display", "none");  
                });
                
                currentShowcase++;
                
                if(currentShowcase > countShowcase){
                    currentShowcase = 1;
                }   
                
                $("#showcase_"+currentShowcase).fadeIn(500);                
            });
            
            
            //exibir item anterior
            $("#prev").bind("click", function() {
                
                //ocultar todos os itens
                $("#banner").find(".showcase").each(function(){
                    $(".showcase").css("display", "none");  
                });
                
                currentShowcase--;
                
                if(currentShowcase < 1){
                    currentShowcase = countShowcase;
                }   
                
                $("#showcase_"+currentShowcase).fadeIn(500);                
            });
            
            //verificar auto slider
            autoSlider = $("#banner").find("#autoSlider").size();
            
            if(autoSlider == 1) {
                
                setInterval(function() {
                    
                    //ocultar todos os itens
                    $("#banner").find(".showcase").each(function(){
                        $(".showcase").css("display", "none");  
                    });

                    currentShowcase++;

                    if(currentShowcase > countShowcase){
                        currentShowcase = 1;
                    }   

                    $("#showcase_"+currentShowcase).fadeIn(500); 
                }, 5000);
            }
        },
        
        industria : function () {
            
            //carregar primeiro item da vitrine
            $("#industriaPhotoFull_1").fadeIn(400);
            
            //total de itens
            countPhotos = $("#industriaPhotos").find(".industriaPhotoFull").size();
            
            //item que está sendo exibindo
            currentPhoto = 1;   
            
            //exibir próxima imagem
            $("#next").bind("click", function() {
                
                //total de itens
                countGallery = $(".thumbs_trabalhos").find(".imageGallery").size();
                
                //ocultar todos os itens
                $("#industriaPhotos").find(".industriaPhotoFull").each(function(){
                    $(".industriaPhotoFull").css("display", "none");  
                });
                
                currentPhoto++;
                
                if(currentPhoto > countPhotos){
                    
                    //localizar a galeria corrente
                    $(".thumbs_trabalhos").find(".border").each(function(){
                        nextGallery = $(".border").attr("id");
                        nextGallery = nextGallery.substr(22,2);
                        nextGallery++;                        
                    });
                    
                    if(nextGallery <= countGallery) {
                        window.location = "javascript:"+$("#thumbCurrent_"+nextGallery).attr("onclick");                    
                    }
                    else{
                        window.location = "javascript:"+$("#thumbCurrent_1").attr("onclick");                    
                    }
                }   
                
                $("#industriaPhotoFull_"+currentPhoto).fadeIn(400);  
                
                //ocultar todos as bordas
                $("#thumbs_inside_trabalhos").find(".border").each(function(){
                    $(".image").removeClass("border");  
                });

                $("#industriaThumbPhoto_"+currentPhoto).addClass("border");
            });
            
            //exibir próxima imagem
            $("#prev").bind("click", function() {
                
                //total de itens
                countGallery = $(".thumbs_trabalhos").find(".imageGallery").size();
                
                //ocultar todos os itens
                $("#industriaPhotos").find(".industriaPhotoFull").each(function(){
                    $(".industriaPhotoFull").css("display", "none");  
                });
                
                currentPhoto--;
                
                if(currentPhoto < 1){
                    //localizar a galeria corrente
                    $(".thumbs_trabalhos").find(".border").each(function(){
                        prevGallery = $(".border").attr("id");
                        prevGallery = prevGallery.substr(22,2);
                        prevGallery--;                        
                    });
                    
                    if(prevGallery > 0) {
                        
                        href = $("#thumbCurrent_"+prevGallery).attr("onclick");
                        href = "javascript:industriaViewLast" + href.substr(20, 26);
                        
                        window.location = href;                  
                    }
                    else {
                        href = $("#thumbCurrent_"+countGallery).attr("onclick");
                        href = "javascript:industriaViewLast" + href.substr(20, 26);
                        
                        window.location = href;                  
                    }
                }   
                
                $("#industriaPhotoFull_"+currentPhoto).fadeIn(400);

                //ocultar todos as bordas
                $("#thumbs_inside_trabalhos").find(".border").each(function(){
                    $(".image").removeClass("border");  
                });

                $("#industriaThumbPhoto_"+currentPhoto).addClass("border");
            });
            
            //exibir próximo vídeo
            $("#industriaNextVideo").bind("click", function() {
                
                //total de vídeos
                countVideos = $(".thumbs_trabalhos").find(".imageThumbVideo").size();
                
                //ocultar todos os itens
                $("#industriaVideos").find(".industriaVideo").each(function(){
                    $(".industriaVideo").css("display", "none");  
                });
                
                //localizar a galeria corrente
                $(".thumbs_trabalhos").find(".border").each(function(){
                    nextVideo = $(".border").attr("id");
                    nextVideo = nextVideo.substr(20,2);
                    nextVideo++;                        
                });
                    
                if(nextVideo <= countVideos) {
                    window.location = "javascript:"+$("#thumbCurrent_"+nextVideo).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbCurrent_1").attr("onclick");                    
                }           
            });
            
            //exibir imagem anterior
            $("#industriaPrevVideo").bind("click", function() {
                
                //total de vídeos
                countVideos = $(".thumbs_trabalhos").find(".imageThumbVideo").size();
                
                //ocultar todos os itens
                $("#industriaVideos").find(".industriaVideo").each(function(){
                    $(".industriaVideo").css("display", "none");  
                });
                
                //localizar o vídeo corrente
                $(".thumbs_trabalhos").find(".border").each(function(){
                    prevVideo = $(".border").attr("id");
                    prevVideo = prevVideo.substr(20,2);
                    prevVideo--;                        
                });
                    
                if(prevVideo > 0) {
                    window.location = "javascript:"+$("#thumbCurrent_"+prevVideo).attr("onclick");                  
                }
                else {
                    window.location = "javascript:"+$("#thumbCurrent_"+countVideos).attr("onclick");                                    
                }                
            });
        }, //industria
        
        search : function () {
            
            //simple accordion
            $('#texto_direita').accordion({
                autoheight: false,
                active:false,
                alwaysOpen: false
            });
            
            //simple accordion
            $('#exposicao').accordion({
                autoheight: false,
                active:false,
                alwaysOpen: false
            });
            
            //exibir próxima fotografia
            $("#searchNextPhotography").bind("click", function() {
                
                //total de fotografias
                countPhotography = $(".thumbs_fotografia").find(".imagePhotography").size();
                
                //ocultar todos os itens
                $("#searchPhotoFull").find(".searchPhotoFull").each(function(){
                    $(".searchPhotoFull").css("display", "none");  
                });
                
                //localizar a fotografia corrent
                $(".thumbs_fotografia").find(".border").each(function(){
                    nextPhotography = $(".border").attr("id");
                    nextPhotography = nextPhotography.substr(18,2);
                    nextPhotography++;                        
                });
                    
                if(nextPhotography <= countPhotography) {
                    window.location = "javascript:"+$("#thumbCurrent_"+nextPhotography).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbCurrent_1").attr("onclick");                 
                }           
            });
            
            //exibir fotografia anterior
            $("#searchPrevPhotography").bind("click", function() {
                
                //total de fotografias
                countPhotography = $(".thumbs_fotografia").find(".imagePhotography").size();
                
                //ocultar todos os itens
                $("#searchPhotoFull").find(".searchPhotoFull").each(function(){
                    $(".searchPhotoFull").css("display", "none");  
                });
                
                //localizar a fotografia corrent
                $(".thumbs_fotografia").find(".border").each(function(){
                    prevPhotography = $(".border").attr("id");
                    prevPhotography = prevPhotography.substr(18,2);
                    prevPhotography--;                        
                });
                    
                if(prevPhotography > 0) {
                    window.location = "javascript:"+$("#thumbCurrent_"+prevPhotography).attr("onclick");                    
                }
                else {
                    window.location = "javascript:"+$("#thumbCurrent_"+countPhotography).attr("onclick");                                                     
                }                  
            });
            
            //exibir próximo vídeo
            $("#searchNextVideo").bind("click", function() {
                
                //total de vídeos
                countVideo = $(".videos").find(".imageThumbVideo").size();
                
                //ocultar todos os itens
                $("#searchVideoFull").find(".searchVideoFull").each(function(){
                    $(".searchVideoFull").css("display", "none");  
                });
                
                //localizar o vídeo corrente
                $(".videos").find(".borderThumbVideo").each(function(){
                    nextVideo = $(".borderThumbVideo").attr("id");
                    nextVideo = nextVideo.substr(12,2);
                    nextVideo++;                        
                });
                    
                if(nextVideo <= countVideo) {
                    window.location = "javascript:"+$("#thumbVideoCurrent_"+nextVideo).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbVideoCurrent_1").attr("onclick");                 
                }           
            });
            
            //exibir vídeo anterior
            $("#searchPrevVideo").bind("click", function() {
                
                //total de vídeos
                countVideo = $(".videos").find(".imageThumbVideo").size();
                
                //ocultar todos os itens
                $("#searchVideoFull").find(".searchVideoFull").each(function(){
                    $(".searchVideoFull").css("display", "none");  
                });
                
                //localizar o vídeo corrente
                $(".videos").find(".borderThumbVideo").each(function(){
                    prevVideo = $(".borderThumbVideo").attr("id");
                    prevVideo = prevVideo.substr(12,2);
                    prevVideo--;                        
                });
                    
                if(prevVideo > 0) {
                    window.location = "javascript:"+$("#thumbVideoCurrent_"+prevVideo).attr("onclick");                    
                }
                else {
                    window.location = "javascript:"+$("#thumbVideoCurrent_"+countVideo).attr("onclick");                                                     
                }                  
            });
            
            //exibir próxima fotografia
            $("#searchNextExtraPhotography").bind("click", function() {
                
                //total de fotografias
                countExtraPhotography = $(".thumbs_exposicao_fotografia").find(".imageExtraPhotography").size();
                
                //ocultar todos os itens
                $("#searchExtraPhotoFull").find(".searchExtraPhotoFull").each(function(){
                    $(".searchExtraPhotoFull").css("display", "none");  
                });
                
                //localizar a fotografia corrent
                $(".thumbs_exposicao_fotografia").find(".borderExtraPhotography").each(function(){
                    nextPhotography = $(".borderExtraPhotography").attr("id");
                    nextPhotography = nextPhotography.substr(23,2);
                    nextPhotography++;                        
                });
                    
                if(nextPhotography <= countExtraPhotography) {
                    window.location = "javascript:"+$("#thumbExtraPhotographyCurrent_"+nextPhotography).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbExtraPhotographyCurrent_1").attr("onclick");                 
                }           
            });
            
            //exibir fotografia extra anterior
            $("#searchPrevExtraPhotography").bind("click", function() {
                
                //total de fotografias
                countPhotography = $(".thumbs_exposicao_fotografia").find(".imageExtraPhotography").size();
                
                //ocultar todos os itens
                $("#searchExtraPhotoFull").find(".searchExtraPhotoFull").each(function(){
                    $(".searchExtraPhotoFull").css("display", "none");  
                });
                
                //localizar a fotografia corrent
                $(".thumbs_exposicao_fotografia").find(".borderExtraPhotography").each(function(){
                    prevPhotography = $(".borderExtraPhotography").attr("id");
                    prevPhotography = prevPhotography.substr(23,2);
                    prevPhotography--;                        
                });
                    
                if(prevPhotography > 0) {
                    window.location = "javascript:"+$("#thumbExtraPhotographyCurrent_"+prevPhotography).attr("onclick");                    
                }
                else {
                    window.location = "javascript:"+$("#thumbExtraPhotographyCurrent_"+countPhotography).attr("onclick");                                                     
                }                  
            });
            
            //exibir próximo vídeo extra
            $("#searchNextExtraVideo").bind("click", function() {
                
                //total de vídeos
                countExtraVideo = $(".exposicao_video").find(".imageThumbExtraVideo").size();
                
                //ocultar todos os itens
                $("#searchExtraVideoFull").find(".searchExtraVideoFull").each(function(){
                    $(".searchExtraVideoFull").css("display", "none");  
                });
                
                //localizar o vídeo corrente
                $(".exposicao_video").find(".borderThumbExtraVideo").each(function(){
                    nextExtraVideo = $(".borderThumbExtraVideo").attr("id");
                    nextExtraVideo = nextExtraVideo.substr(17,2);
                    nextExtraVideo++;                        
                });
                    
                if(nextExtraVideo <= countExtraVideo) {
                    window.location = "javascript:"+$("#thumbExtraVideoCurrent_"+nextExtraVideo).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbExtraVideoCurrent_1").attr("onclick");                 
                }           
            });
            
            //exibir vídeo extra anterior
            $("#searchPrevExtraVideo").bind("click", function() {
                
                //total de vídeos
                countExtraVideo = $(".exposicao_video").find(".imageThumbExtraVideo").size();
                
                //ocultar todos os itens
                $("#searchExtraVideoFull").find(".searchExtraVideoFull").each(function(){
                    $(".searchExtraVideoFull").css("display", "none");  
                });
                
                //localizar o vídeo corrente
                $(".exposicao_video").find(".borderThumbExtraVideo").each(function(){
                    prevExtraVideo = $(".borderThumbExtraVideo").attr("id");
                    prevExtraVideo = prevExtraVideo.substr(17,2);
                    prevExtraVideo--;                        
                });
                    
                if(prevExtraVideo > 0) {
                    window.location = "javascript:"+$("#thumbExtraVideoCurrent_"+prevExtraVideo).attr("onclick");                    
                }
                else{
                    window.location = "javascript:"+$("#thumbExtraVideoCurrent_"+countExtraVideo).attr("onclick");                 
                }   
            });

            /* ordenar itens da direita */

            $("#view_1").css('display', 'block').after($("#view_2").css('display', 'block'));
            $("#view_2").after($("#view_3").css('display', 'block'));
                
        },
        
        press : function () {
            
            //simple accordion
            $('#content_press').accordion({
                header: 'a.press_tit',
                autoheight: false,
                active: false,
                alwaysOpen: false
            });                        
        }
        
    } //aretha
    
    aretha.init();
    aretha.showcase();
    aretha.search();
    aretha.industria();
    aretha.press();
   
})(this.jQuery);

/**
 * exibir as fotos/thumbs de uma galeria
 *
 */
function indutriaThumbsPhotos(idGallery, count) {
    //ocultar todos as bordas
    $(".thumbs_trabalhos").find(".border").each(function(){
        $(".imageGallery").removeClass("border");  
    });
    
    $("#industriaThumbGallery_"+count).addClass("border");
    
    $("#thumbs_inside_trabalhos").load("includes/industria_thumbs_photos.php?id_gallery="+idGallery);
    $("#industriaPhotos").load("includes/industria_photos.php?id_gallery="+idGallery);
}

/**
 * exibir uma foto selecionada
 *
 */
function viewPhoto(index) {
    //ocultar todos os itens
    $("#industriaPhotos").find(".industriaPhotoFull").each(function(){
        $(".industriaPhotoFull").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $("#thumbs_inside_trabalhos").find(".border").each(function(){
        $(".image").removeClass("border");  
    });
    
    $("#industriaThumbPhoto_"+index).addClass("border");

    currentPhoto = index;

    if(currentPhoto > countPhotos){
        currentPhoto = 1;
    }   

    $("#industriaPhotoFull_"+index).fadeIn(400);      
}

/**
 * exibir as fotos/thumbs de uma galeria com ponteiro na última foto
 *
 */
function industriaViewLast(idGallery, count) {
    
    //ocultar todos as bordas
    $(".thumbs_trabalhos").find(".border").each(function(){
        $(".imageGallery").removeClass("border");  
    });
    
    $("#industriaThumbGallery_"+count).addClass("border");
    
    $("#thumbs_inside_trabalhos").load("includes/industria_thumbs_photos.php?id_gallery="+idGallery+"&pointer=last");
    $("#industriaPhotos").load("includes/industria_photos.php?id_gallery="+idGallery+"&pointer=last");
}

/**
 * exibir um vídeo selecionado
 *
 */
function industriaViewVideo(id, count) {
    
    //ocultar todos os itens
    $("#industriaVideos").find(".industriaVideo").each(function(){
        $(".industriaVideo").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $(".thumbs_trabalhos").find(".border").each(function(){
        $(".imageThumbVideo").removeClass("border");  
    });
    
    $("#industriaThumbVideo_"+count).addClass("border");

    $("#industriaVideos").load("includes/industria_video.php?id_video="+id);
}

/**
 * exibir uma fotografia selecionada em pesquisa
 *
 */
function searchViewPhotography(id, count) {
    
    $("#sectionFront").css("display","none");
    $("#sectionExtraPhotos").css("display","none");
    $("#sectionVideo").css("display","none");
    $("#sectionExtraVideo").css("display","none");
    $("#sectionPhotography").css("display","block");
    
    //ocultar todos os itens
    $("#searchPhotos").find(".searchPhotoFull").each(function(){
        $(".searchPhotoFull").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $(".thumbs_fotografia").find(".border").each(function(){
        $(".imagePhotography").removeClass("border");  
    });
    
    $("#searchPhotography_"+count).addClass("border");

    $("#searchPhotos").load("includes/search_photography.php?id_photography="+id);
}

/**
 * exibir um vídeo selecionado em pesquisa
 *
 */
function searchViewVideo(id, count) {
    
    $("#sectionFront").css("display","none");
    $("#sectionPhotography").css("display","none");
    $("#sectionExtraPhotos").css("display","none");
    $("#sectionExtraVideo").css("display","none");
    $("#sectionVideo").css("display","block");
    
    //ocultar todos os itens
    $("#searchVideo").find(".searchVideoFull").each(function(){
        $(".searchVideoFull").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $(".videos").find(".borderThumbVideo").each(function(){
        $(".imageThumbVideo").removeClass("borderThumbVideo");  
    });
    
    $("#searchVideo_"+count).addClass("borderThumbVideo");

    $("#searchVideo").load("includes/search_video.php?id_video="+id);
}

/**
 * exibir uma fotografia extra selecionada em pesquisa
 *
 */
function searchViewExtraPhotography(id, count) {
    
    $("#sectionFront").css("display","none");
    $("#sectionPhotography").css("display","none");
    $("#sectionVideo").css("display","none");
    $("#sectionExtraVideo").css("display","none");
    $("#sectionExtraPhotos").css("display","block");
    
    //ocultar todos os itens
    $("#searchExtraPhotos").find(".searchExtraPhotoFull").each(function(){
        $(".searchExtraPhotoFull").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $(".thumbs_exposicao_fotografia").find(".borderExtraPhotography").each(function(){
        $(".imageExtraPhotography").removeClass("borderExtraPhotography");  
    });
    
    $("#searchExtraPhotography_"+count).addClass("borderExtraPhotography");

    $("#searchExtraPhotos").load("includes/search_extra_photography.php?id_photography="+id);
}

/**
 * exibir um vídeo extra selecionado em pesquisa
 *
 */
function searchViewExtraVideo(id, count) {
    
    $("#sectionFront").css("display","none");
    $("#sectionPhotography").css("display","none");
    $("#sectionExtraPhotos").css("display","none");    
    $("#sectionVideo").css("display","none");
    $("#sectionExtraVideo").css("display","block");
    
    //ocultar todos os itens
    $("#searchExtraVideo").find(".searchExtraVideoFull").each(function(){
        $(".searchExtraVideoFull").css("display", "none");  
    });
    
    //ocultar todos as bordas
    $(".exposicao_video").find(".borderThumbExtraVideo").each(function(){
        $(".imageThumbExtraVideo").removeClass("borderThumbExtraVideo");  
    });
    
    $("#searchExtraVideo_"+count).addClass("borderThumbExtraVideo");

    $("#searchExtraVideo").load("includes/search_extra_video.php?id_video="+id);
}

function searchViewArchives() {
    $("#searchWorks").fadeOut(400);
    $("#searchArchives").fadeIn(800);
}

function searchViewWorks() {
    $("#searchArchives").fadeOut(400);
    $("#searchWorks").fadeIn(800);
}

// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function() {
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
      arguments.callee = arguments.callee.caller;
      console.log( Array.prototype.slice.call(arguments) );
  }
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


// place any jQuery/helper plugins in here, instead of separate, slower script files.
