//function showSlide(rowNumber, id){
//    var rowName=  ".relatedAlbumsRow" + rowNumber;
//    var buttonName = ".btn_" + id;
//    $(buttonName).hide('slow');
//    $(rowName).show('slow');
//    $("#showMoreItem" + rowNumber).show('slow');
//}

//function hideSlide(rowNumber, id) {


//  var rowName;
//  while (rowNumber > 1)
//  {
//    rowName=  ".relatedAlbumsRow" + rowNumber;
//    $(rowName).hide('slow');
//    rowNumber--;
//  }
//  var buttonName ="item_" + id;
//  $(buttonName).show('slow');
//
//}


$(document).ready(function() {

    var toShowPerTime = 4;
    $('.RelatedAlbumSection').attr("ItemsToShowPerTime", toShowPerTime);

    function hideItems(section) {
        var done = 1;
        section.children('.relatedItem').each(function() {
            if (done > section.attr("ItemsToShowPerTime")) {
                $(this).hide();
            } else {
                if ($(this).is(":hidden")) {
                    $(this).fadeIn("slow");
                }
            }
            done = done + 1;
        });
        if (toShowPerTime >= done) {
            section.children(".options").html("");
        }

        done = 1;
    }

    hideItems($('.artistSection'));
    hideItems($('.albumRelation'));
    hideItems($('.labelSection'));
    function showHideLinks(clickedobj) {
        var itemsVisible = clickedobj.parent().parent().children('.relatedItem:visible').size();

        if (itemsVisible > toShowPerTime) {
            clickedobj.parent().children('.options .hidelink').html("<a href=\"#\" class=\"hideResults\">Hide</a>");
        } else {
            clickedobj.parent().children('.options .hidelink').html("");
        }

        if (itemsVisible >= clickedobj.parent().parent().children('.relatedItem').size()) {
            clickedobj.parent().children('.options .showMore').hide();
        } else {

                clickedobj.parent().children('.options .showMore').show();
        }


    }

    $('.showMore').click(function() {
        var toShow = parseFloat($(this).parent().parent().attr("ItemsToShowPerTime")) + toShowPerTime;

        $(this).parent().parent().attr("ItemsToShowPerTime", toShow);
        hideItems($(this).parent().parent());
        showHideLinks($(this));

        return false;
    });

    $('.hideResults').live("click", function() {
        var toShow = parseFloat($(this).parent().parent().parent().attr("ItemsToShowPerTime")) - toShowPerTime;

        $(this).parent().parent().parent().attr("ItemsToShowPerTime", toShow);

        hideItems($(this).parent().parent().parent());
        showHideLinks($(this).parent());
        return false;
    });

});
