// vMenu version 0.1 
// � 2008, Oleg "e1vin" Gromoff
// front-end beta version

// Creating global vMenuData object that stores all runtime data
window.vMenuData = new Object;

// Fulling this object with properties
window.vMenuData.menuElements = new Object();

// Version. Used for yours and mine informational purposes :)
vMenu.prototype.version = 0.2;

// Base property members
vMenu.prototype.baseDiv = null;

// Base function members
vMenu.prototype.init = function() 
{
    // Searching for menu's parent DIV 
    var menuRoot = document.getElementById( this.baseDiv );

//	var dvf=document.createElement('iframe');
//	dvf.id="iframeFullId";
//	document.getElementsByTagName('body')[0].appendChild(dvf);
//	$(dvf).hide();
//	this.ifr = $(dvf);


    if ( menuRoot )
    {
        this.nodeAnalysis( menuRoot );
    }

};

vMenu.prototype.nodeAnalysis = function ( currentNode )
{
    if ( currentNode.nodeType == 1 )
    {
        if ( currentNode.hasChildNodes() )
        {
            for ( var i = 0; i < currentNode.childNodes.length; i++ )
            {
                currentNodeChild = currentNode.childNodes[ i ];
                
                if ( currentNodeChild.nodeType == 1 )
                {
                   if ( currentNodeChild.nodeName != "A" && currentNodeChild.nodeName != "FORM" )
                    {
                        var currentClassName = currentNodeChild.className;
                        var dropoutPattern = /(dropdown|dropright){1}/;
                        
                        if ( currentClassName && dropoutPattern.test( currentClassName ) )
                        {
                            var currentParent = currentNodeChild.parentNode;
                            
                            currentParent.menuDropout = currentNodeChild;
                            var defaultClass = currentParent.className.match( /(inactive|active)/ )
                            
                            if ( defaultClass )
                            {
                                currentParent.defaultClass = defaultClass[ 0 ];
                            }
                            
                            currentParent.onmouseover = function( thob )
                            {
//								thob.ifr.show();
                                this.className = this.className.replace( /(inactive|active)/, "selected" );
                                this.menuDropout.style.display = "block";
                            }.curry( this );

                            currentParent.onmouseout = function( thob )
                            {
//								thob.ifr.hide();
                                this.className = this.className.replace( /selected/, this.defaultClass );
                                this.menuDropout.style.display = "none";
                            }.curry( this );
                        }
                        
                        if ( currentNodeChild.hasChildNodes() )
                        {
                            this.nodeAnalysis( currentNodeChild );
                        }
                    }
                }
            }
        }
    }
};

// Constructor of vMenu object. Please specify parent menu DIV's id as string
function vMenu( menuDiv )
{
    // Copying the constructor parameter to the local variable
    this.baseDiv = menuDiv;
    
    // Calling to init function (setting IDs for DIVs)
    this.init();

    // This one sets all event handlers used in menu
    //this.setEventHandlers();
    
    return;
}