$(document).ready(
	function () {
		$('a.closeEl').bind('click', toggleContent);
		$('div.groupWrapper').Sortable(
			{
				accept: 'groupItem',
				helperclass: 'sortHelper',
				activeclass : 	'sortableactive',
				hoverclass : 	'sortablehover',
				handle: 'div.itemHeader',
				tolerance: 'pointer',
				onChange : function(ser)
				{
				},
				onStart : function()
				{
					$.iAutoscroller.start(this, document.getElementsByTagName('body'));
				},
				onStop : function()
				{
					serialize();
					$.iAutoscroller.stop();
					
				}
			}
		);
	}
);
var toggleContent = function(e)
{
	var targetContent = $('div.itemContent', this.parentNode.parentNode);
	
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(400);
		$(this).html('Hide');
		this.parentNode.parentNode.id = this.parentNode.parentNode.id.replace('MINUS',''); 
		//alert("id:" + this.parentNode.parentNode.id );
		serialize();
		
	} else {
		targetContent.slideUp(400);
		$(this).html('Show');
		this.parentNode.parentNode.id = this.parentNode.parentNode.id + 'MINUS'; 
		//alert("id:" + this.parentNode.parentNode.id );
		serialize();
		
	}
	return true;
};

function serialize(s)
{
	serial = $.SortSerialize(s);
	$.cookie("cooBWYLayout",serial.hash, { expires: 2 , path: '/', domain: '.bwy.org.uk' } );
	//alert(serial.hash);
};