$.fn.middleBoxButton = function(text, url) {
    
    return this.hover(function(e) {
    
        $el = $(this).css("border-color", "#7c512e");
        divHeight = $el.height() + parseInt($el.css("padding-top")) + parseInt($el.css("padding-bottom"));
                
        $tempDiv = $("<div />", {
        
            "class": "overlay rounded"
        
        })
        
        $tempButton = $("<a />", {
        
            href: url,
            text: text,
            "class": "learn-more-button",
            css: {
                top: (divHeight / 2) - 5 + "px"
            }
        
        }).appendTo($tempDiv);
        
        $tempDiv.appendTo($el);
        
    }, function(e) {
    
        $el = $(this).css("border-color", "#999");
    
        $(".overlay").fadeOut("fast", function() {
            $(this).remove();
        })
    
    });
    
};

$(function(){
    
    $("a[href='#photostream'], a[href='#sets'], a[href='#interesting']").remove();
    
    var $allPhotos = $("#all-photos"),
        $origPhotoSet = $allPhotos.find(".flickr-thumb"),
        numPhotos = $origPhotoSet.length,
        oneWidth = $origPhotoSet.width(),
        oneMargin = parseInt($origPhotoSet.css("margin-right")),
        blockWidth = (oneWidth * numPhotos) + (oneMargin * numPhotos);
            
    function movePhotosLeft(first) {
    
        if (first) {
            $origPhotoSet.clone().appendTo(".flickr-gallery");
        } else {
            $origPhotoSet.clone().appendTo(".flickr-gallery").find("img").flightbox();
        }
        
        $allPhotos.animate({
            right: blockWidth
        }, 200000, "linear", function() {
        
            $allPhotos.css("right", 0);
            $("#all-photos .flickr-thumb:lt("+numPhotos+")").remove();
            movePhotosLeft(false); 
        
        });
    
    };
    
    movePhotosLeft(true);
    
    
    var $el, $tempDiv, $tempButton, divHeight = 0;
    
    $("#text-5").middleBoxButton("Learn more about the show", "/about-the-show/");
    $("#text-7").middleBoxButton("Read more show reviews", "/reviews/");
     
    $(".show_calendar_widget").delegate("li", "click", function() {
        window.location = $(this).find("a").attr("href");
    });
    
});