var $j = jQuery.noConflict();

$j(document).ready(function()
{
	try
	{
		$j("#v_toggle").click(function(event){
			event.preventDefault();
			$j("#vertical_slide").slideToggle("normal");
		});

		$j("#twitter_box").keyup(function(){


			var maxLength = 140;
			var length = this.value.length;

			if(length >= maxLength) {

				$j(this).val($j(this).val().substring(0,140));

			}
			length = this.value.length;
			var length_left = maxLength-length;
			$j("#twitter_nr_letter").html(length_left);

		});

	}
	catch(o){}
});


function inciar_ordenacao(id_elem)
{
	 //ordenacao_vertical
	 $j("#"+id_elem).sortable({
		axis: 'y',
		cursor: 'move',
		opacity: 0.6,
		zIndex: 5,
		handle: '.hand',
		placeholder: 'ordenacao_v2_placeholder',
		forcePlaceholderSize: true,
		containment: '#content',
		helper: 'clone'
	});
	$j("#"+id_elem).disableSelection();
}

function inciar_ordenacao_xy(id_elem)
{
	 //ordenacao_xy
	 $j("#"+id_elem).sortable({
		cursor: 'move',
		opacity: 0.6,
		zIndex: 5,
		handle: '.hand',
		placeholder: 'ordenacao_v2_placeholder',
		forcePlaceholderSize: true,
		containment: '#content',
		helper: 'clone'
	});
	$j("#"+id_elem).disableSelection();
}

function actualizar_ordem(id_elem)
{
	var lista_elem = $j("#"+id_elem).sortable('serialize');
	var new_list = '';

	if(lista_elem && lista_elem != '')
	{
		var new_list_array = lista_elem.split('&');
		for(var i=0; i<new_list_array.length; i++)
		{
			if(i>0){
				new_list += "|";
			}
			new_list += "id_"+new_list_array[i].substring(5);
		}
	}
	document.getElementById("ordem_visual").value = new_list;
}


function no_action()
{
	//cancela a acção de seguit o href de um <a>
	return false;
}
/*
exemplo de ordenacao com Jquery

//JS//
$j("#ordcena").sortable({
	axis: 'y',
	cursor: 'move',
	opacity: 0.6,
	zIndex: 5,
	stop: function(event, ui) {
		alert($j("#ordcena").sortable('serialize'));

	}

});
$j("#ordcena").disableSelection();
//HTML//
	$html .= "<ul id=\"ordcena\">";
	$html .= "<li id=\"id_1\" style=\"border: 1px solid red;\"><a href=\"#\">as<a/> a</li>";
	$html .= "<li id=\"id_2\" style=\"border: 1px solid red;\">c</li>";
	$html .= "<li id=\"id_3\"style=\"border: 1px solid red;\">r</li>";
	$html .= "</ul>";
*/
