/* VIDEO PLAYER */
function youtube(id,W,H,container) {
	var params = {
		allowScriptAcess: "always",
		allowFullScreen: "true",
		wmode: "transparent"
	};
	var attributes = {
		id: "youtube",
		name: "YOUTUBE"
	};
	if (!container) {
		container='youtube';
	}
	swfobject.embedSWF("http://www.youtube.com/v/"+id+"&fmt=22&showinfo=0&fs=1", container, W, H, "9.0.0", false, false, params, attributes);
}

/* PLAYER HOMEPAGE */
function gfPlayer(urlXML) {
	var flashvars = {
		gf_XML: urlXML
	};
	var params = {
		allowScriptAcess: 'always',
		allowFullScreen: 'true',
		wmode: 'transparent'
	};
	var attributes = {
		id: 'gf-nominees',
		name: 'GOLDEN FOOT NOMINEES'
	};
	swfobject.embedSWF(img_dir+'/gf-flash.swf', 'gf-nominees', 478, 289, '9.0.0', false, flashvars, params, attributes);
}

function setFlashContent(xml,W,H){
	var flashvars = {
		partnerXML: xml
	};
	var params = {
		allowScriptAcess: 'always',
		allowFullScreen: 'true',
		wmode: 'transparent'
	};
	var attributes = {
		id: 'gf-slide',
		name: 'GOLDEN FOOT SLIDER'
	};
	swfobject.embedSWF(img_dir+'/partner-gallery.swf', 'gf-slide', W, H, '9.0.0', false, flashvars, params, attributes);
}
function setFlashContentNewHome(xml,W,H,idpag){
	var flashvars = {
		partnerXML: xml
	};
	var params = {
		allowScriptAcess: 'always',
		allowFullScreen: 'true',
		wmode: 'transparent'
	};
	var attributes = {
		id: idpag,
		name: 'GOLDEN FOOT SLIDER'
	};
	swfobject.embedSWF(img_dir+'/partner-gallery.swf', idpag, W, H, '9.0.0', false, flashvars, params, attributes);
}
/* PNG HACK */
$(function(){
	$(document).pngFix({ blankgif: img_dir+'pixel.gif' });
	
	/* SELEZIONE NOMINATIVI PAGINA 2010 NOMINEEES LIST */
		
		$(".nomineeslist").click(function () {
			var morecheck;	
			morecheck=$(".nomineeslist:checked").length;
			if(morecheck > 10){
				alert("ATTENTION : You have selected more than 10 names ");
			} 
		});
		$("#listnomin").click(function () {
			var ischeck = '';								 
			ischeck=$(".nomineeslist:checked").length;
			if(ischeck == '10'){
				var ind = '';
				ind = $("#setIndirizzo").attr("value");
				var a ='';
				if(ind != '' ){
					var a=ind.match("@");
					if(a=='@'){
						$("#quest").submit();							  	
					}
					 else{
						alert("Invalid e-mail address");
					}
				}
				else{
					alert("e-mail address empty");
				}		
			}
			else{
				alert("You have to select 10 names");
			}						 
		});
});

/* CARICAMENTO CONTENUTI AJAX */
function callContent(urlXML,box,loader) {
	
	var container = (!box?'#hook':box);
	var loading = (!loader?'.loader-ajax':loader);
	
	$.ajax({
		url: urlXML,
		dataType: 'html',
		beforeSend: function(){
			$(container).html('');
			$(loading).show();
		},
		success: function(data,textStatus){
			$(loading).hide();
			$(container).html(data);
		},
		error: function(){
			$(container).html('<h3 style="text-align: center;">Servizio non disponibile</h3>');
			$(loading).hide();
		}
	});
}

/* CARATTERI MANCANTI */
function charLeft() {
	var msgLength = $('#text-comment').val().length;
	if(msgLength >= 600){
		$('#char-left').html(0);
		$('#text-comment').val($('#text-comment').val().substring(0,600));
		alert('Il messaggio puņ contenere massimo 600 caratteri.');
	} else {
		$('#char-left').html(600 - msgLength);
	}
}

$(function(){
	$('#text-comment').change(function(){charLeft()});
	$('#text-comment').keypress(function(){charLeft()});
	$('#commentform').submit(function(){
		var text_value = $('#text-comment').val();
		var comment = jQuery.trim(text_value);
		$('#text-comment').val(comment);
	});
	
});

/* TABELLA DOCUMENTI */
$(function(){
	$('.doc-year').css('cursor','pointer');
	$('.doc-year').click(function(){
		$(this).next('.doc-year-container').toggle('normal');
	});
	
	$('.doc-table tr').hover(
		function(){ $(this).children('td').css('background-color','#fff')},
		function(){ $(this).children('td').css('background-color','transparent')}
	);
});

/* ORA DEI POST DEL FORUM */
function lastPostHour(postHour,postDay) {
	var currentTime = new Date(); 
	var hours = currentTime.getHours(); 
	var day = currentTime.getDate(); 
	
	if (hours < 10) hours = "0"+hours;
	if (day < 10) day = "0"+day;
	
	var hourAgo = hours + (24-postHour);
	var dayAgo = day - postDay;
	
	if (postDay == day) {
		hourAgo = hours - postHour;
		hourAgo==1?ora=" hour ago":ora=" hours ago";
		document.write(" "+hourAgo + ora);
	} else if (hourAgo > 24 || dayAgo > 1) {
		dayAgo>1?giorno=" day ago":giorno=" days ago";
		document.write(" "+dayAgo + giorno);
	} else {
		hourAgo==1?ora=" hours ago":ora=" hours ago";
		document.write(" "+hourAgo + ora);
	}	
}

/* SONDAGGIO HOME */
/*function survey_serialize() {
	var action = $('#survey-home').attr('action');
	var qs = '';
	
	$('#survey-home input:hidden').each(function(){
		qs += $(this).attr('name')+'='+$(this).attr('value')+'&';
	});
	$('#survey-home input:radio').each(function(){
		var label = $(this).next().html();
		label = jQuery.trim(label); 
		var value = $(this).attr('name')+'='+$(this).attr('value')+'&';
		qs += value;
		$(this).hide();
		$(this).next().html('<a href="'+action+'?'+qs+'">'+label+'</a><br/>');
	});
	$('#submit-survey').hide();
}*/
function survey_redirect() {
	setTimeout(function(){
		window.location.href = online_path+'/Home.html';			
	}, 7500);
}

/* FADE IMMAGINI TESTATA */
function fadeimmagini() {
	var i=1;
	
	$('#winner-img').css('background-image','none');
	$('#winner-img img.img-header:first').show();
	
	var timer = setInterval(function(){
		$('#winner-img img.img-header:visible').fadeOut(2000);
		if ( i >= $('#winner-img img.img-header').length) i = 0;
		$('#winner-img img.img-header:eq('+i+')').fadeIn(3000);
		i++;
	},6000);
}
