var newHeightPanel;
var paddingPanel;
var idPanel;


$(document).ready(function() {
	
	// E' l'elenco delle didascalie delle foto.
	var captionimg = $(".captionsubimage");
	
	// E' l'elenco dei blocchi dei commenti.
	arrCommenti = $(".commentspanel");
	
	// Didascalie.
	for (var i = 0; i < captionimg.length; i++) {
		var padding = parseInt($(captionimg[i]).css("padding-left")) + parseInt($(captionimg[i]).css("padding-right")) + $(captionimg[i]).children("img").width() + parseInt($(captionimg[i]).children("span").css("margin-left")) + 8;
		var newW = $(captionimg[i]).parent().width() - padding;
		jQuery(captionimg[i]).children('span').css('width', newW);
	}
	
	// Finestra riepilogativa.
	$(".comments_view_container_header a, .comments_view_container_header span").each( function() {
		$(this).hover( function() { 
			if(navigator.platform.indexOf("iPad") == -1) 
				jQuery('.comments_view_container_header span').css('color', '#999999');
			}, function() {  
			if (navigator.platform.indexOf("iPad") == -1) 
			jQuery('.comments_view_container_header span').css('color', '#FFFFFF');
		});
	});
	addShowHideCapability();
});


/*
 * Chiude la finestra riepilogativa dei commenti.
 */

function closeCommentsView() {
	$("#comments_view_container").hide();
	$("#layer_opacity_comments").hide();
}


function addShowHideCapability() {

	// Pulsante di chiusura blocco commenti.
	$(".closecomment a").each( function() {

		// Memorizza l'altezza del blocco.
		var numPanelId = $(this).attr("idP");
		var objPanel = $("#commentpanelcontainer_" + numPanelId);
		objPanel.data("PanelHeight", objPanel.children(".commentpanelbox").height());

		// Evento click del pulsante aperutra/chiusura del blocco.
		$(this).click( function() {

			if( $(this).hasClass('panelClose') ) {				
				numPanelHeight = objPanel.data("PanelHeight");

				// Apre il pannello.
				$(this).removeClass('panelClose');
				objPanel.animate( {height: (numPanelHeight)+"px"}, 250, "linear", function() {
					$("#commentpanelcontainer_" + numPanelId + " .commentsplus").hide();
					$("#commentpanelcontainer_" + numPanelId + " .commentsblockmore").show();	
				});

			} else {	
				// Altezza del primo commento.
				numPanelHeight = objPanel.children('.commentpanelbox').children('.commentstextbox:eq(0)').height();
				numPanelPadding = parseInt(objPanel.children('.commentpanelbox').children('.commentstextbox:eq(0)').css('padding-top')) + parseInt(objPanel.children('.commentpanelbox').children('.commentstextbox:eq(0)').css('padding-bottom'));
				
				// Chiude il pannello.
				$(this).addClass('panelClose');
				objPanel.animate({height: (numPanelHeight+numPanelPadding)+"px"}, 250, "linear", function() {
					$("#commentpanelcontainer_" + numPanelId + " .commentsplus").show();
					$("#commentpanelcontainer_" + numPanelId + " .commentsblockmore").hide();
				});
			}
		});
	});
}









