var oxid = {
    // Generall navigation with timeout
    nav: {

        timeout : 400,
        activem : null,
        timerid : null,
        elclass : '',
        opclass : ' open',

        open   : function(parent){
            oxid.nav.stoptm();
            if (parent) {
            	oxid.nav.setclass(oxid.nav.activem,false,true);
            } else {
            	oxid.nav.setclass(oxid.nav.activem,false,false);
            }
            oxid.nav.activem = this.id;
            if (parent) {
            	oxid.nav.setclass(oxid.nav.activem,true,true);
            } else {
            	oxid.nav.setclass(oxid.nav.activem,true,false);
            }
        },

        close : function(){
            oxid.nav.setclass(oxid.nav.activem,false);
        },

        starttm : function(){
            oxid.nav.timerid = window.setTimeout(oxid.nav.close, oxid.nav.timeout);
        },

        stoptm  : function(){
            if(oxid.nav.timerid){
                window.clearTimeout(oxid.nav.timerid);
                oxid.nav.timerid = null;
            }
        },

        setclass : function(id,add,parent) {
        	if (!parent) {
        		var parent = true;
        	}
            var el = document.getElementById(id);
            if( el ) {
                if(add){
                	if (parent) {
                		oxid.nav.elclass = el.parentNode.className;
                		el.parentNode.className += oxid.nav.opclass;
                	} else {
                		oxid.nav.elclass = el.className;
                		el.className += oxid.nav.opclass;
                	}
                }else{
                	if (parent) {
                		el.parentNode.className = oxid.nav.elclass;
                	} else {
                		el.className = oxid.nav.elclass;
                	}
                }
            }
        }
    },

    // Category navigation init
    catnav : function(ul) {
        var mn = document.getElementById(ul);
        if(mn) {
            var nr = 0;
            for (var i=0; i<mn.childNodes.length; i++) {
                if(mn.childNodes[i].tagName && mn.childNodes[i].tagName.toUpperCase() == 'LI'){
                    var mi = mn.childNodes[i];

                    for ( var n=0; n<mi.childNodes.length; n++) {
                        if(mi.childNodes[n].tagName && mi.childNodes[n].tagName.toUpperCase() == 'A'){
                            mi.childNodes[n].onmouseover = mi.childNodes[n].onfocus = oxid.nav.open ;
                            mi.childNodes[n].onmouseout  = mi.childNodes[n].onblur  = oxid.nav.starttm;
                            nr ++;
                        }
                        if(mi.childNodes[n].tagName && mi.childNodes[n].tagName.toUpperCase() == 'UL'){
                            mi.childNodes[n].onmouseover = mi.childNodes[n].onfocus = oxid.nav.stoptm ;
                            mi.childNodes[n].onmouseout  = mi.childNodes[n].onblur  = oxid.nav.starttm;
                            /* setting all childs nodes width same as <ul> */
                            var ml = mi.childNodes[n];
                            var mlWidth = ml.offsetWidth;
                            for ( var k=0; k<ml.childNodes.length; k++) {
                                if(ml.childNodes[k].tagName && ml.childNodes[k].tagName.toUpperCase() == 'LI'){
                                    ml.childNodes[k].style.width = mlWidth;
                                }
                            }
                        }
                    }
                }
            }
            if(nr>0){ document.onclick = oxid.nav.close; }
        }
    },

    // Top navigation init
    topnav : function(trigger, window) {
        var _trigger = document.getElementById(trigger);
        var _window = document.getElementById(window);
        if(_window && _trigger){
        	_trigger.onmouseover = _trigger.onfocus = oxid.nav.open(false) ;
        	_trigger.onmouseout  = _trigger.onblur  = oxid.nav.starttm;
            _window.onmouseover = _window.onfocus = oxid.nav.stoptm ;
            _window.onmouseout  = _window.onblur  = oxid.nav.starttm;
        }
        document.onclick = oxid.nav.close;
    },

    // Blank
    blank : function(id) {
        var _a  = document.getElementById(id);

        if(_a) {
            _a.setAttribute('target','_blank');
        }
    }

};