/**
 * find the previous HTMLElement with the given type of node
 *
 * @param   HTMLElement   o
 * @param   string        typeOfNode
 * @return  HTMLElement
 */
function getPreviousNode ( o , typeOfNode ) {
    if ( arguments[2] == null ) {
        o = o.previousSibling ;
    }

    while ( o && o.nodeName.toLowerCase() != typeOfNode.toLowerCase () ) {
        c = o.childNodes ;

        for ( var i = ( c.length - 1 ) ; i >= 0 ; i-- ) {
            pSub = getPreviousNode ( c[i] , typeOfNode , false )  ;

            if ( pSub  ) {
                return pSub ;
            }
        }
        o = o.previousSibling;
    }

    if ( o ) {
        return o ;
    } else {
        return '' ;
    }
};

/**
 * find the next HTMLElement with the given type of node
 *
 * @param   HTMLElement   o
 * @param   string        typeOfNode
 * @return  HTMLElement
 */
function getNextNode ( o , typeOfNode ) {
    if ( arguments[2] == null ) {
        o = o.nextSibling ;
    }

    while ( o && o.nodeName.toLowerCase() != typeOfNode.toLowerCase () ) {
        c = o.childNodes ;

        for ( var i = 0 ; i < c.length ; i++ ) {
            pSub = getNextNode ( c[i] , typeOfNode , false )  ;

            if ( pSub  ) {
                return pSub ;
            }
        }
        o = o.nextSibling;
    }

    if ( o ) {
        return o ;
    } else {
        return '' ;
    }
};