$(function(){
	/* Sliding boxes */
	$('.box h2, .sidebar .box h3').each(function(){
		var  $header = $(this),
			$box = $(this).parent('.box'),
			$bottom = $box.children('.bottom'),
			$collapse = $('<span class="collapse">Collapse/Expand</span>').appendTo($header);
		
		if ($box.hasClass('hide')) {
			$collapse.toggleClass('change');
			$bottom.css({ display: 'none' });
		}
		
		$header.css({
			cursor: 'pointer'
		}).click(function(event){
			if ($(event.target).is('a')) return true;
			
			$collapse.toggleClass('change');
			$bottom.slideToggle();
		});
	});
	
	/* Disappearing messages */
	$('.message').css({ cursor: 'pointer' }).click(function(){ $(this).slideUp(); });
	
	/* Table striping */
	$('tbody tr:odd').addClass('alt');
	
	/* WYSIWYG editor */
	$('.wysiwyg').each(function(){
		var  $this = $(this),
			$remove = $('<span>(<a href="#">remove WYSIWYG editor?</a>)</span>').appendTo($this.siblings('label')).find('a').click(function(){
				$.sMarkUpRemove($this);
				$remove.remove();
				return false;
			}).end();
		
		$this.sMarkUp('html', 300);
	});
	
	/* Fake checkboxes */
	$('input[type=checkbox]').each(function(){
		var  $fake = $('<span class="checkbox" />').click(function(){
				$(this).toggleClass('active');
				changeCheckboxStatus($this);
			}),
			$this = $(this).after($fake).css({ display: 'none' });
	});
	
	/* Clickable list items for checkboxes */
	$('.checkboxes li').css({ cursor: 'pointer' }).click(function(event){
		if ($(event.target).is('span') || $(event.target).is('input.checkbox')) return true;
		
		$(this).find('span.checkbox').toggleClass('active');
		changeCheckboxStatus($(this).find('input[type=checkbox]'));
	});
	
	function changeCheckboxStatus($checkbox) {
		if ($checkbox.is(':checked')) $checkbox.attr('checked', false);
		else $checkbox.attr('checked', true);
	}
});
