
    document.observe("dom:loaded", function() {
    
        if ($('image_header')) {
        
            var size = $w($('image_header').className)[0];
            if (size) {
                size += '/';
            } else {
                size = '';
            }
            
            // Assign the whole of the image header with the link of the active item
            $('image_header').observe('click', function() {
                var active = $('image_header').select('div.right_panel div.active a')[0];
                if (active) {
                    var href = active.getAttribute('href');
                    var blank = active.getAttribute('class');
                    if (blank == 'blank') {
                        window.open(href);
                    } else {
                        window.location = href;
                    }
                }
            });
            
            $('image_header').select('div.right_panel div').each(function(element, key) {
                
                element.observe('mouseover', function() {
                    
                    // deactivate the currently active title
                    var active = element.adjacent('div.active')[0];
                    if (active) active.removeClassName('active');
                    
                    // Activate this title
                    element.addClassName('active');
                
                    // Hide all description panels and show the one which corresponds to this element
                    var panels = $('image_header').select('div.left_panel div');
                    panels.invoke('hide');
                    panels[key].show();
                    
                    var file_name = element.down('a').getAttribute('rel');
                    var src = '/assets/file_uploads/m_dynamicheader_items_image/' + size;
                    $('image_header').setStyle({'backgroundImage': 'url("' + src + file_name + '")'});
                    
                });
                
            });
        
        }
        
        if ($('image_header_thumbnails')) {
        
            // Assign the whole of the image header with the link of the active item
            $('image_header_thumbnails').observe('click', function() {
                var active = $('image_header_thumbnails').select('div.thumbnails a.active')[0];
                if (active) {
                    var href = active.getAttribute('href');
                    var blank = active.getAttribute('class');
                    if (blank == 'blank') {
                        window.open(href);
                    } else {
                        window.location = href;
                    }
                }
            });
            
            $('image_header_thumbnails').select('div.thumbnails a').each(function(element, key) {
                element.observe('mouseover', function() {
                    dynamic_header_event(element, key);
                    $('image_header_thumbnails').addClassName('paused');
                });
                element.observe('mouseout', function() {
                    dynamic_header_event(element, key);
                    $('image_header_thumbnails').removeClassName('paused');
                });
            });
            
            setInterval(function() {
                
                if ($('image_header_thumbnails').hasClassName('paused')) return false;
                
                // Get the number of thumbnails
                var thumbnails = $('image_header_thumbnails').select('div.thumbnails a');
                thumbnails.each(function(a, key) {
                    if (a.hasClassName('active')) {
                        var index = key + 1;
                        
                        // If there is not a next thumbnail else load the first
                        var thumbnail = $('image_header_thumbnails').select('div.thumbnails a')[index];
                        if (!thumbnail) {
                            var thumbnail = $('image_header_thumbnails').select('div.thumbnails a')[0];
                            index = 0;
                        }
                        dynamic_header_event(thumbnail, index);
                        throw $break;
                    }
                });
            }, 9000)
        }
    
    });
    
    function dynamic_header_event(element, key)
    {
        // deactivate the currently active title
        var active = element.adjacent('a.active')[0];
        if (active) active.removeClassName('active');
        
        // Activate this title
        element.addClassName('active');
    
        // Hide all description panels and show the one which corresponds to this element
        var panels = $('image_header_thumbnails').select('div.left_panel div');
        panels.invoke('hide');
        panels[key].show();
        
        var size = $w($('image_header_thumbnails').className)[0];
        if (!size) size = '950x270';
        
        var file_name = element.getAttribute('rel');
        var src = '/assets/file_uploads/m_dynamicheader_items_image/' + size + '/';
        $('image_header_thumbnails').setStyle({'backgroundImage': 'url("' + src + file_name + '")'});
    }
    


