﻿window.onload = function() {

    // Get selector
    var selector = document.getElementById("selector");
    if (selector !== null) {

        // Get panes
        var home = document.getElementById("home"),
        accommodation = document.getElementById("accommodation"),
        business = document.getElementById("business-breaks"),
        party = document.getElementById("party-breaks"),
				element, 
        // Reset function
        reset = function() {

            home.className = "panel";

            this.className = "panel hide";

            for (i = 0, il = selector.childNodes.length; i < il; i++) {
                if (selector.childNodes[i].nodeName == "LI") {
                    selector.childNodes[i].className = selector.childNodes[i].className.replace(" hit", "");
                }
            }

        };

        // Wire selector events
        for (i = 0, il = selector.childNodes.length; i < il; i++) {

            if (selector.childNodes[i].nodeName == "LI") {

                selector.childNodes[i].onmouseover = function() {

                    element = document.getElementById(this.className);

                    if (element !== null) {

                        if (document.getElementById(this.className).className != "panel") {
                            document.getElementById(this.className).className = "panel";
                        }

                        if (this.className != "home") { home.className = "panel hide"; }
                        if (this.className != "accommodation") { accommodation.className = "panel hide"; }
                        if (this.className != "business-breaks") { business.className = "panel hide"; }
                        if (this.className != "party-breaks") { party.className = "panel hide"; }

                        this.className += " hit";

                        for (j = 0; j < this.parentNode.childNodes.length; j++) {
                            if (this.parentNode.childNodes[j].nodeName == "LI" && this.parentNode.childNodes[j].className != this.className) {
                                this.parentNode.childNodes[j].className = this.parentNode.childNodes[j].className.replace(" hit", "");
                            }
                        }
                    }

                };

            }

        }

    }

};
