/*
    SiteComponents version:
    6.8.0.1, tag SC_6_8_0_1, created Fri Aug 20 11:18:33 +0200 2010

    Disclaimer
    
    While we make every effort to ensure that this code is fit for its intended
    purpose, we make no guarantees as to its functionality. CoreTrek AS will
    accept no responsibility for the loss of data or any other damage or
    financial loss caused by use of this code.


    Copyright
    
    This programming code is copyright of CoreTrek AS. Permission to run this
    code is given to approved users of CoreTrek's publishing system CorePublish.
    
    This source code may not be copied, modified or otherwise repurposed for use
    by a third party without the written permission of CoreTrek AS.
    
    Contact webmaster@coretrek.com for information.
    
*/

/*

    SiteComponents dropdownmenu.js

    Adds listener and action to drop down menu
    
*/

var DropdownMenu = Class.create({

    initialize: function(element) {
        this.element = $(element);
        
        // Get the select element
        this.selectElement = element.select('select').first();
        
        // Add redirect listener to select element
        this.selectElement.observe('change', this.redirectListener.bindAsEventListener(this));
        
    },
    
    
    // ========================================================================
    // Event listeners
    
    /**
    *   Listener to option elements
    *
    *   This listener get the value from an option element and 
    *   set the location href to this value.
    */
    redirectListener: function(event) {
        event.stop();
        
        var optionValue = event.element().getValue();
        
        if(optionValue != null && optionValue.length > 0) {
           location.href = optionValue;
        }
    }
    
});

