function toggleDashboard() {
	var $dashboard = $('#dashboard');
	var $wrapper = $dashboard.closest('#wrapper');
	$wrapper.removeClass('editable');
	if($dashboard.is(':visible')) {
		$dashboard.slideUp();
		$('.column').sortable('disable');
	} else {
		$dashboard.slideDown();
		$wrapper.addClass('editable');
		$('.column').sortable('enable');
	}
}

function saveColumns() {
	var items = new Array();
	$('.column').each(function(column) {
		var $column = $(this);
		items[column] = $column.attr('id')+";";
		$column.children().each(function() {
			items[column] = items[column] + $(this).attr('rel') + ';';
		});
	});
	$.post( '/files/saveDashboard.cfm', { items: items.toString() } ); 
}

$(function() {
	$('#dashboardOpener').click(function () {
		toggleDashboard();
		$(this).find('.arrow').toggleClass('active');
	});
	$('.buttonSmall.arrowButton').live('click', function () {
		var $widgetDetails = $(this).parents('.ribbonInner').children('.details');
		$widgetDetails.animate({ height: "toggle", opacity: "toggle"} );
		$(this).toggleClass('expanded');
	});
	$('.buttonSmall.minButton').live('click', function () {
		var $widgetContent = $(this).parents('.widgetTop').next(0).children('.content');
		if($widgetContent.is(':visible')) {
			$widgetContent.slideUp();
			if($(this).prev(0).hasClass('expanded')) {
				$(this).prev(0).click();
			}
		} else {
			$widgetContent.slideDown();
		}
		$(this).toggleClass('expanded');
	});
	
	$('.buttonSmall.closeButton').live('click', function () {
		var $widget = $(this).closest('.objectWrapper');
		$widget.animate({ height: "toggle", opacity: "toggle" }, function() {
			$(this).show().appendTo('#dashboard > .column');
			saveColumns();
		});
	});
	
	var $websitesPanel = $('#mijnWebsitesPanel');
	$('#mijnWebsites').focus(function() {
		$websitesPanel.slideDown(250);
		$('#mijnWebsites').addClass('open');
	});
	$('#mijnWebsites').blur(function() {
		$websitesPanel.delay(250).slideUp(250);
		$('#mijnWebsites').removeClass('open');
	});
	$('#mijnWebsites').click(function() { $('#mijnWebsites').focus(); });
	
	$("label.inlined + input[type=text]").each(function (type) {
		$(this).focus(function () {
			$(this).prev("label.inlined").addClass("focus");
		});
		$(this).keypress(function () {
			$(this).prev("label.inlined").addClass("has-text").removeClass("focus");
		});
		$(this).blur(function () {
			if($(this).val() == "") {
				$(this).prev("label.inlined").removeClass("has-text").removeClass("focus");
			}
		});
	});

	
	$('.column').sortable('disable');
	
	
});
