function saveCookie() {
	var pageStr	= '';

	$('#col_1, #col_2, #col_3').find('div.bin').not('#bin_gm_banner, #bin_t36_mov_banner')
	.trigger('update')
	.each(function() {

		pageStr		+= 	 $(this).attr('id').replace(/bin_/, '')+';'
						+$(this).data('state')+';'
						+$(this).data('column')+';'
						+$(this).data('row')+'|';
	});
	$.post('inc/savecookie.php', { 's' : pageStr, 'l' : langID });
}

$(document).bind('ready.dragAndDrop', function() {

	// Update event data object
	$('#col_1, #col_2, #col_3').find('div.bin').bind('update', function() {
		var state	= ($(this).data('state')!=undefined && $(this).data('state')!='')
						? $(this).data('state')
						: ($(this).find('div.bincontent').css('display')=='none')
							? 'up'
							: 'down';
		$(this)
		.data('state', state)
		.data('column', $(this).parent().attr('id').replace(/col_/, ''))
		.data('row', (parseInt($(this).parent().children().index(this)+1)));
	}).trigger('update');

	// Init collapse
	$('#col_1, #col_2, #col_3').find('div.binheader').each(function() {
		$('<div class="'+(($(this).parents('div.bin').data('state')=='up') ? 'arrow_out' : 'arrow_in')+'"></div>')
		.prependTo(this)
		.click(function() {
			if ($(this).parents('div.bin').data('state')=='down') {
				$(this)
				.removeClass('arrow_in')
				.addClass('arrow_out')
				.parents('div[id^="col_"]')
				.height('auto')
				.end()
				.parents('div.bin')
					.data('state', 'up')
					.children('div.bincontent').slideUp('500', function() {
						//$(this).parents('div[id^="col_"]').trigger('fixHeight');
						saveCookie();
					});
			} else if ($(this).parents('div.bin').data('state')=='up') {
				$(this)
				.removeClass('arrow_out')
				.addClass('arrow_in')
				.parents('div[id^="col_"]')
				.height('auto')
				.end()
				.parents('div.bin')
					.data('state', 'down')
					.children('div.bincontent').slideDown('500',  function() {
						//$(this).parents('div[id^="col_"]').trigger('fixHeight');
						saveCookie();
					});
			}
		});
	});

	// Init CSS for Drag
	$('#col_1, #col_2').find('div.binheader').css('cursor', 'move');

	// Create reset button
	$('<a href="inc/resetcookie.php" class="text">reset homepage</a>').prependTo('#searchbar');

	var height	= 0;

	// Init drag
	$('#col_1, #col_2').bind('fixHeight', function() {
		height	= 0;
		$(this).siblings('div[id^="col_"]').andSelf()
		.height('auto')
		.each(function() {
			if ($(this).height()>height) {
				height = $(this).height();
			}
		})
		.height(height);
	}).trigger('fixHeight')
	.sortable({
		appendTo				: $('#columns'),
 		zIndex					: 10000,
 		placeholder 			: 'containerPlaceHolder',
		forcePlaceholderSize 	: true,
		connectWith				: $('#col_1, #col_2'),
		items					: 'div.bin',
		handle					: $('div.binheader'),
		tolerance				: 'guess',
		cursorAt				: 'top',
		start					: function(event, ui) {
			$(ui.placeholder).addClass($(ui.item).attr('class').replace(/bin /, '')+'Light');
			$(ui.item).children('div.bincontent').css('background-color', '#ffffff');
		},
		update					: function(event, ui) {
			saveCookie();
		},
		receive					: function(event, ui) {
			// Don't let the columns get empty, at least 1 container MUST be present
			if ($(ui.sender).children().length==0) {
				$(ui.sender).sortable('cancel');
			}
		},
		stop 					: function(event, ui) {
			$(ui.item).children('div.bincontent').css('background-color', '');
			$(ui.item).parent().trigger('fixHeight');
		}
	});

	// Add a change event, if not IE6, since IE6 has bug wich already autoresizes
	if (!IE6) {
		$('#col_1, #col_2').bind('sortchange', function(event, ui) {
			$(ui.item).parent().trigger('fixHeight');
		});
	}

});