[jQuery] Converting an interesting script function to jquery:

[jQuery] Converting an interesting script function to jquery:


if(f = $('product_sort_'+p_nId)){
        for(var i=0; i<f.options.length; i++){
        if(f[i].selected){
            var temp = new Option(f[i].text,f[i].value,true);
            if(p_nDirection == 0 && f[i+1] != null ){
                f[i] = new Option(f[i+1].text,f[i+1].value,false);
                f[i+1] = temp;
            }
            else if(p_nDirection == 1 && f[i-1] != null ){
                f[i] = new Option(f[i-1].text,f[i-1].value,false);
                f[i-1] = temp;
            }
            break;
            }
        }
    }
Here is my version of jquery it shows where I get stuck:
    if(dom.query('#product_sort_'+p_nId)){
        dom.query('#product_sort_'+p_nId+' option').each(function(i){
        if(this.selected){
            var temp = new Option(this.text,this.value,true);
            //dom.query(this)??
         if(p_nDirection == 0 && dom.query(this).next() != null ){
                //**this is where I get stuck: this =
                this = new
Option(dom.query(this).next().text,dom.query(this).next().value,false);
                dom.query(this).next() = temp;
            }
            else if(p_nDirection == 1 && dom.query(this).prev() != null ){
                dom.query(this) = new
Option(dom.query(this).prev().text,dom.query(this).prev().value,false);
                dom.query(this).prev() = temp;
            }
        }
        });
    }