$(function(){
    //Document Load
    var thisURL = window.location;
    var fontsize=$.cookie("font_size");
    var contrast=$.cookie("contrast");
    var textonly=$.cookie("text_only");
    if (BrowserDetect.browser=="Explorer") { } else {
        $(".Phuse_PanelContainingDiv td").each(function(){ $(this).css("width",$(this).parent().parent().parent().attr("width")+"px"); });
    }
    $("#atff").parent("div").hide();
    $(".poll .poll_result:first").hide();
    if (contrast=="high") { $("body").attr("id","contrast"); }
    if (fontsize) { $("body").attr("class",fontsize); }
    $(".poll_result").each(function(){ var totalResult=$(this).children(".vote_count").text();$("div",this).not(".clear").text(totalResult); });
    //$(".loginform .textbox:eq(1)").append("<input type\"text\" id=\"password_text\" value=\"Password\" />");
    $(".grey_panel_brand .content h3.right_aligned").each(function(){
        var textReplace = $(this).html();
        textReplace = textReplace.replace("info@liverpoollink.org.uk","<a href=\"mailto:info@liverpoollink.org.uk\">info@liverpoollink.org.uk</a>");
        $(this).html(textReplace);
    });
    $("#news_results .search_result_item").each(function(){
        $("h3 a[href^='http://www.liverpoollink.org.uk/news/']",this).parent().parent().show();
    });
    $(".SearchButton").noText();
    $(".archive_item:lt(3)").hide();
    var pagingItems = Math.ceil(eval($(".paging_item").length-8)/5);
    var countItems = 1;
    $(".paging").append("<strong>Page:</strong> ");
    while (countItems<=pagingItems+1) {
        $(".paging").append("<span id=\""+countItems+"\">"+countItems+"</span>");
        countItems++;
    }
    $(".news_item p,.news_item span,.news_item font").removeAttr("style").removeAttr("face").removeAttr("size").removeClass("MsoNormal");
    $("#publications_search li").each(function(){ var text=$(this).text(); $(this).replaceWith("<option value=\""+text+"\">"+text+"</option>\n"); });
    var publications_search = $("#publications_search").html();
    $("#publications_search").replaceWith("<select id=\"publications_search\">"+publications_search+"</select>");
    $("#publications_search").prepend("<option value=\"all\" selected=\"selected\">--- Select category ---</option>");
    var dropdownHTML = $("#publications_search").html();
    $("#publications_search").replaceWith("<div class=\"publications_search_box\">View publications by category <select id=\"publications_dropdown\">"+dropdownHTML+"</select></div>");
    $("#C81calMain + table,#C751calMain + table").hide();

    //User Interaction
    $("a[href*='submit-an-issue']").addClass("iframe").fancybox({"frameWidth":700,"frameHeight":550,"hideOnContentClick":false,"overlayOpacity":0.6});
    $("a[href*='equality-and-diversity-monitoring-form']").addClass("iframe").fancybox({"frameWidth":700,"frameHeight":550,"hideOnContentClick":false,"overlayOpacity":0.6});
    $("#small").click(function(){ $("body").removeClass("large_text").addClass("small_text"); $.cookie("font_size","small_text"); });
    $("#medium").click(function(){ $("body").removeClass("small_text").removeClass("large_text"); $.cookie("font_size",null); });
    $("#large").click(function(){ $("body").removeClass("small_text").addClass("large_text"); $.cookie("font_size","large_text"); });
    $("#high_contrast").toggle(function(){ $("body").attr("id","contrast");$(this).text("Reset Contrast");$.cookie("contrast","high"); },function(){ $("body").removeAttr("id");$(this).text("High Contrast");$.cookie("contrast","low"); });
    $("#text_only").toggle(function(){ $("#CSS_5").attr("href","http://www.liverpoollink.org.uk/res/css/Text.css"); $(this).text("Reset Graphics"); },function(){ $("#CSS_5").attr("href","http://staging.ph-creative.com/sites/LCVS/res/css/Site.css"); $(this).text("Text Only"); });
    $("#email_friend").click(function(){ window.location="mailto:?body="+thisURL;return false; });
    $("#help").click(function(){ window.location="http://www.liverpoollink.org.uk/help/"; });
    $(".print").click(function(){ window.print(); });
    $(".archive_item,.feed_item,.publication").fullLink();
    $("#archive_news_feed + .paging span").click(function(){
        $(".paging span").removeClass("active");
        $(this).addClass("active");
        var pageNumber=$(this).attr("id")-1;
        $(".paging_item").animate({"top":"-"+eval(pageNumber*145)+"px"});
    });
    $("#publications + .paging span").click(function(){
        $(".paging span").removeClass("active");
        $(this).addClass("active");
        var pageNumber=$(this).attr("id")-1;
        $(".paging_item").animate({"top":"-"+eval(pageNumber*660)+"px"});
    });
    $("#publications_dropdown").change(function(){
        var thisCategory = $("option:selected",this).val();
        $(".paging_item").hide();
        $(".paging_item .details span:contains('"+thisCategory.slice(0,-1)+"')").parent().parent().parent().fadeIn();
        if (thisCategory=="all") { $(".paging_item").fadeIn(); }
    });
    $(".get_involved #step02,.get_involved #step03,.get_involved #step04").hide();
    $(".get_involved #step01 .next").click(function(){ $(".get_involved #step01").hide();$(".get_involved #step02").fadeIn(); });
    $(".get_involved #step02 .next").click(function(){ $(".get_involved #step02").hide();$(".get_involved #step03").fadeIn(); });
    $(".get_involved #step03 .next").click(function(){ $(".get_involved #step03").hide();$(".get_involved #step04").fadeIn(); });
    $(".calendar").parent().attr("bgcolor","");
    $(".calendar").parent().parent().parent().parent().addClass("link_calendar");
    $(".link_calendar").removeAttr("style").css("width","14%");
    $(".calendar_selectedday").removeAttr("style").css("width","100%");
    $(".calendar_nextprev:first").addClass("prev");
    $(".calendar_nextprev:last").addClass("next");
    $(".link_calendar + table").addClass("calendar_schedule");
    $(".calendar_schedule tr td table tr td div div div div:first").css("background-color","#009534");
    $("#ddlTrusts").change(function(){
        var thisCategory = $("option:selected",this).val();
        $(".trusts div,.trusts .choose").hide();
        $(".trusts #"+thisCategory).fadeIn();
        if (thisCategory=="NULL") { $(".trusts div").hide();$(".trusts .choose").fadeIn(); }
    });
});
