		$(function(){
			// configura drag and drop
			$(".recebeDrag").sortable({
				connectWith: ['.recebeDrag'],
				placeholder: 'dragHelper',
				scroll: true,
				scrollSpeed:50,
				revert: true,
				cursor: "move",
				axis: "y",
				opacity: 0.6,
				stop: function( e, ui ) {
					salvaCookie();
				}
			});
			// restaura
			$('.restaurar').click(function(){
				Func1('1,2,3,4,5,6,7,8');
				salvaCookie();
			});
			// sobe boxes
			$('.lnk-subir').click(function(){
				var ordem=$('#dropesquerda').sortable('toArray');
				var box=$(this).parent().parent().parent().attr('id');
				var novaordem="";
				for(i=ordem.length-1;i>=0;i--){
					if(ordem[i]!=""){
						if(ordem[i]!=box){
							novaordem=ordem[i]+","+novaordem;
						}else{
							novaordem=ordem[i-1]+","+novaordem;
							novaordem=box+","+novaordem;
							i--;
						}
					}
				}
				novaordem=novaordem.substring(0,novaordem.length-1);
				
				$("#"+box+":visible").slideUp("slow");
				setTimeout("Func1('"+novaordem+"')", 500);
				setTimeout("$('#"+box+"').slideDown('slow')", 200);
				setTimeout("salvaCookie()", 500);
			});
			// desce boxes
			$('.lnk-descer').click(function(){
				var ordem=$('#dropesquerda').sortable('toArray');
				var box=$(this).parent().parent().parent().attr('id');
				var novaordem="";
				for(i=0;i<ordem.length;i++){
					if(ordem[i]!=""){
						if(ordem[i]!=box){
							novaordem=novaordem+","+ordem[i];
						}else{
							novaordem=novaordem+","+ordem[i+1];
							novaordem=novaordem+","+box;
							i++;
						}
					}
				}
				novaordem=novaordem.substring(1,novaordem.length);
				$("#"+box+":visible").slideUp("slow");
				setTimeout("Func1('"+novaordem+"')", 500);
				setTimeout("$('#"+box+"').slideDown('slow')", 200);
				setTimeout("salvaCookie()", 500);
			});
			// minimizar boxes
			$('.lnk-minimizar').click(function(){
				var ul = $(this).parent().parent().parent().find('ul');
				if( $(ul).is(':visible') ) {
					$(ul).slideUp();
					$(this).html('[ + ]');
				} else {
					$(ul).slideDown();
					$(this).html('[ - ]');
				}
				return false;
			});
			// remover box
			$('.lnk-remover').click(function(){
				$(this).parent().parent().parent().fadeOut();
				return false;
			});
			// configuração inicial do cookie
			if( $.cookie('df_draganddrop') ) {
				var ordem = $.cookie('df_draganddrop').split('|');
				// posiciona boxes nos containers certos
				$('#dropesquerda div.itemDrag').each(function(){
					if( ordem[0].search( $(this).attr('id') ) == -1 ){
						$('#dropesquerda').append($(this));
					}
				});
				// ordena containers
				var esquerda = ordem[0].split(',');
				for( i = 0; i<= esquerda.length; i++ ){
					$('#dropesquerda').append($('#'+esquerda[i]));
				}
				
			} else {
				Func1('1,2,3,4,5,6,7,8');
				salvaCookie();
				$.cookie('df_draganddrop', '', { expires: 7, path: '/' });
			}
		});	
		// salva cookie
		var salvaCookie = function() {
			var ordem = $('#dropesquerda').sortable('toArray');
			var stringordem="";
			for(i=0;i<ordem.length;i++){
				if(ordem[i]!=""){
					stringordem=stringordem+","+ordem[i];
				}
			}
			stringordem=stringordem.substring(1, stringordem.length);
			$.cookie('df_draganddrop', stringordem);
		};
		function Func1(teste) {
			esquerda=teste.split(',');
			var i=0;
			for( i = 0; i<= esquerda.length; i++ ){
				$('#dropesquerda').append($('#'+esquerda[i]));
			}
			
		} 
