function cambiaProfilo(id){
	if(confirm('Sei sicuro di voler aggiornare il tuo profilo?')){
		window.location = 'artista_pagamento_mod.php?profilo_id='+id;
	}
}


function conferma(videoname){
	document.artisti_profilo.videowebcam1.value=videoname;
	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.commercial3.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();    
}

function campoAgenzia(){

	if($('#agenzia_spettacolo').val()== "0"){

		$('#agenzia_elenco').hide();
		$('#altra_agenzia').hide();
		$('#agenzia_referente').hide();
		$('#agenzia_contatto').hide();
		
		$('#agenzianome').val("");
		$('#agenziareferente').val("");
		$('#agenziacontatto').val("");
	
	}else {
	
		$('#agenzia_elenco').show();

		if($('#agenzia_id').val()== ""){
			
			$('#altra_agenzia').hide();
			$('#agenzia_referente').hide();
			$('#agenzia_contatto').hide();
			
			$('#agenzianome').val("");
			$('#agenziareferente').val("");
			$('#agenziacontatto').val("");
				
		}else{
	
			if($('#agenzia_id').val()==0){
				$('#altra_agenzia').show();
				$('#agenzia_referente').show();
				$('#agenzia_contatto').show();			
			}else{
				$('#altra_agenzia').hide();
				$('#agenzia_referente').show();
				$('#agenzia_contatto').show();
				
				$('#agenzianome').val($("#agenzia_id option:selected").text());			

			}	
			
		}
	}
}


$(document).ready(function(){

	$('.extra').click(function() {
		valore = $(this).attr('rel');
		//alert(valore);
		
		$('#'+valore).hide();
		$('#'+valore+'completo').show();
	});		

	$('.nascondi').click(function() {
		valore = $(this).attr('rel');
		//alert(valore);
		
		$('#'+valore+'completo').hide();
		$('#'+valore).show();
	});		


	$('#agenzia_id').change(function() {
	
		campoAgenzia();

	});		
	$('#agenzia_spettacolo').change(function() {
	
		campoAgenzia();

	});		
	
	// validazione form artisti
	$("#frm_artisti").validate({
		errorPlacement: function(error, element) {
		       error.insertAfter(element);
		   },
		rules: {
			nome: "required",
			cognome: "required",
			email: {
				required: true,
				email: true
			},
			email2: {
				required: true,
        		equalTo: "#email"
			},
			psw: {
				required: true,
				minlength: 5
			},
			psw2: {
				required: true,
        		equalTo: "#psw"
			},			
		},
		messages: {
			nome: "<br />Il campo Nome &egrave; obbligatorio",
			cognome: "<br />Il campo Cognome &egrave; obbligatorio",
			email:{
				required:"<br />Il campo E-mail &egrave; obbligatorio",
				email:""
			},
			email2:{
				required:"<br />Il campo Conferma e-mail &egrave; obbligatorio",
				equalTo:"<br />L'e-mail inserita non corrisponde"
			},
			psw: {
				required: "<br />Il campo Password &egrave; obbligatorio",
				minlength: "<br />La password deve essere di almeno 5 caratteri"
			},
			psw2:{
				required:"<br />Il campo Conferma password &egrave; obbligatorio",
				equalTo:"<br />La password inserita non corrisponde"
			}
		}
	});


	// 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"
			},			
			telefono: "required"
		},
		messages: 
		{
			ragione_sociale: "",
			referente: "",
			email:{
				required:"",
				email:""
			},
			password1: "",
			password2: "",
			telefono: ""
		}
	});

	// 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: "<br />Il campo &egrave; obbligatorio",
			sesso: "<br />Il campo &egrave; obbligatorio",
			altezza_id: "<br />Il campo &egrave; obbligatorio",
			capelli_id: "<br />Il campo &egrave; obbligatorio",
			taglia_id: "<br />Il campo &egrave; obbligatorio",
			occhi_id: "<br />Il campo &egrave; obbligatorio",
			piede_id: "<br />Il campo &egrave; obbligatorio",
			etnia_id: "<br />Il campo &egrave; obbligatorio",
			//titolovideo1: ""
		},
		 submitHandler: function(form) {
		   form.submit();
		   f1();
 		}
	});



/*	
		$("#artisti").validate({

			//if(($('#agenzia_id').val()!= "")&&($('#agenzia_id').val()== 0)){
			
				errorPlacement: function(error, element) {
				       error.insertAfter(element);
				   },
				rules: {
					agenzia: "required",
					agenzia_contatto: "required"
				},
				messages: {
					agenzia: "",
					agenzia_contatto: ""
				}

			}else{
				
				errorPlacement: function(error, element) {
				       error.insertAfter(element);
				   },
				rules: {
					agenzia_contatto: "required"
				},
				messages: {
					agenzia_contatto: ""
				}	
				
			}	
				
		});	
*/


	// 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);
	}

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

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

	//Volume TG
	$('#volumeoff1').click(function() {
		$('#volumeoff1').hide();
		$('#volumeon1').show();
	});	

	$('#volumeon1').click(function() {
		$('#volumeon1').hide();
		$('#volumeoff1').show();
	});	

	$('#playon').click(function() {
		$('#playon').hide();
		$('#playoff').show();
		$('#stopon').show();
	});
		

	$('#stopon').click(function() {
		$('#stopon').hide();
		$('#stopoff').show();
		$('#playon').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');
	});	


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

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

	
	
});
