
(function() {

    //Shows welsh add to basket button if lang is Welsh. C# fix preferable.
    function fixButtonLang() {
        var string = $("#miniNav li").eq(0).find("a").html();
        if (string === "Saesneg") { //If we are in welsh language

            //Fix the twitter link to welsh
            $("#twitter a").attr("href", "http://twitter.com/#!/Cefnogi_Cynnar")   
                
            var inputs = $("#content input.submit");
            inputs.each(function() {
                $(this).attr("src", "/images/btn_add_to_basket_cym.png");
            });
        }
    }

    //Itterate through the blank more links on the your stories page and fix them if blank
    function fixMoreLinks() {
        var links = $(".list .more");
        links.each(function() {
            if ($(this).html() === "") {
                $(this).html("<span>More</span>");
                var href = $(this).parents(".item").find('h1 a').attr("href");
                $(this).attr('href', href);
            };
        });
    }

    jQuery(document).ready(function() {

        init();
        fixButtonLang();
        fixMoreLinks();
        Cufon.replace('.bannerTitle, h1, h2, h3, h4, h5', { fontFamily: 'VAGRounded Lt' });

        $('#allMaterialList .item input').each(function() {
            $(this).change(function(index) {
                var index = $('#allMaterialList .item input').index(this);
                if ($(this).is(':checked')) {
                    $('#allMaterialList .item .inner').eq(index).slideDown();
                } else {
                    $('#allMaterialList .item .inner').eq(index).slideUp();
                }
            });
        });
    });

}).call(this);
