// Define LI over class function

var applyListItemOverBehaviour = function () {
    // Define mouse over and out behaviours
    var liMouseOverBehaviour = function () {
        // This function adds 'over' to the element's classes
        this.className += ' over';
        showIframe( this );
    };
    
    var liMouseOutBehaviour = function () {
        // This function removes 'over' from the element's classes
        this.className = this.className.replace(' over', '');
        hideIframe( this );
    };

    // Find all list items
    var all_li = document.getElementsByTagName( 'li' );

    // Apply behaviours
    for ( var i = 0; i < all_li.length; i += 1 ) {
        all_li[ i ].onmouseover = liMouseOverBehaviour;
        all_li[ i ].onmouseout = liMouseOutBehaviour;
    }
};

var ieCover = function() {
    var ieNavs = document.getElementsByTagName('ul');
    for (var i = 0; i < ieNavs.length; i += 1) {
        var ul = ieNavs[i];
        // If they have a class of nav add the menu hover.
        if (/\bnav\b/.test(ul.className)) {
            createIframe(ul);
        }
    }
};

function createIframe(nav) {	
    var ieULs = nav.getElementsByTagName('ul');
    for (var i = 0; i < ieULs.length; i += 1) {
        var ieUL = ieULs[i];
        if (ieUL) {
            var iFrame = document.createElement('iframe');
            if(document.location.protocol == "https:") {
                iFrame.src="javascript:false";
            }
            else if(window.opera != "undefined") {
                iFrame.src="";
            }
            else {
                iFrame.src="javascript:false";
            }
            iFrame.className = "nav";
            iFrame.scrolling="no";
            iFrame.frameBorder="0";
            ieUL.insertBefore(iFrame, ieUL.childNodes[0]);
        }
    }
}

function showIframe(nav) {
    var iFrame = nav.getElementsByTagName('iframe')[0];
    var ul = nav.getElementsByTagName('ul')[0];
		
    if (ul && iFrame) {
        iFrame.style.display = "block";
        iFrame.style.top = ul.offsetTop;
        iFrame.style.left = ul.offsetLeft;		
        /* --Fix by SA 12/09/2007 - Fixes an issue with IE7-- 
		When there is only 1 item in the dropdown we set the height and top.
		IE7 doesnt like a negative value being given to the style.height attrib
		*/
		if (ul.getElementsByTagName('li').length != 1) {
			iFrame.style.height = ul.offsetHeight - ul.offsetTop;
		} else { 
			iFrame.style.height = 20; 
			iFrame.style.top = ul.offsetTop - 30; 
		}		
        iFrame.style.width = ul.offsetWidth - ul.offsetLeft;
        iFrame.style.zindex = 5;
    }
}

function hideIframe(nav) {
    var iFrame = nav.getElementsByTagName('iframe')[0];
    if (iFrame) {
        iFrame.style.display = "none";
    }
}

// Apply JS behaviours
if (window.attachEvent) {	
    window.attachEvent('onload', applyListItemOverBehaviour);
    window.attachEvent('onload', ieCover);
}

