$(document).ready(function(){
    if ($.cookie('details') == null) {
        $.cookie('details', 'hide', {
            expires: 9999, path: '/'
        });
    }
    if ($.cookie('win') == null) {
        $.cookie('win', 'new', {
            expires: 9999, path: '/'
        });
    }
});

$(document).ready(function(){
    if ($.cookie('details') == 'hide') {
        $("#detail-toggle").attr('checked', '');
        $("div.entry-min-discussion").show();
		$("span.expand").show();
    }
    else {
        $("div.entry-extended-discussion").show();
        $("#detail-toggle").attr('checked', 'on');
		$("span.collapse").show();
    }
    $('#detail-toggle').click(function(e){
        if ($('#detail-toggle:checked').val() == 'on') {
	        $("div.entry-extended-discussion").show();
	        $("div.entry-min-discussion").hide();
			$("span.expand").hide();
			$("span.collapse").show();
            $.cookie('details', 'show', {
                expires: 9999, path: '/'
            });
        }
        else {
	        $("div.entry-extended-discussion").hide();
	        $("div.entry-min-discussion").show();
			$("span.expand").show();
			$("span.collapse").hide();			
            $.cookie('details', 'hide', {
                expires: 9999, path: '/'
            });
        }
        
    });
    
    if ($.cookie('win') == 'new') {
        $("#new-window-toggle").attr('checked', 'on');
        $("[target]").attr("target", "_blank");
    }
    else {
        $("#new-window-toggle").attr('checked', '');
        $("[target]").attr("target", "_self");
    }
    $('#new-window-toggle').click(function(e){
        if ($('#new-window-toggle:checked').val() == 'on') {
            $("[target]").attr("target", "_blank");
            $.cookie('win', 'new', {
                expires: 9999, path: '/'
            });
        }
        else {
            $("[target]").attr("target", "_self");
            $.cookie('win', 'same', {
                expires: 9999, path: '/'
            });
        }
    });
});

$(document).ready(function(){
    $("span[@class=expand] > a").each(function(index){
        $(this).bind("click", function(){
            id = this.id.split('-')[1];
            $("div[@id=cl-" + id + "] > div[@class=entry-discussion] > table > tbody > tr > td > div[@class=entry-min-discussion]").toggle();
            $("div[@id=cl-" + id + "] > div[@class=entry-discussion] > table > tbody > tr > td > div[@class=entry-extended-discussion]").toggle();
			$("a[@id=ex-" + id + "]").parent().toggle();
			$("a[@id=co-" + id + "]").parent().toggle();
        });
    })
    $("span[@class=collapse] > a").each(function(index){
        $(this).bind("click", function(){
            id = this.id.split('-')[1];
            $("div[@id=cl-" + id + "] > div[@class=entry-discussion] > table > tbody > tr > td > div[@class=entry-min-discussion]").toggle();
            $("div[@id=cl-" + id + "] > div[@class=entry-discussion] > table > tbody > tr > td > div[@class=entry-extended-discussion]").toggle();
			$("a[@id=ex-" + id + "]").parent().toggle();
			$("a[@id=co-" + id + "]").parent().toggle();
        });
    })	
});

$(document).ready(function(){
    $('#about_button').click(function(e){
		$('#about_text').toggle();
		$('#about_collapse').toggle();
		$('#about_expand').toggle();
	})
});
