var sort_ison = 0;
function sort_over( obj ) {
    var pos = new Array();
    var sortbox = document.getElementById('sortbox');
    sortbox.style.display = '';
    pos = mxFindPos( obj );
    sortbox.style.top = (pos[1] - 7) + 'px';
    sortbox.style.left = (pos[0] - 6) + 'px';
    //alert('posx: ' + pos[0] + ' posy: ' + pos[1] );
    build_shadow( sortbox, sortbox.offsetLeft, sortbox.offsetTop, sortbox.offsetWidth, sortbox.offsetHeight );
    sort_in();
}
function sort_in() {
    sort_ison = 1;
}
function sort_out_real() {
    if ( ! sort_ison ) {
        var sortbox = document.getElementById('sortbox');
        sortbox.style.display = 'none';
    }
}
function sort_out() {
    sort_ison = 0;
    setTimeout(sort_out_real, 200);
}
function mxFindPos( obj ) {
    var p, x, y;
    x = obj.offsetLeft;
    y = obj.offsetTop;
    p = obj;
    while ( p = p.offsetParent ) {
        //p = p.offsetParent;
        //p.style.backgroundColor = 'pink';
        x += p.offsetLeft;
        y += p.offsetTop;
    }
    return new Array( x, y );
}

function build_shadow( obj, x, y, w, h ) {
    var t = document.getElementById('sortbox_shadow_1');
    if ( t ) {
        return;
    }
    var t1 = document.createElement('div');
    t1.style.width = '4px';
    t1.style.height = ( h - 8 ) + 'px';
    t1.style.position = 'absolute';
    t1.style.zIndex = 2;
    t1.style.left = ( - 8 ) + 'px';
    t1.style.top = (  4 ) + 'px';
    t1.style.background = 'transparent url(/images/shadow1.png) repeat-y 1px 0px';
    t1.setAttribute('id','sortbox_shadow_1');
    obj.appendChild(t1);
    var t2 = document.createElement('div');
    t2.style.width = '8px';
    t2.style.height = '6px';
    t2.style.position = 'absolute';
    t2.style.zIndex = 2;
    t2.style.left = ( - 8 ) + 'px';
    t2.style.top = ( h - 4) + 'px';
    t2.style.background = 'transparent url(/images/shadow2.png) 0px 0px no-repeat';
    obj.appendChild(t2);
    var t3 = document.createElement('div');
    t3.style.width = ( w - 8 ) + 'px';
    t3.style.height = '6px';
    t3.style.position = 'absolute';
    t3.style.zIndex = 2;
    t3.style.left = '0px';
    t3.style.top = ( h - 4) + 'px';
    t3.style.background = 'transparent url(/images/shadow3.png) repeat-x 0px 0px';
    obj.appendChild(t3);
    var t4 = document.createElement('div');
    t4.style.width = '8px';
    t4.style.height = '6px';
    t4.style.position = 'absolute';
    t4.style.zIndex = 2;
    t4.style.left = ( - 8 + w ) + 'px';
    t4.style.top = ( h - 4) + 'px';
    t4.style.background = 'transparent url(/images/shadow4.png) 0px 0px no-repeat';
    obj.appendChild(t4);
    var t5 = document.createElement('div');
    t5.style.width = '4px';
    t5.style.height = ( h - 8 ) + 'px';
    t5.style.position = 'absolute';
    t5.style.zIndex = 2;
    t5.style.left = ( - 4 + w) + 'px';
    t5.style.top = (  4 ) + 'px';
    t5.style.background = 'transparent url(/images/shadow5.png) repeat-y 0px 0px';
    obj.appendChild(t5);
}

function sort_select( id ) {
    var t = document.getElementById('sort_value');
    t.value = id;
    t = document.getElementById('offers_form');
    t.submit();
}

