var global_contentType = "important";

$(document).ready(function(){
													 
$("h1.top_title").hide();

//	foto gallery

	$(".media_container a").mouseover(function(){
		$("em",this).css({"display": "none"});
	});


	$(".media_container a").mouseout(function(){
		$("em",this).css({"display": "block"});
	});
	

	var y_media_gallery = 0;
	var step_media_gallery = 195;
	var curr_step_media_gallery = 1;
	var quanti_media = $("#media_gallery .media_container a").size();
	var tot_steps_media = parseInt(quanti_media/6);
	var quanti_media_out = quanti_media - (tot_steps_media*6);
	var additional_modules = parseInt(quanti_media_out/2);
	if(quanti_media_out>0) {
		tot_steps_media++;
	}

	$("#tit_media_gallery .down").click(function(event){
		event.preventDefault();
		if (curr_step_media_gallery < tot_steps_media) {
			y_media_gallery = y_media_gallery - step_media_gallery;
			curr_step_media_gallery = curr_step_media_gallery + 1;
			$("#tit_media_gallery .up").css({"opacity": "1"});    
			
			if (curr_step_media_gallery==tot_steps_media) {
				$("#tit_media_gallery .down").css({"opacity": "0.2"});
				$("#media_gallery .media_container div").animate({"top": (y_media_gallery+(additional_modules*65)-34) + "px"},300,"swing");
			} else {
				$("#media_gallery .media_container div").animate({"top": y_media_gallery + "px"},300,"swing");
			}
		}
	});

	$("#tit_media_gallery .up").click(function(event){
		event.preventDefault();
		if (curr_step_media_gallery > 1) {
			y_media_gallery = y_media_gallery + step_media_gallery;
			curr_step_media_gallery = curr_step_media_gallery - 1;
			$("#tit_media_gallery .down").css({"opacity": "1"});
			$("#media_gallery .media_container div").animate({"top": y_media_gallery + "px"},300,"swing");
			if (curr_step_media_gallery==1) {
				$("#tit_media_gallery .up").css({"opacity": "0.2"});
			}
		}
	});

//	blog emergenti

	var x_blog_emergenti = 0;
	var step_blog_emergenti = 768;
	var curr_step_blog_emergenti = 1;
	var quanti_blog_emergenti = $("#blog_emergenti div a.highslide").size();
	var tot_steps_blog_emergenti = parseInt(quanti_blog_emergenti/4);

	$("#blog_emergenti_title .right").click(function(event){
		//alert(curr_step_blog_emergenti + " - " + tot_steps_blog_emergenti + " - " + quanti_blog_emergenti);
		event.preventDefault();
		if (curr_step_blog_emergenti < tot_steps_blog_emergenti) {
			x_blog_emergenti = x_blog_emergenti - step_blog_emergenti;
			curr_step_blog_emergenti = curr_step_blog_emergenti + 1;
			$("#blog_emergenti_title .left").css({"opacity": "1","left": "180px"});
			$("#blog_emergenti div").animate({"left": x_blog_emergenti + "px"},500,"swing");
			if (curr_step_blog_emergenti==tot_steps_blog_emergenti) {
				$("#blog_emergenti_title .right").css({"opacity": "0.2","left": "172px"});
			}
		}
	});

	$("#blog_emergenti_title .left").click(function(event){
		event.preventDefault();
		if (curr_step_blog_emergenti > 1) {
			$("#blog_emergenti_title .right").css({"opacity": "1","left": "180px"});
			x_blog_emergenti = x_blog_emergenti + step_blog_emergenti;
			curr_step_blog_emergenti = curr_step_blog_emergenti - 1;
			$("#blog_emergenti div").animate({"left": x_blog_emergenti + "px"},500,"swing");
			if (curr_step_blog_emergenti==1) {
				$("#blog_emergenti_title .left").css({"opacity": "0.2","left": "172px"});
			}
		}
	});

	toolbarBindings(); // bindo i comportamenti della toolbar (filtri)
	postClickBindings(); // bindo il comportamento al click di un post

//	segnala un blog

	var segnala_open = 0;

	$("#open_segnala").click(function(event){
		event.preventDefault();													
		if (segnala_open == 0) {
			$("#segnala_panel").animate({"top": "-220px"},400,"swing");
			$("#open_segnala").addClass("is_open");
			segnala_open = 1;
		} else {
			$("#segnala_panel").animate({"top": "0px"},400,"swing");
			$("#open_segnala").removeClass("is_open");
			segnala_open = 0;
		}
	});

	/**
	 * aggiornamento numero post/blog
	 */
	$.ajax({
		type:'POST',
		url:DAILYME.blog_post_count_url,
		data:'',
		success: function(dReturn)
		{
			var dati = eval("("+dReturn+")");
			$("#n_post strong").html(dati.n_post);
			$("#n_blog strong").html(dati.n_blog);
		}
	});

	



	/**
	 * Nasconde le tendine quando si clicca all'esterno di esse
	 */
	$(document).mousedown(function(e) {
		if(!$(e.target).is(".tendine_container ul")) {
			$(".tendine_container ul").hide();
		}
	});

	filtriOptionsBindings();
	sidebar_binding();
	
	morePostsBinding();
	
	/**
	 * Invio AJAX del form "segnala un blog"
	 */
	segnalaBlog();
	
	orologio();
	var orologioTimeout = setInterval('orologio()',60000);

}); // fine domready


function segnalaBlog()
{
	$("#form_segnala").submit(function(event){
		event.preventDefault();
		$.post($(this).attr("action"), $(this).serialize(), function(data){
			$("#form_segnala").remove();
			$("#open_segnala").after(data);
			segnalaBlog();
		}, "html");
	});
}


function morePostsBinding()
{

	$(".infinite-scroll").click(function(){
		$(this).hide();
		$("#loading_altri_post").show();
		var offset = $(".post").length;
		if(offset>95) // prevent from loading more than 100 posts
		{
			$("#loading_altri_post").hide();
			return false
		}
		
		var url_offset = dailyme_current_view_settings == 'important' ? (offset+5) : offset;
		var url = $(this).attr("href") + "/offset/" + url_offset + "?" + new Date().getTime();
		$.ajax({
			type:'GET',
			url:url,
			success:function(dReturn)
			{
				var posts_html = $(dReturn).find(".post");
				var topics_html = $(dReturn).find("#topics_html_response").html();
				var js_html = $(dReturn).find("#wrapped_js").html();
				$("#left_column").append(posts_html);
				$("#no_topic_result").remove();
				$("#mid_column").append(topics_html);
				$("body").append(js_html);
				// appendPageBody(dReturn,true);
				var last_to_show = offset + 10;

				for(var i=offset;i<last_to_show;i++) {
					$(".post").eq(i).hide();
				}

				for(var i=offset;i<last_to_show;i++) {
					$(".post").eq(i).show();
				}
				
				$("#main_container").scrollTo($(".post").eq(offset),800);
				$("#loading_altri_post").hide();
				
				if ($(".post").length>90  || !dailyme_more_posts) {
					$(".infinite-scroll").hide();
				} else {
					$(".infinite-scroll").show();
				}
				
				ajaxUpdateClicks();
				sidebar_binding();
			}	
		});
		return false;
	});

}


function toolbarBindings()
{
//	toolbar switches

	$("#btn_per_data, #btn_per_fonte, #btn_per_tag, #btn_per_category").click(function(event){
		$(this).hide();
		$("#top_area").removeClass("panel_open");
	});

	$("#btn_filtri").click(function(event){
		if($(this).hasClass("on"))
		{
			$(this).removeClass("on");
			$("#top_area").removeClass("panel_open"); // IE6 > #top_area{ margin-bottom:24px } - altri browser > #form_filtri { margin-bottom:24px }
			$("#form_filtri").hide();
		}
		else
		{
			$(this).addClass("on");
			$("#top_area").addClass("panel_open"); // IE6 > #top_area{ margin-bottom:24px } - altri browser > #form_filtri { margin-bottom:24px }
			$("#form_filtri").show();
		}

	});
	
	$("#search_submit, #btn_cancella, #btn_filtra, #btn_recenti, #btn_importanti, .pager a").click(function(event){
		$("#top_area").removeClass("panel_open");																			
	});
	
	
	
//	$("#searchform").submit(function(event){
//		$("#top_area").removeClass("panel_open");
//	});
}

function postClickBindings()
{
	/**
	 * Registra i click sui link dei post nel database.
	 */
	$(".postLink").click(function(event) {
		var id = $(this).attr("class").match(/.*post-(\d+)/)[1];
		$.get(DAILYME.click_url + id);
	});
}

/**
 * 1a chiamata ajax: setta i parametri
 * 2a chiamata ajax: carica effettivamente i contenuti
 * (non so xke, ma symfony non ne vuole sapere di usare il layout giusto
 * in caso di chiamata ajax + redirect,
 * la soluzione è 2 chiamate ajax.. verrà usata estensivamente qui - teo)
 * @param contentType
 * @return
 */
function loadContent(contentType)
{
	global_contentType = contentType;
	resetTb();
	appendPreloader();
	$.ajax({
		type:'GET',
		url:DAILYME.base_url+'set/order/'+contentType+'?r='+Math.random(),
		success:function(dReturn)
		{
			// ajaxReloadContent();
			appendPageBody(dReturn,true);
		}	
	});
}

function submitFilters()
{
	var data_start = $("#yearFilter").val() + $("#monthFilter").val() + $("#dayFilter").val();
	var data_end = $("#yearFilter_to").val() + $("#monthFilter_to").val() + $("#dayFilter_to").val();

	if (($("#periodFilter").val() == 1) && (data_end < data_start))
	{ // controllo intervallo date in caso di selezione periodo
		$("#per_data em").show();
		$("#giorno, #mese, #anno, #giorno_to, #mese_to, #anno_to").css({"color":"#c00"});

	} else {

		resetTb();
		appendPreloader();
		var formData = $("#form_filtri input").serialize();
		$.ajax({
			type:'POST',
			data:formData,
			url:DAILYME.filters_url,
			success: function(dReturn) { 
//				ajaxReloadContent(true);
				appendPageBody(dReturn,true);
			}
		});

	}
}


function resetFilters(filterType)
{
	$("#per_keyword a, #per_data a, #per_fonte a").removeClass("cat_checked");
	$(".data_container label").css({"color": "#777"});
	$(".data_container input").removeAttr('disabled').css({"color": "#333"});
	$("#form_filtri")[0].reset();
	$("#categoryFilter, #authorFilter, #todayFilter, #yesterdayFilter, #periodFilter").val("");
	resetTb();
	appendPreloader();
	var reset_filters_url = DAILYME.reset_filters_url;
	if(filterType)
	{
		reset_filters_url += '/type/'+filterType;
	}
	reset_filters_url += '?r=' + Math.random();
	$.ajax({
		type:'GET',
		data:'',
		url:reset_filters_url,
		success:function(dReturn) {
//			ajaxReloadContent(true);
			appendPageBody(dReturn,true);
		}
	});
	return false;
}


function setButtons()
{
	if(global_contentType == 'recent')
	{
		$("#btn_recenti").addClass("on");
		$("#btn_importanti").removeClass("on");
	}
	else
	{
		$("#btn_recenti").removeClass("on");
		$("#btn_importanti").addClass("on");
	}
}

function appendPageBody(htmlData,reloadTb)
{
	$(".preloader").remove();
	$("#altri_post").show();
	$(".ajaxColumn").remove();
	$("#bottom_area").prepend(htmlData);
	sidebar_binding();
//	iBox.checkTags(document.body, 'a');
	ajaxUpdateClicks();
	postClickBindings();
	if(reloadTb)
	{
		ajaxReloadToolbar();
	}
	removeCrawlerLinks();
}


function removeCrawlerLinks()
{
	$(".crawler_links").remove();
}


function ajaxReloadContent(reloadToolbar)
{
	var dest_url = DAILYME.base_url;
	dest_url += "?async=true";
	if($.browser.msie && $.browser.version=="6.0")
	{
		// this to prevent IE6 from caching response,
		dest_url += "&r="+Math.random();
	}
	
	if(DAILYME.twitter_timeout)
	{
		clearTimeout(DAILYME.twitter_timeout);
	}
	
	$.ajax({
		type:'GET',
		url:dest_url,
		success:function(dReturn)
		{ 
			appendPageBody(dReturn,reloadToolbar);
		}
	});
}



function ajaxReloadToolbar()
{
	var dest_url = DAILYME.reload_toolbar_url + '?r=' + Math.random();
	$.ajax({
		type:'GET',
		url:dest_url,
		success:function(dReturn)
		{ 
			$("#toolbar").remove();
			$("#form_filtri").remove();
			$("#btn_filtri").removeClass("on");
			$("#top_area").removeClass("panel_open"); // IE6 > #top_area{ margin-bottom:24px } - altri browser > #form_filtri { margin-bottom:24px }
			$("#form_filtri").hide();
			$("#toolbar_container").html(dReturn);
			toolbarBindings();
			filtriOptionsBindings();
			init(); // unitip
		}
	});
}


function ajaxUpdateClicks()
{
	var post_ids = [];
	//	Estrae i post-id
	$(".n_clicks").each(function(idx, el){
		if ($(this).attr("id")) {
			var id = $(el).attr("id").match(/click-(\d+)/);
			if (id && id[1]) {
				post_ids.push(id[1]);
			}

			// cerco anche tra gli emergenti
			var id = $(el).attr("id").match(/click-em-(\d+)/);
			if (id && id[1]) {
				post_ids.push(id[1]);
			}
		}
	});
	$.get(DAILYME.dynamic_url, {"post_id[]": post_ids}, function(data){
		$.each(data, function(id, value){
			if (value) {
				var id1 = "#click-" + id;
				$(id1).text(value);
				// per gli emergenti (togliamo rischio id duplicate, meglio 2 righe di js)
				var id2 = "#click-em-" + id;
				$(id2).text(value);
			}
		});
	}, 'json');
}


function resetTb(all)
{
  $("#altri_post").show();
	$("#btn_filtri").removeClass("on");
	$("#form_filtri").hide();
	$("#btn_recenti").removeClass("on");
	$("#btn_importanti").addClass("on");
	if(all)
	{
		$("#form_filtri a").removeClass("cat_checked");
		$("#btn_per_tag").hide();
		$("#btn_per_fonte").hide();
		$("#btn_per_data").hide();
		$("#authorFilter").val("");
		$("#categoryFilter").val("");
		$("#todayFilter").val("0");
		$("#yesterdayFilter").val("0");
		$("#periodFilter").val("0");
	}
	setButtons();
}

function appendPreloader()
{
	$("#bottom_area").append(
			'<div id="preloader" class="preloader">'+
			'<img src="/images/ec_load.gif" /></div>'
	);
}

function ajaxSearch(page)
{
	resetTb(true);
	appendPreloader();
	var form_data = $("#searchform input").serialize();
	var search_url = DAILYME.search_url;
	var searchValue = $("#searchform input").val();
	if(page>0)
	{
		search_url += '/'+searchValue+'/'+page;
	}
	$.ajax({
		type:'POST',
		url:search_url,
		data:form_data,
		success:function(dReturn)
		{
			$("#btn_importanti").removeClass("on");
			$("#btn_recenti").removeClass("on");

			appendPageBody(dReturn,false);
			$("#altri_post").hide();
		}
	});
	return false; // this to prevent form from being submitted (evita il submit del form)
}


function alcuniBlog()
{
	$("#footer_blog_container").css('opacity','0.2');
	$.ajax({
		type:'GET',
		url:DAILYME.reload_random_blogs+'?q='+Math.random(),
		success:function(dReturn)
		{
		  if(dReturn)
		  {
			  $("#footer_blog_container").html(dReturn);
			  $("#footer_blog_container").css('opacity','1');
		  }
		}
	});
}


function sidebar_binding() {
	
// tooltip post
	$(".ico_info").unbind();
	$(".ico_info").click(function(event) { // no livequery!!!
			event.preventDefault();
			$(".media_tooltip").hide();
			$(this).next().show();
			$(".highslide-html-content div").css('overflow','visible'); // per visualizzare il tooltip per intero all'interno dei layer 
	});
	
	$(document).click(function(e) { // no livequery!!!
		if(!$(e.target).is(".ico_info")) {
			$(".media_tooltip").hide();
		}
	});

	
	
// apertura / chiusura more tags
	$(".piu").click(function(event) {
		if($(this).hasClass("meno"))
		{
			$(this).parent().prev().find("p").css("height","16px");
			$(this).removeClass("meno");
		}
		else
		{
			$(this).parent().prev().find("p").css("height","auto");
			$(this).addClass("meno");
		}
	});													 

	
// multimedia

	$("#video_preview a").click(function(event){	
		$("#video_content").animate({"top": "-" + ($(this).attr("rel")*103) + "px"},500,"swing");
		$("#video_preview_txt a, #video_preview_txt span").removeClass("curr_video");
		$("#video_preview_txt a#tit_video_" + $(this).attr("rel")).addClass("curr_video");
		$("#video_preview_txt span#auth_video_" + $(this).attr("rel")).addClass("curr_video");																 											 
	});
	
	$("#pic_controller a").click(function(event){
		$("#pic_content").animate({"left": "-" + ($(this).attr("rel")*183) + "px"},500,"swing");
		$("#pic_controller a").removeClass("current");
		$(this).addClass("current");															 											 
	});
	
	$("#pic_preview a").click(function(event){
		$("#pic_content").animate({"top": "-" + ($(this).attr("rel")*103) + "px"},500,"swing");
		$("#pic_preview_txt a, #pic_preview_txt span").removeClass("curr_set");
		$("#pic_preview_txt a#tit_set_" + $(this).attr("rel")).addClass("curr_set");
		$("#pic_preview_txt span#auth_set_" + $(this).attr("rel")).addClass("curr_set");												 											 
	});
	
	$("#chiudi_pic").click(function(event){
		$("#chiudi_pic, #pic_preview").hide();
		$("#apri_pic").show();
	});
	
	$("#chiudi_video").click(function(event){
		$("#chiudi_video, #video_preview").hide();
		$("#apri_video").show();
	});
	
	$("#apri_pic").click(function(event){
		$("#chiudi_pic, #pic_preview").show();
		$("#apri_pic").hide();
	});
	
	$("#apri_video").click(function(event){
		$("#chiudi_video, #video_preview").show();
		$("#apri_video").hide();
	});

//	flash news / top news

	if (global_contentType == "important") {
		var layer_to_scroll = "flash_news";
	} else {
		var layer_to_scroll = "top_news";
	}

	var y_flash = 0;
	var step_flash = 137;
	var curr_step_flash = 1;
	var quanti_flash = $("#flash_news_content div.flashpost").size();
	var tot_steps_flash = quanti_flash;

	$("#tit_" + layer_to_scroll + " .down").click(function(event){
		event.preventDefault();
		if (curr_step_flash < tot_steps_flash) {
			y_flash = y_flash - step_flash;
			curr_step_flash = curr_step_flash + 1;
			$("#tit_" + layer_to_scroll + " .up").css({"opacity": "1"});
			$("#flash_news_content").animate({"top": y_flash + "px"},300,"swing");
			if (curr_step_flash==tot_steps_flash) {
				$("#tit_" + layer_to_scroll + " .down").css({"opacity": "0.2"});
			}
		}
	});

	$("#tit_" + layer_to_scroll + " .up").click(function(event){
		event.preventDefault();
		if (curr_step_flash > 1) {
			$("#tit_" + layer_to_scroll + " .down").css({"opacity": "1"});
			y_flash = y_flash + step_flash;
			curr_step_flash = curr_step_flash - 1;
			$("#flash_news_content").animate({"top": y_flash + "px"},300,"swing");
			if (curr_step_flash==1) {
				$("#tit_" + layer_to_scroll + " .up").css({"opacity": "0.2"});
			}
		}
	});
	
}

//tendine data pannello filtri
function filtriOptionsBindings()
{
	$("#giorno, #mese, #anno, #giorno_to, #mese_to, #anno_to").click(function(event) {
		var related_select_id = "#select_" + $(this).attr('id'); 
		$(related_select_id).show();
		$("#per_data em").hide();
		if ($("#periodFilter").val() == 1) {
			$("#giorno, #mese, #anno, #giorno_to, #mese_to, #anno_to").css({"color":"#333"});
		}
	});

	$(".tendine_container ul li").mouseover(function(event) {
		$(this).css({"color": "#fff","background-color": "#333"});
	});

	$(".tendine_container ul li").mouseout(function(event) {
		$(this).css({"color": "#333","background-color": "#fff"});
	});

	$("#select_giorno li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#giorno").val($(this).text());
		$("#dayFilter").val($(this).text());
	});

	$("#select_mese li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#mese").val($(this).text());
		$("#monthFilter").val($(this).text());
	});

	$("#select_anno li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#anno").val($(this).text());
		$("#yearFilter").val($(this).text());
	});

	$("#select_giorno_to li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#giorno_to").val($(this).text());
		$("#dayFilter_to").val($(this).text());
	});

	$("#select_mese_to li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#mese_to").val($(this).text());
		$("#monthFilter_to").val($(this).text());
	});

	$("#select_anno_to li").mousedown(function(event) {
		$(this).parent().css({"display":"none"});
		$("#anno_to").val($(this).text());
		$("#yearFilter_to").val($(this).text());
	});
	

	
	fakeInputBindings();
	
	$("#fonte_scroll_down").click(function(event) {
		if(curr_step_authors < n_step_authors) {
			pos_authors = pos_authors - step_authors;
			$("#authors_content").animate({"top": pos_authors + "px"},300,"swing");
			curr_step_authors ++;
			check_opacity();
		}
	});

	$("#fonte_scroll_up").click(function(event) {
		if(curr_step_authors > 1) {
			pos_authors = pos_authors + step_authors;
			$("#authors_content").animate({"top": pos_authors + "px"},300,"swing");
			curr_step_authors --;
			check_opacity();
		}
	});
	
	$("#per_fonte em").click(function(event){
		$("#authors_content").css('top','0').html(
				'<img style="float:left;margin-left:183px;margin-top:35px;border:5px solid #e5e5e5" src="/images/ec_load.gif" />'
		);
		$("#fonte_scroll_up").css({"opacity": "0.15"});
		$.ajax({
			type:'POST',
			data:'',
			url:DAILYME.base_url+'get/filters/fonte/'+$(this).attr('id'),
			success:function(dReturn) { if(dReturn) {
				$("#authors_content").html(dReturn);
				n_authors = $("#authors_content a").size();
				n_step_authors = Math.ceil(n_authors/15);
				pos_authors = 0;
				curr_step_authors = 1;
				check_opacity();
				filtriOptionsBindings();
				init(); // unitip
			} }

		});
	});
	

	
	
// filtro periodo
	$("#today, #yesterday").click(function(e){
		var input_id = "#" + $(this).attr('id') + "Filter";
		var new_value = $(this).hasClass("cat_checked") + 0; // Forzo a intero
		$(input_id).val(new_value);
		$("#per_data em").hide();
		$("#period").removeClass("cat_checked");
		$("#periodFilter").val(0);
		able_disable_dateinterval();
		e.preventDefault();
	});

	$("#period").click(function(e){
		$("#today, #yesterday").removeClass("cat_checked");
		var input_id = "#" + $(this).attr('id') + "Filter";
		var new_value = $(this).hasClass("cat_checked") + 0; // Forzo a intero
		$(input_id).val(new_value);
		$("#todayFilter, #yesterdayFilter").val(0);
		able_disable_dateinterval();
		e.preventDefault();
	});
	
//	scroller keywords pannello filtri

	var pos_kw = 0;
	var step_kw = 168;
	var n_kw = $("#keyword_content a").size();
	var n_step_kw = Math.ceil(n_kw/8);
	var curr_step_kw = 1;

	$("#keyword_scroll_down").click(function(event) {
		if(curr_step_kw < n_step_kw) {
			pos_kw = pos_kw - step_kw;
			$("#keyword_content").animate({"top": pos_kw + "px"},300,"swing");
			curr_step_kw ++;
			check_opacity();
		}
	});

	$("#keyword_scroll_up").click(function(event) {
		if(curr_step_kw > 1) {
			pos_kw = pos_kw + step_kw;
			$("#keyword_content").animate({"top": pos_kw + "px"},300,"swing");
			curr_step_kw --;
			check_opacity();
		}
	});
	
//	scroller autori pannello filtri
	var pos_authors = 0;
	var step_authors = 105;
	var n_authors = $("#authors_content a").size();
	var n_step_authors = Math.ceil(n_authors/15);
	var curr_step_authors = 1;

	var alfabeto = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	var steps_per_lettera = new Array();

	var i = 0;
	for (i=0;i<26;i++) {
		steps_per_lettera.push(Math.ceil(($("#authors_content a." + alfabeto[i]).attr("id"))/20));
	}

	$("#per_fonte p em").click(function(event){
		$("#per_fonte p em").css({"color":"#aaa"});
		$(this).css({"color":"#333"});
	});
	
	// reset dei filtri al click
	$("#btn_per_fonte #btn_per_tag #btn_per_data").click(function(){
		$(this).hide();
		$("#top_area").removeClass("panel_open");
	});
	
	function check_opacity()
	{
		if (curr_step_authors == n_step_authors) { $("#fonte_scroll_down").css({"opacity": "0.15"}); } else { $("#fonte_scroll_down").css({"opacity": "1"}); }
		if (curr_step_authors == 1) { $("#fonte_scroll_up").css({"opacity": "0.15"}); } else { $("#fonte_scroll_up").css({"opacity": "1"}); }
		if (curr_step_kw == n_step_kw) { $("#keyword_scroll_down").css({"opacity": "0.15"}); } else { $("#keyword_scroll_down").css({"opacity": "1"}); }
		if (curr_step_kw == 1) { $("#keyword_scroll_up").css({"opacity": "0.15"}); } else { $("#keyword_scroll_up").css({"opacity": "1"}); }
	}
}


function fakeInputBindings()
{
	$("#per_keyword a, #per_data a, #per_fonte a").unbind();
//	check tags e data in pannello filtri
	
	
	$("#per_keyword a, #per_data a, #per_fonte a, #per_category a").click(function(e){
		$(this).toggleClass("cat_checked");
		// e.preventDefault();
	});
	
	/**
	 * Popola il campo nascosto relativo agli autori quando vengono selezionati come filtro.
	 */
	$("#authors_content a, #keyword_content a, #per_category a").click(function(e){
		var parent_id = $(this).parent().attr("id");
		// Prende il valore da title o _title (attributo di backup del plugin tooltip)
		// var title = $(this).attr("title") ? $(this).attr("title") : $(this).attr("_title");
		var title = $(this).attr("rel");
		var value = (title) ? title : $(this).text();
		var filter = '';
		// var filter = (parent_id == "authors_content") ? $('#authorFilter') : $('#categoryFilter');
		switch (parent_id)
		{
			case "authors_content":
				filter = $('#authorFilter');
				break;
			case "keyword_content":
				filter = $('#categoryFilter');
				break;
			case "category_content":
				filter = $('#categoryFilter_2');
				break;
		}
		glue = '|';
		value += glue;
		$(filter).val($(filter).val().replace(value, ''));
		if ($(this).hasClass("cat_checked")) {
			$(filter).val($(filter).val() + value);
		}
	});

}


function able_disable_dateinterval()
{
	if (document.form_filtri.periodFilter.value == 0) {
		$(".data_container label").css({"color": "#ddd"});
		$(".data_container input").attr("disabled", "disabled").css({"color": "#ddd"});
	} else {
		$(".data_container label").css({"color": "#777"});
		$(".data_container input").removeAttr('disabled').css({"color": "#333"});
	}
}


/**
 * cicla i twitt
 * @return
 */
function rotateTwitt()
{
	var current = 0;
	$("#twitter a").each(function(i){
		if($(this).css("display") != 'none')
		{
			current = i;
		}
	});
	var next = current + 1;
	if(next>(DAILYME.max_twitter_feed-1))
	{
		next=0;
	}
	
	$("#twitter a").hide();
	$("#twitter a").eq(next).show();
	DAILYME.twitter_timeout_hook = setTimeout("rotateTwitt()",DAILYME.twitter_rotation_timeout);
}


/**
 * aggiorno l'ora ogni minuto
 * @return
 */
function orologio()
{
	var currentDate = new Date();
	
	var currHour = currentDate.getHours();
	if(currHour<10)
	{
		oraString += '0';
	}
	var oraString = currHour + '.';
	
	var currMin = currentDate.getMinutes();
	if(currMin<10)
	{
		oraString += '0';
	}
	oraString += currMin;
	
	$("#gL").html(oraString);
}


function blogChartBindings()
{
	// tab blogchart
	
	$(".tab_bc").unbind().click(function(event) {
	  event.preventDefault();
	  $(".tab_bc").removeClass("tab_active");
	  $(this).addClass("tab_active");
	});
	
	$("#bg_tabler_1").unbind().click(function(event) {
	  $("#bc_tab_1").show();
	  $("#bc_tab_2").hide();
	  $("#bc_tab_3").hide();
	});
	
	$("#bg_tabler_2").unbind().click(function(event) {
	  $("#bc_tab_1").hide();
	  $("#bc_tab_2").show();
	  $("#bc_tab_3").hide();
	});
	
	$("#bg_tabler_3").unbind().click(function(event) {
	  $("#bc_tab_1").hide();
	  $("#bc_tab_2").hide();
	  $("#bc_tab_3").show();
	});
	
	// pager blogchart/tagchart
	
	$(".blogchart_pager div a").unbind().click(function(event) {
	  event.preventDefault();
	  // $("#ibox_content").html('');
	  $(".blogchart_pager div a").removeClass("page_active");
	  $(this).addClass("page_active");
	  var url = $(this).attr("href");
	  var parent = $(this).parents("div.blogchart_pager").attr("id").replace("_pager", ""); // #tagchart o #blogchart
	  $.get(url, function(data) {
	    var content = $('<div>'+data+'</div>');
	    $("#" + parent).replaceWith($(content).find('#'+parent));
	  });
	  // return false;
	});   
}
