function list_products(category_id){

    $("#products_holder").hide();

    $.ajax({
          processData: false,
          type: "POST",
          url: "/products/list_products/" + category_id,
          cache: false,
          error: function(){
            $("#products_holder").html("sorry, an error occurred!");
            //$("#products_holder").wait(500).fadeIn('slow');
            $("#products_holder").show();
          },
          success: function(result){
            $("#products_holder").html(result);
            $("#products_holder").append('<div class="clearall"><!----></div>');
            $("#products_holder").addClass('offstage').show();

            initSIFR(); // update all the sIFR stuff

            $('.prod_detail').click(function(){
                var clicked_id_array = $(this).attr('id').split('_');
                var product_id = clicked_id_array[1];
                get_product(product_id);
                return false;
            });

            $("#products_holder").removeClass('offstage').hide();
            //$("#products_holder").wait(500).fadeIn('slow');
            $("#products_holder").show();

          }
            
    });
}

function get_product(product_id){
    $.ajax({
          processData: false,
          type: "POST",
          url: "/products/get_product/" + product_id,
          cache: false,
          error: function(){
            $("#products_holder").html("sorry, an error occurred!");
          },
          success: function(result){
            $("#products_holder").html(result);

            // update the sIFR stuff
            sIFR.replace(helveticaNeueThin, {
              selector: 'h1',
              css: '.sIFR-root {color: #000000;}',
              wmode: "transparent"

            });

            sIFR.replace(helveticaNeueThin, {
              selector: 'h2',
              css: '.sIFR-root {color: #000000;}',
              wmode: "transparent"

            });

            sIFR.replace(helveticaNeueThin, {
              selector: 'h3',
              css: '.sIFR-root {color: #000000;}',
              wmode: "transparent"
            });

            $('.load_category').click(function(){
                var category_id = $(this).attr('rel');
                if($('#flashHeader').length)
                {
                    load_category(category_id);
                    return false;
                } else {
                    return true;
                }
            });

            $('.print_product').click(function(){
                var clicked = $(this);
                var url = clicked.attr('href');
                open_new_window(url);
                return false;
            });

            // gallery image swapper
            $('.gallery_swap').click(function(){
                var clicked = $(this);
                $('#product_main_image').attr("src",clicked.children('img').attr('rel'));
                return false;
            });

          }
        });
}

function load_category(category_id) {
    //alert('hey hey! category_id = '+ category_id);
    document.getElementById('flashHeader').gotoCategory(null,category_id);
}


function open_new_window(url)
{
    window.open(url,url,'width=600,height=500,resizable=yes,scrollbars=yes');
}

