$().ready(function(){
	if($("html").height() > ($("#contenido").height()+$("#contenido").offset().top)){
		$("#contenido").height($("html").height()-$("#contenido").offset().top+0);
	}
	if($("#contenido").height() > $("#menu").height()) $("#menu").height($("#contenido").height());
	if($(".generic-section").length && $("#contenido").height() > $(".generic-section").height()) $(".generic-section").height($("#contenido").height() + ($("#contenido").offset().top - $(".generic-section").offset().top)- $("#todo").offset().top);
	//$("#imagesfade").height()
	$('#imagesfade').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: "220px" });
	
	var addmore = 0;
	$(".addmore").click(function(){
		addmore++;
		
		var newFile = $("#add-more-images").clone();
		newFile.insertBefore(this);
		
		newFile.attr("id", "addmore-"+addmore);
		newFile.find("input").attr("name", "data[Articulo][imagen][]");
		newFile.attr("style", "");
		newFile.find("a").click(function(){
			$(this).parent().remove();
			$("#imagelabel").height($("#imagelabel").parent().height());
		});
		//$("#add-more-images").html();}
		
		$("#imagelabel").height($("#imagelabel").parent().height());
		return false;
	});
	
	if($("#sort-categories")){
		$('#sort-categories').Sortable({
				accept : 		'sort-item',
				opacity: 		0.8,
				fx:				200,
				axis:			'vertically',
				opacity:		0.4,
				revert:			true,
				onStop : function(){
						serial = $.SortSerialize('sort-categories');
						$.ajax({
							url: "/category/changeorder/",
							type: "POST",
							data: serial.hash,
							success: function(feedback){
								//$('#debug').html(feedback);
							}
						});
					}
		});
	}
	
	if($("#sort-entries")){
		$('#sort-entries').Sortable({
				accept : 		'sort-item',
				opacity: 		0.8,
				fx:				200,
				axis:			'vertically',
				opacity:		0.4,
				revert:			true,
				onStop : function(){
						serial = $.SortSerialize('sort-entries');
						$.ajax({
							url: "/entry/changeorder/",
							type: "POST",
							data: serial.hash,
							success: function(feedback){
								//$('#debug').html(feedback);
							}
						});
					}
		});
	}
});