jQuery.noConflict();

var sidebar =
{
    init: function()
    {
        jQuery("#sidebar div[@id$=Content]").each(function(i){
            jQuery(this).addClass("sidebarContent");

            var id = this.id.replace(/Content/g, "");
            sidebar.createClickEvent(id);
        });
        this.initRightCol();
        slideMiddleCol();
        jQuery("#postContent").slideToggle("fast");
    },

    initRightCol: function()
    {
        jQuery("#respond").click(function() {
            sidebar.handleLeaveCommentClick();
         });
    },

    createClickEvent: function(id)
    {
        jQuery("#" + id + "Link").click(function() {
            sidebar.handleClick(id);
         });
    },

     handleClick: function(id)
    {
        id += "Content";        
		var prevID = jQuery.cookie('SliderAccordionID');
		if( id != prevID && jQuery("#" + prevID).css("display") == 'block' )
			jQuery("#" + prevID).slideToggle("fast");	
        var st = getToggledState(jQuery("#" + id).css("display"));
        jQuery("#" + id).slideToggle("fast");
		jQuery.cookie("SliderAccordionID", id, {expires: 30, path: '/'});       
    },

    handleLeaveCommentClick: function()
    {
        jQuery("#respondForm").slideToggle("slow");
    },

    focusSearchForm: function()
    {
        if( jQuery("#searchContent").css("display") == "block" )
        {
            jQuery("#s").focus();
        }
    }
};

function slideMiddleCol()
{
    jQuery("#middleCol").slideToggle("slow");
}

function slideRightCol()
{
	var st = getToggledState(jQuery("#theComments").css("display"));	
	jQuery("#theComments").slideToggle("slow");
}

function getToggledState(state)
{
    if( state == "block" )
        return "none";
    else
        return "block";
}

jQuery(document).ready(function()
{
    sidebar.init();
});