function conferma(videoname){
	document.artisti_profilo.videowebcam1.value=videoname;
	tb_remove();
	document.getElementById('testovideo1webcam').innerHTML="<span style='color:green; font-weight:bold;'>Il video &egrave; stato inserito correttamente</span>";
}

function Categoria(ID){
	document.location = "artista_registrazione.php?categoria_id=" + ID;
}

$(function() {
	$(".abbonamento").tooltip({
		bodyHandler: function() {
			return $($(this).attr("href")).html();
		},
		showURL: false
	});
});

function crea(dati){
	document.getElementById('video_home').innerHTML=dati;
}

function videoTickerHome(data){
	//alert(data);

	//Movimento pulsanti	
	$(".fototicker").hide("slow", function () {
		// use callee so don't have to name the function
		$(this).next().hide("slow", arguments.callee); 
	});
	
	$(".fototicker").fadeOut("slow");
	document.getElementById('video_ticker').innerHTML=data;
	$(".fototicker").fadeIn("slow");

}

function videoTickerHome1(data){
	//alert(data);

	//Movimento pulsanti	
	$(".fototicker1").hide("slow", function () {
		// use callee so don't have to name the function
		$(this).next().hide("slow", arguments.callee); 
	});
	
	$(".fototicker1").fadeOut("slow");
	document.getElementById('video_ticker1').innerHTML=data;
	$(".fototicker1").fadeIn("slow");

}

function videoTickerHome2(data){
	//alert(data);

	//Movimento pulsanti	
	$(".fototicker2").hide("slow", function () {
		// use callee so don't have to name the function
		$(this).next().hide("slow", arguments.callee); 
	});
	
	$(".fototicker2").fadeOut("slow");
	document.getElementById('video_ticker2').innerHTML=data;
	$(".fototicker2").fadeIn("slow");

}

function videoHome(data,volume){
	caricaVideo(data,volume);
}

/*
function caricaVideo(data,volume){
	var s1 = new SWFObject("http://www.castyourselftv.com/include/swf/flvplayer.swf","single","300","290","7");
	s1.addParam("allowfullscreen","true");
	s1.addParam("wmode", "transparent");
	s1.addVariable("file","/upload_video/"+data);
	s1.addVariable("width","300");
	s1.addVariable("height","290");
	s1.addVariable("autostart", "true"); 
	if(volume=='off') s1.addVariable("volume", "0");
	s1.write("video_home");
}
*/

/*
function caricaVideo(data){
	var flashvars = {
		file:"http://www.castyourselftv.com/upload_video/"+data, 
		autostart:"true"
	}

	var params = {
		allowfullscreen:"true", 
		allowscriptaccess:"always",
		wmode:"transparent"
	}

	var attributes = {
		id:"video_home",  
		name:"video_home"
	}

	swfobject.embedSWF("playernew/player-viral.swf", "video_home", "300", "290", "9.0.115", false, flashvars, params, attributes);	
}
*/

function caricaVideo(data){

	flowplayer("video_home", { src: "flowplayer/flowplayer.commercial-3.1.5.swf", wmode: 'transparent' }, { 

		key: '#$06a14ac530bedd42f8a',

		logo: { 
			url: '/img/brand.png', 
			fullscreenOnly: false,
			top: '15%', 
			right: '15%',
			width: '15%', 
			height: '15%' 													
		},

		clip: {

			url: "http://www.castyourselftv.com/upload_video/"+data, 
			autoPlay: true
		},

		onLoad: function() {
			this.mute();
	    }		
		
	});
}

function logVideo(videoID){
	//alert("video alert");
	$.post('ajax_logvideo.php?videoID='+videoID);
}

function giraVideo(volume,tipo){
	
	//alert(volume + " - " + tipo);
	$.post('ajax_video.php?tipo='+tipo, $('input:checked'), function(data){ videoHome(data,volume)}, 'html');
	setTimeout(giraVideo,32000);
}  

function giraVideoTicker(){

	//alert("nuovi video");
	$.post('ajax_videoticker.php', $('input:checked'), function(data){ videoTickerHome(data)}, 'html');
	setTimeout(giraVideoTicker,10000);
}  

function giraVideoTicker1(){

	//alert("nuovi video");
	$.post('ajax_videoticker1.php', $('input:checked'), function(data){ videoTickerHome1(data)}, 'html');
	setTimeout(giraVideoTicker1,15000);
}  

function giraVideoTicker2(){

	//alert("nuovi video");
	$.post('ajax_videoticker2.php', $('input:checked'), function(data){ videoTickerHome2(data)}, 'html');
	setTimeout(giraVideoTicker2,10000);
}  

function f1(){
	$("#wrapper").fadeTo("fast", 0.2); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	$($("#fileprogress-content")).show();
}
function f2(){
	$("#wrapper").fadeTo("fast", 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	$($("#fileprogress-content")).hide();    
}


$(document).ready(function(){

	// validazione form artisti
	$("#frm_artisti").validate({
		errorPlacement: function(error, element) {
		       error.insertAfter(element);
		   },
		rules: {
			nome: "required",
			cognome: "required",
			email: {
				required: true,
				email: true
			},
			password1: "required",
			password2: {
        		equalTo: "#password1"
			},
	  		giorno: "required",
			mese: "required",
			anno: "required",
			citta_nascita: "required",
			indirizzo_residenza: "required",
			citta_residenza: "required",
			pv_residenza_id: "required",
			cellulare: "number",
			enpals: "required",
			collocazione: "required",
			agenzia_spettacolo: "required",
			profilo_id: "required",
			esperienza_id: "required",
			durata_id: "required",
			condizioni: "required"
		},
		messages: {
			nome: "",
			cognome: "",
			email:{
				required:"",
				email:""
			},
			password1: "",
			password2:{
				equalTo:""
			},
			giorno: "",
			mese: "",
			anno: "",
			citta_nascita: "",
			indirizzo_residenza: "",
			citta_residenza: "",
			pv_residenza_id: "",
			cellulare: "",
			enpals: "",
			collocazione: "",
			agenzia_spettacolo: "",
			profilo_id: "",
			esperienza_id: "",
			durata_id: "",
			condizioni: ""
		}
	});


	// validazione form aziende
	$("#frm_aziende").validate({
		errorPlacement: function(error, element) {
		       error.insertAfter(element);
		   },
		rules: {
			ragione_sociale: "required",
			referente: "required",
			email: {
				required: true,
				email: true
			},
			password1: "required",
			password2: {
        equalTo: "#password1"
      },			
			settore_id: "required",
			indirizzo: "required",
			citta: "required",
			provincia_id: "required",
			condizioni: "required"
		},
		messages: {
			ragione_sociale: "",
			referente: "",
			email:{
				required:"",
				email:""
			},
			password1: "",
			password2: "",
			settore_id: "",
			indirizzo: "",
			citta: "",
			provincia_id: "",
			condizioni: ""
		}
	});

	// validazione form artisti
	$("#frm_password").validate({
		errorPlacement: function(error, element) {
		       error.insertAfter(element);
		   },
		rules: {
			psw_old: "required",
			psw: "required",
			psw2: "required"
		},
		messages: {
			psw_old: "",
			psw: "",
			psw2: ""
		}
	});


	// validazione form artisti
	$("#artisti_profilo").validate({
		errorPlacement: function(error, element) {
		       error.insertAfter(element);
		   },
		rules: {
			categoria_id: "required",
			sesso: "required",
			altezza_id: "required",
			capelli_id: "required",
			taglia_id: "required",
			occhi_id: "required",
			piede_id: "required",
			etnia_id: "required",
			titolovideo1: "required"
		},
		messages: {
			categoria_id: "",
			sesso: "",
			altezza_id: "",
			capelli_id: "",
			taglia_id: "",
			occhi_id: "",
			piede_id: "",
			etnia_id: "",
			titolovideo1: ""
		},
		 submitHandler: function(form) {
		   form.submit();
		   f1();
 		}
	});
		
	// Lancio lo script per i video ticker
	if($('.video_ticker_home').width() > 0){
		giraVideoTicker();
	}

	// Lancio lo script per i video ticker in primo piano
	if($('#video_ticker1').width() > 0){
		giraVideoTicker1();
	}

	// Lancio lo script per i video ticker free
	if($('#video_ticker2').width() > 0){
		giraVideoTicker2();
	}
	
	if($('#video_home').width() > 0){
		giraVideo('on',0);
	}

	$('#volumeoff').click(function() {
		$('#volumeoff').hide();
		$('#volumeon').show();
	});	

	$('#volumeon').click(function() {
		$('#volumeon').hide();
		$('#volumeoff').show();
	});		


	$("#artisti_profilo").submit(function () {
	 
		//f1();

	});	


	$(".novideo").mouseover(function() {
		var novideo_id = $(this).attr('id');
		$('#'+novideo_id).addClass('sfondo');
	});

	$(".novideo").mouseout(function() {
		var novideo_id = $(this).attr('id');
		$('#'+novideo_id).removeClass('sfondo');
	});	
	
});