/*
* ISOFT
* @Define: Scripts for location dropdown
* @Dependancies: MooTools
**/

var IsoftLocations = new Class({
    Implements: [Options, Events],

    //Default options
    options: {
        locList: "#location ul", //location list
        locItem: "#location ul li a", //list item
        locTrigger: "#locTrigger" //Trigger to dropdown
    },

    initialize: function(options) {
        this.setOptions(options);
        this.events();
    },

    events: function() {
        $$(this.options.locTrigger).addEvent("click", this.showList.bind(this));
        $$(this.options.locList).addEvent("mouseleave", this.hideList.bind(this));
        $$(this.options.locItem).addEvent("click", this.switchText.bind(this));
    },

    showList: function() {
        $$(this.options.locList).setStyle("visibility", "visible");
    },

    hideList: function() {
        $$(this.options.locList).setStyle("visibility", "hidden");
    },

    switchText: function(event) {
        //event.preventDefault();
        $$(this.options.locItem).removeClass("selected"); //clear all first
        event.target.addClass("selected");
        $$(this.options.locTrigger).set("html", event.target.get("html"));
        this.hideList();
    }
});

window.addEvent('domready', function() {
    new IsoftLocations();
});

