$( document ).ready( function() {

    if( category_id > 0 ) {

      $( "#packageselect" ).load( linkurl + "/PostClassified-/", 
                                  { category_id : category_id,
                                    uid         : uid,
                                    noedit      : noedit }, 
                                    reattach_events );

    } else {

      attach_events( 0 );
      $( "#category_0" ).show();
      $( "#loadingcategory" ).hide();
    }
});

function attach_events( id ) {

    if( $( "#category_" + id ).length != 0 ) {

        $( "#category_" + id ).change( function() {
    
            var category_id = $( this ).attr( 'value' );
            if( category_id > -2 ) {

                //User selected go back
                if( category_id == -1 ) {

                    var category_id = $( "#category_" + (id-1) ).attr( 'value' );
                }

                //$( "#packages_section" ).slideUp( 2000, function() {

                  $( "#packageselect" ).load( linkurl + "/PostClassified-/", 
                                              { category_id : category_id,
                                                uid         : uid }, 
                                              reattach_events );
                //});
            }
        });

        attach_events( id+1 );
    }
}

function reattach_events() {

  //$( "#packages_section" ).slideDown( 2000 );
  attach_events( 0 );
}
