//--- data

function StartCharting() {
    //change tab data
    $(".tab").bind("click", function() {
        $('.marketPrices tr').removeClass("currentGraph"); // Rob 29.01.10:
        var data = $(this).attr("dataId");
        loadData(data);
        addClass("tab", this);
    })
    //set legend
    changePricePerWeight(1);

    //add selected state to first class
    addClass("tab", "ul.tabs li:first-child a");

    BindTabButton("cattleIcon", "mkpCattle", "myDataSource_cows_1");
    BindTabButton("sheepIcon", "mkpSheep", "myDataSource_sheep_1");
    BindTabButton("pigsIcon", "mkpPigs", "");

    // Rob 29.01.10:

    $('[id$=cattleIcon]').click(function() {
        $('.marketPrices tr').removeClass("currentGraph");
        $('[id$=row_steers]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $('[id$=tab_cows_1]').click(function() {
        $('[id$=row_steers]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $('[id$=tab_cows_2]').click(function() {
        $('[id$=row_heifers]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $('[id$=tab_cows_3]').click(function() {
        $('[id$=row_bulls]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("[id$=tab_cows_4]").click(function() {
        $("[id$=row_cattle]").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("[id$=tab_sheep_1]").click(function() {
        $('[id$=row_new_lambs]').addClass("currentGraph");
        $('[id$=trMPOSL]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $('[id$=sheepIcon]').click(function() {
        $('[id$=marketPrices tr]').removeClass("currentGraph");
        $('[id$=row_new_lambs]').addClass("currentGraph");
        $('[id$=trMPOSL]').addClass("currentGraph");
        changePricePerWeight(1);
    });

    $('[id$=tab_sheep_2]').click(function() {
        $('[id$=row_ewes]').addClass("currentGraph");
        changePricePerWeight(2);
    });
}

function BindTabButton(iconToBind, tabToShow, dataSourceToLoad) {
    $('[id$=' + iconToBind + ']').click(function() {
        $('[id$=cattleIcon]').removeClass("selected");
        $('[id$=sheepIcon]').removeClass("selected");
        $('[id$=pigsIcon]').removeClass("selected");
        $('[id$=' + iconToBind + ']').addClass("selected");

        $('[id$=mkpCattle]').hide();
        $('[id$=mkpSheep]').hide();
        $('[id$=mkpPigs]').hide();
        $('[id$=' + tabToShow + ']').show();
        //new chart work
        $('[id$=mkpCattle_tabs]').hide();
        $('[id$=mkpSheep_tabs]').hide();
        $('[id$=' + tabToShow + '_tabs]').show();
        if (dataSourceToLoad != '') {
            loadData(dataSourceToLoad);
            $('[id$=chart]').show();
            addClass("tab", "ul.tabs li:first-child a");
        } else {
            $('[id$=chart]').hide();
            init = false;
        }
    });
}
function changePricePerWeight(_val) {
    if (_val == 1) {
        $('dd[id$=key-price]').text('p/kg');
    }
    else {
        $('dd[id$=key-price]').text('£/head');
    }
}




