/*	Using the Behaviour library to trigger the WCH script for IE so the function
	calls don't have to be added to the HTML. Also using previousSibling to hide
	the border of the menu item to the left of a hovered menu item, since IE 
	can't use the margin property to do this. */

var myrules = {
    '#mainmenu li' : function(element) {
        element.onmouseover = function() {
            if (document.all) {
                if (this.previousSibling) {
                    var activeCheck = this.previousSibling.className;
                    if (activeCheck != 'active') {
                        this.previousSibling.style.backgroundPosition = '-5000px 5px';
                    }
                }
                var menuCheck = this.className;
                if (menuCheck != '') {
                    WCH.Apply(this.id + 'menu');
                }
            }
        }
        element.onmouseout = function() {
            if (document.all) {
                if (this.previousSibling) {
                    var activeCheck = this.previousSibling.className;
                    if (activeCheck != 'active') {
                        this.previousSibling.style.backgroundPosition = 'right 5px';
                    }
                }
                var menuCheck = this.className;
                if (menuCheck != '') {
                    WCH.Discard(this.id + 'menu');
                }
            }
        }
    },
    '#toggledetails' : function(element) {
        element.onclick = function() {
            var el = document.getElementById('details');
            var ln = document.getElementById('toggledetails');
            if (el.style.display != 'none') {
                el.style.display = 'none';
                ln.innerHTML = 'Show Details';
            }
            else {
                el.style.display = '';
                ln.innerHTML = 'Hide Details';
            }
        }
    }/*,
	'.selectrow' : function(element){
		element.onclick = function(){
			var lk = document.getElementById(this.id + 'link');
			if (this.checked) {
				lk.style.fontWeight = 'bold';
			} else {
				lk.style.fontWeight = 'normal';
			}
		}
	}*/
};
Behaviour.register(myrules);

/*	This appends the class "WCHhider" to all the selects on a page so the client
	doesn't have to go through all their pages and add the class to make the 
	Windowed Control Hider script work.
	
	It also takes care of getting rid of the menu item border next to active
	menu items, since IE can't do that with the margin setting that works in
	Safari and Firefox.  */

appendIEstyles = function() {
    var sel = document.getElementsByTagName("select");
    for (var i = 0; i < sel.length; i++) {
        sel[i].className += " WCHhider";
    }
    var active = document.getElementById("mainmenu").getElementsByTagName("LI");
    for (var i = 0; i < active.length; i++) {
        if (active[i].className == 'active') {
            active[i].previousSibling.className += ' preactive';
        }
    }
    var active = document.getElementById("sectionmenu").getElementsByTagName("LI");
    for (var i = 0; i < active.length; i++) {
        if (active[i].className == 'subactive') {
            if (active[i].previousSibling) {
                active[i].previousSibling.style.backgroundPosition = '-5000px 5px';
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", appendIEstyles);


function toggle(obj1, obj2) {
    var el = document.getElementById(obj1);
    var ln = document.getElementById(obj2);
    if (el.style.display != 'none') {
        el.style.display = 'none';
        ln.innerHTML = 'Show Details';
    }
    else {
        el.style.display = '';
        ln.innerHTML = 'Hide Details';
    }
}
