// JavaScript Document// Discover more //
// need to wait for the window to load rather than the dom due to images no longer having fixed sizes (grid system)

//based on MuseumsSheffield http://www.museums-sheffield.org.uk/




$(window).load(function() {
    var dm = $('#discoverMore'),
        originalText = dm.find('a.button:first').html();
    dm.removeClass('hidden');
    $('#discoverMoreNav', dm).append($('#sitemap')[0].cloneNode(true));
        
    $('.button', dm).click(function(evt) {
        evt.preventDefault();
        var $t = $(evt.currentTarget);

        if(parseInt(dm.css('top')) < 0) // opening
        { 
            dm.animate({
                top: 0
            }, 400, 'linear', function() {
                $t.fadeOut(250, function() {
                    $t.html('cierre la pesta&ntilde;a <span></span>');
                    $t.addClass('open');
                    $t.fadeIn(250);
                });
            });
            
            // Track interactions
            /*if (_gaq) {
                _gaq.push(['_trackEvent', 'Explore bar', 'Open']);  
            }*/
            
        }
        else
        {
            dm.animate({
                top: 20 - dm.outerHeight()
            }, 400, 'linear', function() { 
                    $t.fadeOut(250, function() {
                    $t.html(originalText);
                    $t.removeClass('open');
                    $t.fadeIn(250);
                })
            });
            
            // Track interactions
            /*if (_gaq) {
                _gaq.push(['_trackEvent', 'Explore bar', 'Close']); 
            }*/
        }
    });
                                                
    $('#discoverMore').css({top: 20 - dm.outerHeight()});
    
    // re-align the discover more bar on window resize
    var resizeTimeout = null;
    $(window).resize(function() {
        clearTimeout(resizeTimeout);
        resizeTimeout = setTimeout(function() {
            var dm = $('#discoverMore');
            dm.css({top: 20 - dm.outerHeight()});
        }, 200);
    });
});







