/* Catalogue drop down button effect */

Event.observe(window, 'load', 
    function() {

    // Attach an event to the full descriptions
    fullDescriptions();
    
    }
);

/**
 * Full Descriptions
 *
 * Attach an event on click which will retrieve the js version of the full description and insert the content
 */

function fullDescriptions() {
    
    /* Get all the productFullDesc elements */

    fullDescriptions = document.getElementsByClassName('productFullDesc');
    
    len = fullDescriptions.length;
    for(i=0;i<len;i++) {
        Event.observe(fullDescriptions[i], 'click', function(event) {
            var elt = Event.element(event);
            // This is the a tag surrounding the full description button, attach a click event to it
            var atag = elt.up();  
            
            // Get the src of the atag
            var url = atag.href;
          
            Event.observe(atag, 'click', fullDescriptionLink, false);
            // Get the parent tag and insert the full description
            var ptag = atag.up();

            // Get the main container

            var container = ptag.previous();

            // Hide the main container's contents
            
            container.hide();

            showDesc(ptag,url);

        })
    }
}
    
function fullDescriptionLink(e) {
    // Prevent the link from working
    Event.stop(e);
}



function showDesc(elt,url) {
    
    // First replace the p tag with the fancy ajax style loading icon to show that we are doing something
    
    elt.update('<img src="/img/loading.gif" alt="Loading full description" class="loadingDesc" />');
    
    // Now fetch the js version of this

    var timestamp = Number(new Date()); 	

    new Ajax.Updater(elt, url, {
        asynchronous: 'true',
        method: 'get',
        parameters: 'js=1&timestamp='+timestamp
    });   

}    

/**
 * Hide all the subsections
 */

function hideSubSection() {
    subsections = $('catalogueMenu').getElementsByClassName('subsection');
    len = subsections.length;
    for(i=0;i<len;i++) {
        subsections[i].hide();
    }
} 

function menuEvents() {
    Event.observe($('testthis'), 'click', function(event) {
        var elt = Event.element(event);
        new Effect.SlideDown('menu_organ-recordings2'); return false;
    });
}
