jQuery(document).ready(function($j) {
    $j('[id^="drop_menu"]').hide().mouseout(function() {
        $j(this).hide();
    });
    $j('[id^="parent_menu"]').mouseover(function() {
        pageID = $j(this).attr('id').replace('parent_menu_', '');
        $j('#drop_menu_' + pageID).show();
    }).mouseout(function() {
        pageID = $j(this).attr('id').replace('parent_menu_', '');
        $j('#drop_menu_' + pageID).hide();        
    });

    $j('#pricelist tbody tr, #abon tbody tr').each(function() {
        tds = $j(this).children('td');
        if (tds.length > 1) {
            $j(this).addClass('HIDE_ME').hide();
        } else {
            tds.css('cursor', 'pointer').click(function() {
                smth = $j(this).parent();
                smth.siblings('tr.HIDE_ME').hide().end().siblings('tr.HIDE_THEM').removeClass('HIDE_THEM');
                if (!smth.hasClass('HIDE_THEM')) {
                    smth.addClass('HIDE_THEM');
                    smth.nextAll('tr').each(function() {
                        if ($j(this).hasClass('HIDE_ME') > 0) {
                            $j(this).show();
                        } else {
                            return false;
                        }
                    });
                } else {
                    smth.removeClass('HIDE_THEM');
                }
            });
        }
    });

    jQuery.rotate_img = function() {
        curr_img = $j('[id^="img_rotate_"]:eq(0)');
        next_img = curr_img.next().css({'opacity': 0, 'top': curr_img.position().top - ( curr_img.height() / 2 - curr_img.next().height() / 2), 'left': curr_img.position().left - ( - curr_img.width() / 2 + curr_img.next().width() / 2), 'position': 'absolute', height: curr_img.height()}).show();
        curr_img.animate({'opacity': 0}, 3000, function() {
            $j(this).appendTo('#image_rotator').hide()
        });
        next_img.animate({'opacity': 1}, 3000);
    }
    
    if ($j('#_img_rotate_interval').length == 1) {
        setInterval('jQuery.rotate_img()', $j('#_img_rotate_interval').val() * 1000);
    }
    
    $j('#post-it').show().dialog({
        autoResize: true,
        width: 300,
        modal: true
    });
});