/*
Funcionalidad desarrollada por:
Jorge Fernández Heredia
Feb. 2011

Esta funcionalidad se incrementará según la necesidad.

Ejm: al presionar el botón de editar portlet, se deberá llamar a una función
que obtenga el contenido del área de edición, en vez de los actuales alerts.
*/
$(function() {
	$( ".column" ).sortable({
		connectWith: ".column",
		cursor: 'move',
		handle: '.portlet-header'
	});

	$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
		.find( ".portlet-header" )
			.addClass( "ui-widget-header ui-corner-all" )
			/* Activa los íconos de edición y colapsado del portlet
				.prepend( "<span class='ui-icon ui-icon-minusthick minimizar_portlet'></span><span class='ui-icon ui-icon-pencil editar_portlet'></span>")
			*/
			.end()
		.find( ".portlet-content" );

	$( ".portlet-header .editar_portlet" ).click(function() {
		$( this ).toggleClass( "ui-icon-pencil" ).toggleClass( "ui-icon-cancel" );
		if($(this).parents('.portlet:first').find('.edit_area').css("display") == 'none' && $(this).parents('.portlet:first').find('.edit_area').css("visibility") == 'hidden')
		{
			$(this).parents('.portlet:first').find('.edit_area').css('display', 'block');
			$(this).parents('.portlet:first').find('.edit_area').css('visibility', 'visible');
			
			alert('Abrieno interface de edición');
		}else{
			$(this).parents('.portlet:first').find('.edit_area').css('display', 'none');
			$(this).parents('.portlet:first').find('.edit_area').css('visibility', 'hidden');
			
			alert('Cerrando interface de edición');
		}
	});

	$( ".portlet-header .minimizar_portlet" ).click(function() {
		$(this).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
		$(this).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
		
		$(this).parents('.portlet:first').find('.ui-icon-cancel').removeClass('ui-icon-cancel').addClass('ui-icon-pencil');
		
		if($(this).parents('.portlet:first').find('.ui-icon-pencil').css("display") == 'none' && $(this).parents('.portlet:first').find('.ui-icon-pencil').css("visibility") == 'hidden')
		{
			$(this).parents('.portlet:first').find('.ui-icon-pencil').css('display', 'block');
			$(this).parents('.portlet:first').find('.ui-icon-pencil').css('visibility', 'visible');
		}else{
			$(this).parents('.portlet:first').find('.ui-icon-pencil').css('display', 'none');
			$(this).parents('.portlet:first').find('.ui-icon-pencil').css('visibility', 'hidden');
		}
		
		$(this).parents('.portlet:first').find('.edit_area').css('display', 'none');
		$(this).parents('.portlet:first').find('.edit_area').css('visibility', 'hidden');
	});

	/*$( ".column" ).disableSelection();*/
});
