$(document).ready(function(){

   $('#headsub h2').click(function() {
	  var content = $(this).parents('.portlet-wrapper').find('#box5');
	  if (content.css('display') == 'none') {
	     content.slideDown('fast');
             //$("#headsub").removeClass("sortright");
             //$("#headsub").addClass("sortdown");
             
             //$(this).addClass("tester");

             $(this).parent().removeClass("sortright")
             $(this).parent().addClass("sortdown");

             //$(this).parent().prev.css('margin', '0');

             //$(this).prev().addClass("sort2");
	     //$(this).text('down');

	     var id = $(this).parents('.portlet-wrapper').attr('id');
		$.cookie(id, 'shown');
	  } else {
		content.slideUp('fast');
                //$(this).parent().prev().css('margin', '0 0 2px 0');
                //$(this).parent().prev.css('margin', '0');
                //$(this).parent().prev.css('padding', '5px');

                $(this).parent().removeClass("sortdown")
                $(this).parent().addClass("sortright");

		var id = $(this).parents('.portlet-wrapper').attr('id');
		$.cookie(id, 'hidden');	
	  }
   });

   $('.headsub h2').each(function(){

      $(this).click(function(){	 
         var content = $(this).parents().next('#box5');

          if (content.css('display') == 'none') {
	     content.slideDown('fast');

             $(this).parent().removeClass("sortright")
             $(this).parent().addClass("sortdown");

	     var id = $(this).parents('.portlet-wrapper').attr('id');
		$.cookie(id, 'shown');
	  } else {
		content.slideUp('fast');
                $(this).parent().removeClass("sortdown")
                $(this).parent().addClass("sortright");

		var id = $(this).parents('.portlet-wrapper').attr('id');
		$.cookie(id, 'hidden');	
	  }
      });
   });

   // Hide the sub menus
   $('ul.menu li ul').hide();

    $(".unitTitle").click(function() {
        $(this).next(".link-list").slideToggle(600);
        if (!$(this).hasClass('expanded')) 
        { 
           $(this).find('#headsub1').text('(Hide)');
           $(this).addClass('expanded');
        }   
        else
        {
           $(this).find('#headsub1').text('(Show)');
           $(this).removeClass('expanded');
        }
    });
});

