Cufon.replace('#nav a, #langnav a, #artistmenu a, li.spacer, h1, h2, h3, .cufon', {
    hover:true
});

$(document).ready(function(){
    $("a.lightbox").fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'speedIn' : 300,
        'speedOut' : 300,
        'titleShow' : true,
        'titlePosition' : 'inside',
        'type' : 'image',
        'centerOnScroll' : true,
        'overlayColor' : '#FFF'
    });

    $("a.movielightbox").fancybox({
        'autoscale' : true,
        'transitionIn' : 'elastic',
        'transitionOut': 'elastic',
        'padding' : 0,
        'titleShow' : true,
        'titlePosition' : 'inside',
        'type'    : 'swf',
        'href'    : this.href,
        'swf'   : { 'wmode':'transparent', 'allowfullscreen':'true' }
    });
    
    
    /* Artists */
    if($('body#artistview').length > 0) {
        $(window).scrollTop(0);
        var locationhash = window.location.hash;
        if(locationhash) {
            $('#langnav a').each(function(index) {
                $(this).attr('href', $(this).attr('href') + locationhash );    
            });        
        }

        if($('#press > div').length == 0) {
            $('a#press_link').hide();
        }
        if($('#biography > div').length == 0) {
            $('a#biography_link').hide();
        }

        $("#selectedworks, #biography, #press").hide();
        if(locationhash) {
            $(locationhash).show();
            $("#artistmenu a#" + locationhash +"_link").addClass("act");        
        }
        else {
            $("#selectedworks").show();
            $("#artistmenu a#selectedworks_link").addClass("act");    
        }
        Cufon.replace('#artistmenu a', {
            hover:true
        });
        
        

        $("#artistmenu > ul li:gt(0) a").click(function(e) {
            
            $("#selectedworks, #biography, #press").hide();
          
            var anchorid = $(this).attr('id');
            var underscore = anchorid.indexOf('_');
            var $tabValue = $(this).attr('href');
            var $withoutHash = $tabValue.substr(0,$tabValue.indexOf('#'));
            var langurl = '';
            var langurlwohash = '';

            anchorid = anchorid.substring(0, underscore);
            window.location.hash = '#' + anchorid;
            
            $('#langnav a').each(function(index) {
                var langurl = $(this).attr('href') + '#' + anchorid;
                if(langurl.indexOf('#') > 0) {
                    var langurlwohash = langurl.substr(0,langurl.indexOf('#'));
                    $(this).attr('href', langurlwohash + '#' + anchorid );    
                } else {
                    var langurlwohash = langurl;
                    $(this).attr('href', langurlwohash );    
                }
            });
            

            $("#artistmenu > ul > li > a").removeClass("act");
            $(this).addClass("act");
            $("#" + anchorid).show();
            Cufon.replace('#artistmenu a', {
                hover:true
            });
            return false;
        });    
    }
    
    /* Exhibitionthumbs Rollover */
    var onMouseOutOpacity = 0.50;
    $('ul.thumbnails li').opacityrollover({
        mouseOutOpacity:   onMouseOutOpacity,
        mouseOverOpacity:  1.0,
        fadeSpeed:         'fast',
        exemptionSelector: '.selected'
    });
    
    /* Current Exhibition */
    //$('#current #cummulated h2.datemarker:eq(0)').hide();
    
    // infinitescroll() is called on the element that surrounds 
    // the items you will be loading more of
    var lister = 1;
    var items = $('ul.f3-widget-paginator li').length - 1;
    
    $('#main .tx-johnengallery-pi1 > #previous').infinitescroll({
        navSelector  : "ul.f3-widget-paginator",            
                       // selector for the paged navigation (it will be hidden)
        nextSelector : "ul.f3-widget-paginator li.next > a",    
                       // selector for the NEXT link (to page 2)
        itemSelector : "div.tx-johnengallery-pi1 .exh_item",          
                       // selector for all items you'll retrieve
        animate      : false,      
                     // boolean, if the page will do an animated scroll when new content loads
                     // default: false
     
        extraScrollPx: 100,      
                     // number of additonal pixels that the page will scroll 
                     // (in addition to the height of the loading div)
                     // animate must be true for this to matter
                     // default: 150
        debug        : false,
        loadingImg   : "fileadmin/templates/img/ajax-loader.gif",          
                     // loading image.
                     // default: "http://www.infinite-scroll.com/loading.gif"

        loadingText  : "Loading more exhibitions ...",      
                     // text accompanying loading image
                     // default: "<em>Loading the next set of posts...</em>"
        pathParse : (!location.search) ? undefined : function( pathStr, nextPage ){
                        return pathStr.replace('2', nextPage );
                      }
    },function(arrayOfNewElems){
       
        Cufon.replace('h1, h2, h3', {
            hover:true
        });
         
         $(arrayOfNewElems).each(function(index) {
            $($(this).find('a.lightbox')).fancybox({
                'transitionIn' : 'elastic',
                'transitionOut' : 'elastic',
                'speedIn' : 300,
                'speedOut' : 300,
                'titleShow' : true,
                'titlePosition' : 'inside',
                'type' : 'image',
                'centerOnScroll' : true,
                'overlayColor' : '#FFF'
            });
            
            $($(this).find('ul.thumbnails li')).opacityrollover({
                mouseOutOpacity:   onMouseOutOpacity,
                mouseOverOpacity:  1.0,
                fadeSpeed:         'fast',
                exemptionSelector: '.selected'
            });    
         });

         lister++;
         
         if(items == lister) {
            $window.unbind("scroll", infiniteScroll);    
         }
    });
    
    $().UItoTop({ easingType: 'easeOutQuart' });
    
    /* Previous Exhibitions */
    /*
    if($('#previous').length > 0) {
        $('.stage_2 h2.datemarker').hide();
        $('.exh_item').each(function(index) {
            if($(this).hasClass('stage_2')) {
                var $stage1_exhibition = $(this).prev('.stage_1');
                var $stage2_exhibition = $(this);
                var $stage1_artist = $stage1_exhibition.find('h1.artistmarker');
                var $stage2_artist = $(this).find('h1.artistmarker');
                var $stage1_date = $stage1_exhibition.find('h2.datemarker');
                
                $stage1_exhibition.before('<div class="cummulated"></div>');
                var $cummulated = $stage1_exhibition.prev('div.cummulated');
                
                $stage1_artist.appendTo($cummulated);
                $stage2_artist.appendTo($cummulated);
                $stage1_date.appendTo($cummulated);    
            }
            Cufon.replace('h1, h2, h3', {
                hover:true
            });
        });
        $('.stage_0').addClass('floatbox').css({'margin-top':'20px'});    
    }
    */
    
    /* Upcoming Exhibitions */
    /*
    if($('#upcoming').length > 0) {
        $('.stage_2 h2.datemarker').hide();
        $('.exh_item').each(function(index) {
            if($(this).hasClass('stage_2')) {
                var $stage1_exhibition = $(this).prev('.stage_1');
                var $stage2_exhibition = $(this);
                var $stage1_artist = $stage1_exhibition.find('h1.artistmarker');
                var $stage2_artist = $(this).find('h1.artistmarker');
                var $stage1_additionalinfo = $stage1_exhibition.find('h1.additionalinfo');
                var $stage2_additionalinfo = $stage2_exhibition.find('h1.additionalinfo');
                var $stage1_date = $stage1_exhibition.find('h2.datemarker');
                
                $stage1_exhibition.before('<div class="cummulated"></div>');
                var $cummulated = $stage1_exhibition.prev('div.cummulated');
                
                $stage1_artist.appendTo($cummulated);
                $stage1_additionalinfo.appendTo($cummulated);
                $stage2_artist.appendTo($cummulated);
                $stage2_additionalinfo.appendTo($cummulated);
                $stage1_date.appendTo($cummulated);
                
                $stage1_exhibition.detach();
                $stage2_exhibition.detach();
                
                $cummulated.after('<hr class="line" />');    
            }
        });
        Cufon.replace('h1, h2, h3', {
            hover:true
        });    
    }
    */
});




