function carousel_initCallback(carousel) {
    var mycarousel = carousel;
}
function countSliderLI() {
    var c = $("#mycarousel li").length;
    return c;
}

$(document).ready(function() {

    $("#mycarousel li a.hassub").live("click", function() {

        var id = $(this).attr("id");

        $(this).prepend('<img src="/img/loader.gif" alt="loader" class="myloader" />');

        $.post("/ajax/subcats2.php?cid="+id.substring(1),"",function(data,status) {
          if (data != '') {
             $(".jcarousel-skin-ie7").remove();
             $("#media_holder").prepend('<ul id="mycarousel" class="jcarousel-skin-ie7">'+data+'</ul>');
             var count = countSliderLI();
             if (count > 3) {
                $('#mycarousel').jcarousel({wrap: 'circular',scroll: 4});
             } else {
                $('#mycarousel').jcarousel({wrap: null,scroll: 4});
             }
          }
          $(".mycarouselhome").show();
        });
        
        return false;
    });
    
    $("#mycarousel li a.physio, #catlistphysio").live("click", function() {
        Shadowbox.open({
            content:    '/ajax/physio.php',
            player:     "iframe",
            title:      "",
            height:     450,
            width:      600
        });

        return false;
    });

    $(".mycarouselhome a").bind("click", function() {

        $.post("/ajax/subcats2.php?cid=0","",function(data,status) {
          if (data != '') {
             $(".jcarousel-skin-ie7").remove();
             $("#media_holder").prepend('<ul id="mycarousel" class="jcarousel-skin-ie7">'+data+'</ul>');
             var count = countSliderLI();
             if (count > 3) {
                $('#mycarousel').jcarousel({wrap: 'circular',scroll: 4});
             } else {
                $('#mycarousel').jcarousel({wrap: null,scroll: 4});
             }
          }
          $(".mycarouselhome").hide();
        });

        return false;
    });

    $(".add2workout.remove").live("click", function() {
        $(this).parent().remove();
        if ($("#timeline").children("li").length == 0) {
            $("#savebtn").hide();
        }
    })

    $(".delworkout").bind("click", function() {
       var id = $(this).attr("id").substr(3);

       var del = confirm("Press OK to delete this workout.");
       if (del == 1) {
           $.post("/ajax/delworkout.php?wid="+id,"", function(data) {
               if (data.success == 1) {
                   $("#rw"+id).fadeOut(1500);
               }
           },'json');
       }

       return false;
    });

    $(".editworkout").bind("click", function() {
        var id = $(this).attr(id).substring(1);
        alert(id);
    });

});

function add2workout(clip) {

    $.post("/ajax/add2workout.php?vid="+clip,"",function(data) {  
        $(".timeline").append(data);
        $("#timeline").sortable("refresh");
        $("#savebtn").show();
    });

    return false;
}

function saveworkout(wid) {

    var order = [];

    var i = 0;
    $("#timeline").children("li").each(function() {
        order[i] = $(this).attr("id").substring(2);
        i++;
    });

    $.post("/ajax/saveworkout.php?wid="+wid,"clips="+order+"&",function(data) {
        if (data.success == 1) {
            $(".success").show().delay(3000).fadeOut(1000);
        }
    },'json');

}

function WPCheckout() {

    var cart = $("#cartId").val();
    var amt = $("#amount").val();

    $.post("/ajax/worldpay.php","cart="+cart+"&amount="+amt, function(data) {
        if (data.url_togoto != '') {
            window.location = data.url_togoto+'&successURL=http://www.healthclubtv.com/ordersuccess';
        }
    },"json");

}
