//--- data

$(document).ready(function() {
    $("a.zoom1").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 850,
        'frameHeight': 720
    });
    //change tab data
    $(".tab").bind("click", function() {
    	$("#marketPrices tr").removeClass("currentGraph"); // Rob 29.01.10:
        var data = $(this).attr("id");
        var _data = data.split('-');
        loadData(_data[1]);
        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:

    $("#cattleIcon").click(function () {
        $("#marketPrices tr").removeClass("currentGraph");
        $("#row-steers").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_cows_1").click(function () {
        $("#row-steers").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_cows_2").click(function () {
        $("#row-heifers").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_cows_3").click(function () {
        $("#row-bulls").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_cows_4").click(function () {
        $("#row-cattle").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_sheep_1").click(function () {
        $("#row-new-lambs").addClass("currentGraph");
        $("#trMPOSL").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#sheepIcon").click(function () {
        $("#marketPrices tr").removeClass("currentGraph");
        $("#row-new-lambs").addClass("currentGraph");
        $("#trMPOSL").addClass("currentGraph");
        changePricePerWeight(1);
    });

    $("#tab-myDataSource_sheep_2").click(function () {
        $("#row-ewes").addClass("currentGraph");
        changePricePerWeight(2);
    });
});

function BindTabButton(iconToBind, tabToShow, dataSourceToLoad) {
    $("#" + iconToBind).click(function() {
        $("#cattleIcon").removeClass("selected");
        $("#sheepIcon").removeClass("selected");
        $("#pigsIcon").removeClass("selected");
        $("#" + iconToBind).addClass("selected");

        $("#mkpCattle").hide();
        $("#mkpSheep").hide();
        $("#mkpPigs").hide();
        $("#" + tabToShow).show();
        //new chart work
        $("#mkpCattle_tabs").hide();
        $("#mkpSheep_tabs").hide();
        $("#" + tabToShow + "_tabs").show();
        if (dataSourceToLoad != '') {
            loadData(dataSourceToLoad);
            $("#chart").show();
            addClass("tab", "ul.tabs li:first-child a");
        } else {
            $("#chart").hide();
            init = false;
        }
    });
}
function changePricePerWeight(_val) {
	if (_val == 1)
	{
		$('dd#key-price').text('p/kg');
	}
	else
	{
		$('dd#key-price').text('£/head');
	}
}




