



function Scroller(controlsId, targetId, increment, interval) {
	
	var _target, _increment, _interval, _wsi, _S;
	
	var Scroller = function() {
		
		_target = document.getElementById(targetId);
		_increment = increment || 15;
		_interval = interval || 100;
		
		$("#" + controlsId + " > span.down").bind("mousedown", function(){ _S.downScroll() });
		$("#" + controlsId + " > span.down").bind("mouseup", function(){ _S.stopScroll() });
		$("#" + controlsId + " > span.up").bind("mousedown", function(){ _S.upScroll() });
		$("#" + controlsId + " > span.up").bind("mouseup", function(){ _S.stopScroll() });
		
	}
	
	this.stopScroll = function() {
		clearInterval(_wsi);
	}
	
	this.upScroll = function() {
		_wsi = setInterval(function(){ _target.scrollTop -= _increment }, _interval);
	}
	
	this.downScroll = function() {
		_wsi = setInterval(function(){ _target.scrollTop += _increment }, _interval);
	}
	
	_S = this;
	Scroller();
	
}


//PLAYER GALLERY

function startGalleryCycle(id) {
		
	$("#" + id).cycle({ 
		fx: 'scrollLeft', 
		prev: "#" + id + '_prev', 
		next: "#" + id + '_next' 
	});
	
	$("#" + id + "_pause").removeClass("play");
	$("#" + id + "_pause").addClass("pause");
	
}

function toggleGalleryCycle(id) {
	
	if ($("#" + id + "_pause").hasClass("pause")) {
	
		$("#" + id).cycle('pause');
		$("#" + id + "_pause").removeClass("pause");
		$("#" + id + "_pause").addClass("play");
		
	} else {
		
		$("#" + id).cycle('resume');
		$("#" + id + "_pause").removeClass("play");
		$("#" + id + "_pause").addClass("pause");
		
	}
	
}
			
//PLAYER GALLERY



//SVUOTA INPUT
$(document).ready(function() {
$(".input-sbianca").click(function() {
 if($(this).val() != "") {
 $(this).val(""); //Svuoto il contenuto.
 }
 });
});
//SVUOTA INPUT

	

// CINEMA COLLAPSE
$(document).ready(function(){
	
//CONTROLLO IL COLLAPSE DELLE CITAZIONI
  $(".last-citazioni").hide();

  $(".msg_head").click(function(){
  $(".last-citazioni").slideToggle(600);
});	

//CONTROLLO IL COLLAPSE DELLA COLONNA SONORA
  $(".info-tracklist").hide();

 $(".colonna-sonora").click(function(e){
	if ($(this).hasClass("tit")) {
				
	$(".colonna-sonora").removeClass("tit");
	 $(".info-tracklist").slideToggle(600);
	e.preventDefault();
	} 
	else {
	$(".colonna-sonora").addClass("tit");
 	$(".info-tracklist").slideToggle(600);
	e.preventDefault();
	}

 });	
});






	function onSubmitRicercaSmall() {
		if($("#provincia-small").val() == ''){
			alert("E' necessario specificare almeno la provincia");
			return;
		} else {
			$("#ricercacinema-small").submit();
		}
	}
	
	function caricaComboInitSmall() {
		$("#provincia-small").removeOption(/./);
		$("#provincia-small").addOption("","Provincia");
		$("#provincia-small").ajaxAddOption("/json/province.json",null,false);
	}
	
	function onChangeProvinciaSmall() {
		//Caricare localit� e film
		if($("#provincia-small").val() == '') {
			$("#idComune-small").removeOption(/./);
			$("#idComune-small").addOption("","Scegli");
		}
		$("#idComune-small").removeOption(/./);
		$("#idComune-small").addOption("","Scegli");
		$("#idComune-small").ajaxAddOption("/json/localita/"+$("#provincia-small").val()+".json",null,false);
	}

	function onSubmitRicercaFilm() {
		if($("#titolo_film").val() == "Inserisci il titolo del film che stai cercando"){
			$("#titolo_film").val("");
		}

		if($("#regista").val() == "Regista"){
			$("#regista").val("");
		}

		if($("#attori").val() == "Attori"){
			$("#attori").val("");
		}

		$("#ricercaf").submit();
	}

	function onSubmitRicercaFilmSmall() {
		if($("#ricercafilm #titolo_film").val() == "Inserisci il titolo del film che stai cercando"){
			$("#ricercafilm #titolo_film").val("");
		}

		if($("#ricercafilm #regista").val() == "Regista"){
			$("#ricercafilm #regista").val("");
		}

		if($("#ricercafilm #attori").val() == "Attori"){
			$("#ricercafilm #attori").val("");
		}

		$("#ricercafilm").submit();
	}
	
	/** Pietro Alfano **/
	function highlightCurrentPrograms(){
		var start, end;
		var now = new Date();
		var currentHour = now.getHours() > 9 ? now.getHours() : "0" + now.getHours();
		var currentMinute = now.getMinutes()>9 ? now.getMinutes(): "0" + now.getMinutes();
		var currentTime = "" + (currentHour) + "" + (currentMinute);
		$('.ch td').each(function(i){
			start = $('.int b:first', $(this)).html();
			end = $('.int b:last', $(this)).html();
			if (start < currentTime && end > currentTime){
				$('.pr', $(this)).addClass('cpr');			
			}
		});
	}
	/** **/
/**
 * Gestisce tutta la navigazione dei programmi TV
 * 
 * @author Davide Zanotti (davidezanotti@gmail.com)
 */
var ProgramsNavigator = {
	
	// Filters applied 
	sourceFilter: null,
	catFilter: null,
	progFilter: null,
	filtersApplied: 0,
	
	// Adds a zero before if the number is less than 10
	pad: function pad(n) {
		return n > 9 ? n : "0" + n;
	},
	
	// Holds a reference to the current date
	currentDate: new Date(),
	
	// Update displayed date
	setDate: function () {
		
		var pn = ProgramsNavigator;
		var d = new Date();
		var days = ["Domenica", "Luned&igrave", "Marted&igrave", "Mercoled&igrave", "Gioved&igrave", "Venerd&igrave", "Sabato"];
		var dayString = days[pn.currentDate.getDay()];
		var html = [];
		var navigateTo = function(increment) {
			
			var pn = ProgramsNavigator;
			pn.currentDate = new Date(
			pn.currentDate.getFullYear(), 
				pn.currentDate.getMonth(), 
				pn.currentDate.getDate() + increment, 
				pn.currentDate.getHours() - (pn.currentDate.getHours() % 2)
			);
			pn.setDate();
			pn.loadPrograms();
			pn.filtersApplied++;
			
		}
		
		if (pn.currentDate.getDate() > d.getDate()) {
			html.push('<a id="nav_tv_back" href="javascript:;">&laquo;</a> ');
		}
		
		if (pn.currentDate.getDate() == d.getDate()) {
			
			html.push('<span style="font-weight: normal">');
			html.push(pn.currentDate.getHours());
			html.push(":");
			html.push(pn.pad(d.getMinutes()));
			html.push(" - ");
			html.push('</span>');
			
		}
		
		html.push(dayString);
		html.push(" ");
		html.push(pn.pad(pn.currentDate.getDate()));
		html.push("/");
		html.push(pn.pad(pn.currentDate.getMonth() + 1));
		
		if (pn.currentDate.getDate() <= d.getDate() + 5) {
			html.push(' <a id="nav_tv_next" href="javascript:;">&raquo;</a>');
		}
		
		// Display date into HTML
		document.getElementById("current_date").innerHTML = html.join("");
		
		// Adds listeners to back/next arrows
		$("#nav_tv_back").bind("click", function(){ navigateTo(-1) });
		$("#nav_tv_next").bind("click", function(){ navigateTo(1) });
		
	},
	 
	// attach tooltips
	addToolTips: function() {
		
		var triangle = new Image(16, 16);
			triangle.src = "/images/static/common/cinema/triangle.gif";
			triangle.id = "tooltip_triangle";
		
		// Get left position of the first table's cell
		var leftPos = $("div#col-sx  div.channels .ch tr td:first").position().left;
		
		$("div#col-sx  div.channels .ch tr td span.pr").bind("mouseover", function() {
			
			// Referencing the current selected <span> node 
			var currentNode = $(this);
			
			// <td> which contains the <span>
			var cell = currentNode.parent();
			
			// Get cell's height
			var cellHeight = cell.height();
			
			// Get <span> containing program's description
			var desc = cell.find("span[class*='prd']:first");
			
			// Get cell's top position
			var topPos = cell.position().top;
			
			// Attach mouseover handler
			currentNode.bind("mouseout", function() {
				
				desc.css("display", "none");
				currentNode.css("textDecoration", "none");
				currentNode.find("#tooltip_triangle").remove();
				
			});
			
			triangle.style.top = (topPos + 1) + "px";
			triangle.style.left = (cell.position().left + Math.round(currentNode.width() / 2)) + "px";
			
			// Display hidden <span> and add text decoration to the selected one
			currentNode.css("textDecoration", "underline");
			currentNode.append(triangle);
			desc.css("display", "block");
			desc.css("top", (topPos - desc.height() - 20) + "px");
			desc.css("left", leftPos + "px");
			
		});
		
	},
	
	// Adds (or subtract) hours to a date
	dateAddHours: function(date, increment) {
		
		var pn = ProgramsNavigator;
		var h = pn.currentDate.getHours() + increment;
		
		if (h > 23) {
			h = 21;
		} else if (h < 0) {
			h = 0;
		}
		
		pn.currentDate = new Date(pn.currentDate.getFullYear(), pn.currentDate.getMonth(), pn.currentDate.getDate(), h);
		
	},
	
	// Returns a string representing a formatted date
	getPageForDate: function() {
		
		var pn = ProgramsNavigator;
		
		return [
			pn.currentDate.getFullYear(), 
			pn.pad(pn.currentDate.getMonth() + 1), 
			pn.pad(pn.currentDate.getDate()), "-", 
			pn.currentDate.getHours() - (pn.currentDate.getHours() % 2),
			".shtml"
		].join("");
		
	},
	
	// Returns a 3 elements array containing hours
	getHoursForDate: function() {
		
		var h = ProgramsNavigator.currentDate.getHours();
		var firstHour = h - (h % 2);
		
		return [firstHour, firstHour+1];
		
	},
	
	// Makes an ajax call and display data into page
	loadPrograms: function() {
		
		var pn = ProgramsNavigator;
		var page = pn.getPageForDate();
		var hours = pn.getHoursForDate();
		
		$("#dynamic_data_container").html('<div id="programs_loading_mask">Loading...</div>');
		
		$.ajax({
			type: "GET",
			url: "/programmazionetv/" + page,
			dataType: "text",
			cache: false,
			success: function(data) {
				
				// Display retrieved content
				document.getElementById("dynamic_data_container").innerHTML = data;
				// Apply filters
				pn.applyFilters();							
				// Add dynamic rows coloring
				pn.makeStripes();
				// Add tips on mouseover
				pn.addToolTips();
				// Highlight current programs
				highlightCurrentPrograms();

				// set list channel link
				$('table.ch tbody tr th span a').click(function(e){
					var hours=-1;
					var channel=-1
					var category=-1;
					$('#hours_menu li').each(function(i){
						if ($(this).is('.active')){
							hours = i;
						}
					});
					$('#source_menu li').each(function(i){
						if ($(this).is('.active')){
							channel = i;
						}
					});
					$('#category_menu li').each(function(i){
						if ($(this).is('.active')){
							category = i;
						}
					});
					$(this).attr('href',$(this).attr('href') + '?hours=' + hours + '&channel=' + channel + '&category=' + category);
				});
				initFilters();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				
				if (typeof console != "undefined") {
					console.error("Unable to load data: " + textStatus);
				}
				
			}
		});
		
		
	},
	
	// Rows coloring
	makeStripes: function() {
		
		var pn = ProgramsNavigator;
		var counter = 0;
		var h = pn.getHoursForDate();
		var backButton = '<a class="right" href="http://cinema-tv.corriere.it/tv.shtml"><img src="/images/static/common/cinema/back_home_tv.gif" alt="Torna alla home tv" /></a>';
		var html = [
			'<div class="stripe_wrapper">',
				'<table class="time_navigator">',
					'<tbody>',
						'<tr>',
							'<td class="time_section back"><a href="javascript:;" class="nav back-ico">&laquo;</a></td>',
							'<td class="time_section2">' + h[0] + ':00</td>',
							'<td class="time_section2">' +  + h[1] + ':00</td>',
							'<td class="time_section next"><a href="javascript:;" class="nav next-ico">&laquo;</a></td>',
						'</tr>',
					'</tbody>',
				'</table>',
			'</div>'
		].join("");
		
		// Display "back to home" button
		document.getElementById("back_home_tv").innerHTML = pn.filtersApplied > 0 ? backButton : "";
		
		// Removes all navigators
		$("div#col-sx div.channels table.time_navigator").each(function() { $(this).parent().remove() });
		
		// Alternative rows coloring
		$("div#col-sx div.channels table.ch").each(function() {
			
			var current = $(this);
			
			// Remove previous defined classes
			current.removeClass("even_table");
			current.removeClass("odd_table");
			
			// Toggle coloring if table is visible
			if (current.css("display") != "none") {
				
				// Append a navigator every 10 rows (tables)
				if(counter % 10 == 0) {
					current.before(html);
				}
				
				// Assign the properly class to the table
				current.addClass(counter % 2 ? "even_table" : "odd_table");
				counter++;
				
			}
			
		});
		
		$("div#col-sx div.channels table.time_navigator tbody tr td.back a").bind("click", function() {
			
			pn.dateAddHours(pn.currentDate, -2);
			pn.loadPrograms();
			
		});
		
		$("div#col-sx div.channels table.time_navigator tbody tr td.next a").bind("click", function() {
			
			pn.dateAddHours(pn.currentDate, 2);
			pn.loadPrograms();
			
		});
	},
	
	// Attach event listeners to menu items
	attachFiltersListeners: function() {
		
		var pn = ProgramsNavigator;
		var loadHours = function(h, node) {
			
			var current = $(node);
			var parent = current.parent();
			var currentId = current.attr("id"); 
			
			// Deselect all others buttons
			$("#hours_menu li a").each(function(){
				
				var n = $(this);
				
				if (n.attr("id") !== currentId) {
					n.parent().removeClass("active");
				}
				
			});
			
			if (parent.hasClass("active")) {
				
				parent.removeClass("active");
				pn.currentDate = new Date();
				pn.filtersApplied--;
				
			} else {
				
				parent.addClass("active");
				
				if (pn.currentDate.getHours() == new Date().getHours()) {
					
					pn.filtersApplied++;
					
				}
				
				pn.currentDate = new Date(pn.currentDate.getFullYear(), pn.currentDate.getMonth(), pn.currentDate.getDate(), h);
				
			}
			
			setTimeout(pn.loadPrograms, 0);
			
		}
		
		var toggleButtons = function(scope, path, filter) {
			
			var current = $(scope);
			var currentId = current.attr("id");
			var parent = current.parent();
			var buttons = $(path);
			
			// Deselect all others buttons
			buttons.each(function(){
				
				var node = $(this);
				
				if (node.attr("id") !== currentId) {
					node.parent().removeClass("active");
				}
				
			});
			
			// Activate/disactivate selected button and filters
			if (parent.hasClass("active")) {
				
				parent.removeClass("active");
				pn[filter] = null;
				pn.filtersApplied--;
				
			} else {
				
				parent.addClass("active");
				
				if (pn[filter] == null) {
					pn.filtersApplied++;
				}
				
				pn[filter] = scope.id.split("_")[0];
				
			}
			
			setTimeout(function() {
				pn.applyFilters();
				pn.makeStripes();
			}, 0);
			
		}
		
		//  televisione - satellite - digitale terrestre free - digitale terrestre pay
		$("#source_menu li a").bind("click", function(){ toggleButtons(this, "#source_menu li a", "sourceFilter") });
		
		// film - fiction - intratt. - documentari - news - sport - bambini
//		$("#category_menu li a").bind("click", function(){ toggleButtons(this, "#category_menu li a", "catFilter") });
		$("#category_menu li a").bind("click", function(){ toggleButtons(this, "#category_menu li a", "progFilter") });
		
		// mattino presto - mattino - pomeriggio - sera - notte
		$("#earlymorning_hoursfilter_btn").bind("click", function(){ loadHours(6, this) });
		$("#morning_hoursfilter_btn").bind("click", function(){ loadHours(9, this) });		
		$("#afternoon_hoursfilter_btn").bind("click", function(){ loadHours(15, this) });		
		$("#evening_hoursfilter_btn").bind("click", function(){ loadHours(21, this) });		
		$("#night_hoursfilter_btn").bind("click", function(){ loadHours(0, this) });		
		
	},
	
	// Apply filters
	applyFilters: function() {
		
		var pn = ProgramsNavigator;
		var catFilterSelector = pn.catFilter != null ? "." + pn.catFilter : "";
		var progFilterSelector = pn.progFilter != null ? "." + pn.progFilter : "";
		var sourceFilterSelector = pn.sourceFilter != null ? "." + pn.sourceFilter : "";
		
		$("div.channels table.ch").css("display", "none");
		$("div.channels table.ch" + catFilterSelector + sourceFilterSelector).css("display", "block");
		
		if(pn.progFilter != null || pn.sourceFilter != null) {
			pn.state = "filtered";
		}
		
		if (progFilterSelector != null){
			$('#dynamic_data_container .prog-selezionato').removeClass('prog-selezionato');
			if (pn.progFilter != null){
				$('#dynamic_data_container .'+pn.progFilter).addClass('prog-selezionato');
			}
		}
		
	}
		
};

var hours=getParameter('hours') ==''?-1:getParameter('hours');
var channel=getParameter('channel') ==''?-1:getParameter('channel');
var category=getParameter('category') ==''?-1:getParameter('category');

function initFilters(){
	if (hours > -1){
		$('#hours_menu li').eq(hours).find('a').click();
		hours = -1;
	}
	if (channel > -1){
		$('#hours_menu li').eq(channel).find('a').click();
		channel = -1;
	}
	if (category > -1){
		$('#hours_menu li').eq(category).find('a').click();
		category = -1;
	}
}

// Mostra la relativa fascia oraria
function displayTVTime(button) {
	
	var cssClass = button.id.split("_")[0];
	
	// Deselect all cells
	$("table.channel").css("display", "none");
	
	// Disactivate all menu buttons
	$("ul.category_menu li").removeClass("active");
	
	// Activate selected button
	$("#" + button.id).parent().addClass("active");
	
	// Higlight all matched cells
	$("ul.riga-canale").each(function(){
		
		$(this).css("display", $(this).hasClass(cssClass) ? "block" : "none")
		
	})
	
}

// Replace long text with "..."
function replaceLongText() {
	
	$('.ellipsis').each(function (i) {
		var e = this;
		var w = $(e).width() - 10000;
		var t = e.innerHTML;
		$(e).html("<span>" + t + "</span>");
		e = $(e).children(":first-child")
		while (t.length > 0 && $(e).width() >= w) {
			t = t.substr(0, t.length - 1);
			$(e).html(t + "...");
		}
	});
	
}

function adjustActorsBoxes() {
	
	var rightColBoxes = $("#home-2col div.info_box");
	var actorBoxes = $("#col-sx div.actors div.actor");
	
	for (var i=0; i<rightColBoxes.length; i++) {
		
		$(actorBoxes.get(i)).css("width", "405px");
		
	}
	
}

/* GESTIONE ARCHIVIO VIDEO*/
function loadListing_archivio(url) {
	$("#archivio-listing").html('<div id="programs_loading_gallery"></div>');
	//carico xml
	$.ajax({
		type: "GET",
		url: url,
		success: function(data) {
			$('#archivio-listing').html(data);
			insertPagination();
			loadpageArchivio(1);
			$('#pager a').click(function (e){
				e.preventDefault();
				loadpageArchivio($(this).attr('class'));
			});
		}
	});
}

function cercaArchivioVideo(url, pagina,tipologia) {
	currentPage = pagina;
	if($('#cerca-film input[name=titolo]').attr("value") == '') {
		alert("Inserire un titolo");
	} else {
		//loading
		$("#archivio-listing").html('<div id="programs_loading_gallery"></div>');
			$.ajax({
				type: "GET",
				url: url,
				data: {"film.titolo" : $('#cerca-film input[name=titolo]').attr("value"), 
						"tipoArchivioVideo" : tipologia, 
						"paginaCorrente" : pagina
					},
				cache: false,
				success: function(data) {
					$("#archivio-listing").html(data);
					pages = parseInt($('#totpagine').html());
					controlPaginationView('#pager-din a');
				}
			});
	}
}

function controlPaginationView(selector){
	var otherPages = maxPage - (pages - currentPage + 1);
	$(selector).each(function(i){
		if ($(this).attr('class').search('nav-arrow') < 0){
			var page = i+1;
			if (
				((otherPages > 0) && (page >=currentPage-otherPages) && (page <currentPage))
				||
				((page >=currentPage) && (page < (parseInt(currentPage)+maxPage)))
			){
				$(this).show();
			}else{
				$(this).hide();
			}	
		}
	});
}

function loadpageArchivio(selected) {
	selected = ("" + selected).split(' ')[0];
	currentPage = selected;
	$("#archivio-listing a.result").each(function(i) {
		//	gestisce la selezione corrente
		$('.select').removeClass('select');
		$('#pager a.'+selected).addClass('select');
		if ((i+1>=(selected-1)*10+1) && (i+1<(selected-1)*10+11)) {
			$(this).show();
		} else {
			$(this).hide();
		}
	});
	$('#prev').attr('rel',currentPage-1);
	$('#next').attr('rel',parseInt(currentPage)+1);

	currentPage == 1?$("#prev").addClass("nascondi"):$("#prev").removeClass("nascondi");
	currentPage == pages?$("#next").addClass("nascondi"):$("#next").removeClass("nascondi");

	$('#prev').unbind('click').click(function(e){e.preventDefault();loadpage($(this).attr('rel'));});
	$('#next').unbind('click').click(function(e){e.preventDefault();loadpage($(this).attr('rel'));});

	if ((maxPage != null) && (pages > maxPage)){
		controlPaginationView('#pager a');
	}
} 

//RISULTATI RICERCA TROVOCINEMA funzione nascondi righe
function loadpage(selected) {
	var current;
	var currenttitle = '';
	var showtitle;
	$("div.results-film .cinema_results").each(function(i) {
		//	gestisce la selezione corrente
		$('.select').removeClass('select');
		$('#pagination-film li a.'+selected).addClass('select');
		if ((i+1>=(selected-1)*10+1) && (i+1<(selected-1)*10+11)) {
			current = $('thead',$(this)).attr('id');
			currenttitle  
			if(currenttitle != current){
				showtitle=true;
				currenttitle=current;
			}else{
				showtitle=false;
			}
			$(this).show();
			if (showtitle){
				$('thead',$(this)).show();
			}else{
				$('thead',$(this)).hide();
			}
		}else{
			$(this).hide();
		}

	});

} 


function insertPagination(){
	$elements=$("#archivio-listing a.result");

	elements = $elements.length;
	pages = 1;
	if(elements > 10) {
		pages=elements%10==0?elements/10:(elements-(elements%10))/10+1;
		$("#archivio-listing").append('<div id="pager-riga"><div id="pager"> </div></div>');

		var link= '<a class="page" href="#">page</a>';

		for (i=1;i<=pages;i++){
			$("#pager").append(link.replace(/page/,i).replace(/page/,i));
		}
	} else {
		$("#archivio-listing").append('<div id="pager-riga"><div id="pager">1</div></div>');
	}
	$("#pager").append('<a id="prev" class="nav-arrow" href="#" rel=""><img width="13" height="10" src="/images/static/common/freccia_sx.gif"/></a>');
	$("#pager").append('<a id="next" class="nav-arrow" href="#" rel=""><img width="13" height="10" src="/images/static/common/freccia_dx.gif"/></a>');
}

function getParameter(whichOne) {
	var pairs = location.search.substring(1).split('&');
	var r = "";
	var tp = new Array();
	for (var i = 0; i < pairs.length; i ++) {
		tp = pairs[i].split('=');
		if (whichOne == tp[0])
			r = unescape(tp[1].replace(/\+/g, " "));
	}
	return r;
}

function enableTabPremiYearNavigation(){
	$('.scheda-premio #select_archivio input[type="button"]').click(function(e){
		var $schedaPremio = $(this).closest('.scheda-premio');
	    var anno = $schedaPremio.find('select :selected').text();
	    var premio = $schedaPremio.attr('id');
	    premio = premio.substring(premio.search('-')+1,premio.length);
		var url = "/premi/" + premio + "/" + premio + "-" + anno + ".shtml";
		$schedaPremio.find('.riconoscimenti').html('<div id="programs_loading_gallery"></div>');
		$.ajax({
			type: "GET",
			url: url,
			cache: false,
			success: function(data) {
				$schedaPremio.find('.riconoscimenti').html(data);
			},
			error: function(data){
				$schedaPremio.find('.riconoscimenti').html('Si &egrave; verificato un errore nel caricamento della scheda del premio');
			}
		});

	});
	$('.scheda-premio #select_archivio select.pr-edizione').keypress(function(e){
		if (e.which == 13){
			e.preventDefault();
			$(this).closest('form').find('input[type="button"]').click();
		}
	});
	
}

$(document).ready(function(){
		$(".recesnsioni_utente .send_ric").click(function(){
			$(this).parents("form:eq(0)").submit();
			return false;
		});


	if(jQuery('.recesnsioni_utente').length > 0 ){	
		$("#cercafilm").autocomplete('/recensioni/getJsonFilm.action', {
			selectFirst: true,
			minChars: 4
		});	
		$("#cercaautore").autocomplete('/recensioni/getJsonAutore.action', {
			selectFirst: true,
			minChars: 4
		});			
	}
	
	if(jQuery('.recensioni_search').length > 0 ){	
		$("#titolo_film").autocomplete('/recensioni/getJsonFilm.action', {
			minChars: 4,
			after: function(input,text) {
					jQuery('.recensioni_search ul.autocomplete li').click(function(){
						$(this).parents("form:eq(0)").submit();
					});
				}
		}).attr("autocomplete","off");
	}
	
						   
						   
	// Rimuovo il class linkNotizie dal link "archivio notizie"
	$(".article_cinema .articles-home #altri-titoli div a").removeClass("linkNotizie");
	
	// controllo testo nella scheda attore
	if ($(".articles-home").size() == 0) {
		$("#home-2col").parent().addClass("text_up").removeClass("clearfix");
		$("p.movie_description").remove();
		adjustActorsBoxes();
	}
	
if(browser_user_ag == "iPad"){
  if(jQuery('.player_container').length > 0 ){
      jQuery('.player_container').parent("div.articles-home").remove();
jQuery('#home-2col').removeClass("right").css("width","100%").parents(".text_up:eq(0)").css({"width":"100%","float":"none","height":"200px"});
jQuery('#home-2col').find("div.small_box").css({"float":"left", "margin-right":"10px","width":"230px","padding-right":"30px","position":"relative"}).find(".controls").css({'float':'right','left':'auto','right':'1px','bottom':'35px','position':'absolute'}).find(".down").css("margin-right","20px");
      jQuery('#home-2col .medium_box').css({"height":"172px","float":"left"});
  }
}	

	/*if ($("#info_box_tabs #section-3").size() == 0) {
		$("#info_box_tabs").addClass("none");
	}*/
	//	RISULTATI RICERCA TROVOCINEMA paginazione ogni 10	
	$tables=$("div.results_trovacinema .cinema_results");
	
	tables = $tables.length;
	var pages=tables%10==0?tables/10:(tables-(tables%10))/10+1; 

	$(".results-film").append('<div id="page-number"><ul id="pagination-film"></ul></div>');
	
	var link= '<li><a class="page" href="#">page</a></li>';
	
	for (i=1;i<=pages;i++){
	$("#pagination-film").append(link.replace(/page/,i).replace(/page/,i));
	
	}
	
	$('#pagination-film li a').click(function (){
		loadpage ($(this).attr('class'));		   
	});
	
	loadpage (1);
	//	FINE RISULTATI RICERCA TROVOCINEMA paginazione ogni 10	
		
	/*//aggiungo _small nel box tv in 3 colonna	
	$(".logosmall img").each(function() {
		var current = $(this).attr('src');
		$(this).attr('src', current.replace('.', '_small.'));
	})*/
	
	// caricamento della funzione per la navigazione all'interno del db premi
	enableTabPremiYearNavigation();

	
});

var idEntitaRating = "";
var rating = $.cookie("recensioniRating");
var text_value_n = "DISCRETO";
	function setValueVote(idEntitaRating, valore) {                                
		//$(".thank_vote").html("Grazie per aver votato!")
		$(".vote_user_rec").val(valore);
			var num_stelle = 1;
			if(valore==25) {
				num_stelle = 1;
			}
			if(valore==50) {
				num_stelle = 2;
			}
			if(valore==75) {
				num_stelle = 3;
			}				
			if(valore==100) {
				num_stelle = 4;
			}				
			$("#invia_recensione .testo_voto").html(text_value_n);	
			$("#rating_rec .stelle-rating").attr("class","stelle-rating stelle-"+num_stelle);
	}

	function hoverHandler(i) {
		$(".rating-"+i).hover(function () {
			$(this).parents("div.rating_rec:eq(0)").find(".link-rating").addClass("stars-"+i);	
			if(i==1) text_value_n = "DISCRETO";
			if(i==2) text_value_n = "BUONO";
			if(i==3) text_value_n = "OTTIMO";
			if(i==4) text_value_n = "ECCELLENTE";
			$("#invia_recensione .testo_voto").text(text_value_n);			
		}, function () {
			$(this).parents("div.rating_rec:eq(0)").find(".link-rating").removeClass("stars-"+i);
			$("#invia_recensione .testo_voto").text("");
		});
	}
	
	function disableVoting(idEntitaRating) {
		$("div[rel="+idEntitaRating+"] .click-rating a").unbind("mouseenter mouseleave");
		$("div[rel="+idEntitaRating+"] .click-rating a").css("cursor","default");
		$("div[rel="+idEntitaRating+"] .click-rating a").unbind("click", clickHandler);
	}
	
	function clickHandler(rating,idEntitaRating,classRating){
		rating=$.cookie("recensioniRating");
	 	if(checkRating(rating,idEntitaRating)){
			if (classRating == "rating-1") {
				setValueVote(idEntitaRating,"25");
			} else if (classRating == "rating-2"){
				setValueVote(idEntitaRating,"50");
			} else if (classRating == "rating-3"){
				setValueVote(idEntitaRating,"75");
			} else {
				setValueVote(idEntitaRating,"100");
			}
			$("#invia_recensione .testo_voto").removeClass("testo_voto");
			var valueRating = $.cookie("recensioniRating");
			valueRating = valueRating + idEntitaRating + "|"
			$.cookie("recensioniRating",valueRating);
			disableVoting(idEntitaRating);
  		}
		return false;
	}
	
	function checkRating(rating,idEntitaRating) {
		var disableRating = true;
		rating=rating.split("|");
		for(var i=0;i<rating.length;i++) {
			if (rating[i] == idEntitaRating) {
				// se ha giÃ  votato
				$(".thank_vote").html("Hai gi&agrave; votato!");
				disableRating = false;
				disableVoting(idEntitaRating);
				break;	
			} 
		}
		return disableRating;
	}

$(document).ready(function() {	

		jQuery('.recesnsioni_utente input, #titolo_film').example(function() {
          return $(this).attr('title');
        });

	if($("#rating_rec").length > 0) {
			// se non ha il cookie lo creo
			if(!rating){
				$.cookie("recensioniRating","0Rating|");
				rating = $.cookie("recensioniRating") 
			}			
				// se non ha mai votato 
				$(".link-rating a").click(function(){
				 	idEntitaRating = $(this).parents("div.rating_rec:eq(0)").attr("rel");
          			clickHandler(rating,idEntitaRating,$(this).attr("class"));
        		})
				hoverHandler(1);
				hoverHandler(2);
				hoverHandler(3);
				hoverHandler(4);
	}
});

$(window).ready(function(){

var box_trovocinema = $(".trovocinema").size();			 
	
	if (box_trovocinema == 0) {
	}else{
	$("#trovocinema-tabs").css("display","block");
	}
						 
});