var price_entry;
var recommend_entry;
var bs = {};
bs.asort = function(hash,key){
  return hash.sort(function(a, b){
    return (a[key] > b[key]) ? 1 : -1;
  });
}
bs.arsort = function arsort(hash,key){
  return hash.sort(function(a, b) {
    return (a[key] < b[key]) ? 1 : -1;
  });
}

$("#tabs").idTabs(function(id,list,tabs){
    if (recommend_entry == null && $("#recommend div[id^='plan']").length > 0) {
        recommend_entry = $("#recommend div[id^='plan']");
    }
    if (id == "#price" ) {
        if (price_entry == null) {
            price_entry = $("#recommend div[id^='plan']");
            var ids = new Array();
            for (var i=0; i<price_entry.length; i++) {
                var tmp = $(".price p span", price_entry[i]);
                //var tmp = $(".price p", price_entry[i]);
                if (tmp.length) {
                    var tmp2 = $(tmp).get(0).innerHTML;
                    if (jQuery.trim(tmp2) == "") {
                        tmp2 = price_entry[i].id;
                    }
                } else {
                    tmp2 = price_entry[i].id;
                }
                var entry = {};
                entry.price = parseInt(tmp2.replace(/,/, ''));
                entry.val = price_entry[i];
                ids.push(entry);
            }
            ids = bs.asort(ids, 'price');
            //ids.asort('price');
            var tmp_entry = [];
            for(var i=0; i<ids.length; i++) {
                tmp_entry.push(ids[i].val);
            }
            price_entry = $(tmp_entry);
        }
        $("#price").append(price_entry);
    } else {
        $("#recommend").append(recommend_entry);
    }
    $("a",tabs).removeClass("selected").filter("[href='"+id+"']").addClass("selected");
    for(i in list)
        $(list[i]).hide();
    $(id).fadeIn();
    return false;
});


