// JavaScript Document
/////////////////////////////// PROTO ////////////////////////////////////////77


String.prototype.extractSubstr = function(a,b) {

return this.substring(a,b)


}


function setDecimali(num){
	var numero = num.toString();
	var arr_num = numero.split(".");
	if (numero.indexOf(".") != (-1))
	{
		if (arr_num[1].length == 1)
		{
			numero += 0;
		}
		else
		{
			numero = arr_num[0] + "." + arr_num[1].substring(0, 2);
		}
		numero = parseFloat(numero);
	}
	else
	{
		numero = parseInt(numero);
	}
	return(numero)

}

////////randomizzare un array


Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
}

//With that code in place we can shuffle the content of our array as easily as we can sort it. Here's an example:
//var myary = [0,1,2,3,4,5,6,7,8,9];
//myary.shuffle();






/*
 * 
 * Textarea Word Count Jquery Plugin 
 * Version 1.0
 * 
 * Copyright (c) 2008 Roshan Bhattarai
 * website : http://roshanbh.com.np
 * 
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
*/

jQuery.fn.wordCount = function(params, limit){
	var p = {
		counterElement:"display_count"
	};
	var total_words;
	var str_tot;
	
	if(L=="it"){
	
		str_tot="( totale parole: ";
	
	}else{
		
		
		str_tot	=" ( word count: ";
		
	}
	
	if(params) {
		jQuery.extend(p, params);
	}
	
	//for each keypress function on text areas
	//this.bind('keypress keyup',function() //versione originale
	this.bind('keypress keyup input paste',function()  
	{ 
		total_words=this.value.split(/[\s\.\?]+/).length;
		jQuery('#'+p.counterElement).html(' '+str_tot+ ' '+total_words+' ) ');
		
		
		if (total_words>limit){
		
			jQuery('#'+p.counterElement).css('color','#990000')
		
		}else{
			
			jQuery('#'+p.counterElement).css('color', '#000000')
			
		}
		
	});	
	
	
	//alert(total_words);
	
	
};



// chiamata in formdomandapartceipazione2 x conrolalre parole al popolamento della form
jQuery.fn.wordCount2 = function(textarea, params, limit){
	var p = {
	counterElement:"display_count"
	};
	var total_words;
	var str_tot;
 
	if(L=="it"){
		str_tot="( totale parole: ";
	}
	else{
		str_tot =" ( word count: ";
	}
 
	if(params) {
		jQuery.extend(p, params);
	}

	total_words=$('#'+textarea).val().split(/[\s\.\?]+/).length;
	jQuery('#'+p.counterElement).html(' '+str_tot+ ' '+total_words+' ) ');
  
  if (total_words>limit){
   jQuery('#'+p.counterElement).css('color','#990000')
  }
	else{
   jQuery('#'+p.counterElement).css('color', '#000000')
  }
};



jQuery.fn.charachterCount = function(params, minlimit, maxlimit){
	var p = {
		counterElement:"display_count"
	};
	var total_char;
	var str_tot;
	
	if(L=="it"){
	
		str_tot="( totale caratteri: ";
	
	}else{
		
		
		str_tot	=" ( number of charachters: ";
		
	}
	
	if(params) {
		jQuery.extend(p, params);
	}
	
	//for each keypress function on text areas
	//this.bind('keypress keyup',function() //versione originale
	this.bind('keypress keyup input paste',function()
	{ 
		total_char=this.value.length;
		jQuery('#'+p.counterElement).html(' '+str_tot+ ' '+total_char+' ) ');
		
		
		if (total_char<minlimit || total_char>maxlimit){
		
			jQuery('#'+p.counterElement).css('color','#990000')
		
		}else{
			
			jQuery('#'+p.counterElement).css('color', '#000000')
			
		}
		
	});	
	
	
	//alert(total_words);
	
	
};





//ZIPPO due array in una

function zip(arrayA, arrayB) {
    var length = Math.min(arrayA.length, arrayB.length);
    var result = [];
    for (var n = 0; n < length; n++) {
        result.push([arrayA[n], arrayB[n]]);
    }
    return result;
}



//alert su form

function scrivi(what, lang, step){
	var strArray="alerts_"+lang
	var indexAr=eval(strArray)[what];
	//alert(step)
	//step mi serve per quando clono i campi nella form ad es della domanda di partecipazione
	
	
	if(step==3){  //step dei visitatori  (step 1)//per gestire gli alert dei campi dinamici in modo generico, non essendoci a monte la voce prevista in languages
		
	//estraggo una nuova stringa che toglie i caratteri _N
		var newStr=what.slice(0,-2)
		
		indexAr=eval(strArray)[newStr];
		
		//alert(newStr)
	
	}else{ 
		
		indexAr=eval(strArray)[what];
		
	}
	
	alert(indexAr);
	
	
}

function getTxt_lang (what, lang){ //testo di un elemento
	var objTesti="txt_"+lang;
	var indexObjTx=eval(objTesti)[what];
	return indexObjTx=eval(objTesti)[what];
}




function split_string(what, lang, separator){//splitto una stringa in un array

		var objTesti="txt_"+lang;
		var indexObjTx=eval(objTesti)[what];
		
		var ar=new Array();
		ar=indexObjTx.split(",");
		return ar
		
}


jQuery.fn.setBg_img=function (img){	//setto background di un elemento 			
		
		$(this).css({backgroundImage: "url("+img+")", backgroundRepeat: 'no-repeat', backgroundPosition: 'left top'})
		
		

}



function setStrTxt_lang(what, lang){ //restituisce la stringa in una variabile
		//
		var objTesti="txt_"+lang;
		var indexObjTx=eval(objTesti)[what];
		return indexObjTx;
		
}


jQuery.fn.setTxt_lang=function (what, lang){ //testo di un elemento
		//alert(indexObjTx)
		var objTesti="txt_"+lang;
		var indexObjTx=eval(objTesti)[what];
		$(this).text(indexObjTx);
		
}



jQuery.fn.setHtml_lang=function (what, lang){ //html di un elemento
		var objTesti="txt_"+lang;
		var indexObjTx=eval(objTesti)[what];
		$(this).html(indexObjTx);
}


jQuery.fn.setAttr_lang=function (what, lang, attr_string){ //per settare attributi
		var objTesti="txt_"+lang;
		var indexObjTx=eval(objTesti)[what];
		$(this).attr(attr_string, indexObjTx);

}


jQuery.fn.setImg_lang=function (img){//inserisco immagine in un elemento
		
		var target=img;
		var imgToInsert=new Image();
		imgToInsert.src=target;
		$(this).html(imgToInsert);
		//alert(target)

}




//aggiungo ancora ad url


jQuery.fn.setAnchor=function(ancora){
	
	//looppo dentro a degli <a>

					$(this).each(
					
									function(i){
										
										var $href=$(this).attr('href')+ancora;
										$(this).attr('href', $href);
										
					});
					
					
					
}
					
					
					
					
					


////////////////disabilito numero di skype

jQuery.fn.noSkype=function(num){

	var str=$(this).text();
	var l=str.length;
	//determino la diufferenza per spezzare il testo alpunto desiderato
	var diffright=l-num;
	
	var diffleft=l-diffright;
	
	
	//estraggo la parte sinistra della stringa
	var newstrLeft=str.substring(0,diffleft);
	
	// e la parte destra
	var newstrRight=str.substring(diffleft,l)
	
	var _span="<span class=\"hide\">_</span>";
	
	var totalStr=newstrLeft+_span+newstrRight
	
	//alert(totalStr);
	$(this).html(totalStr);
	

	
}



//GESTIONE DELLE FORM

//svuoto campo form al click

jQuery.fn.clearField=function(){

	$(this).bind ('focus',function(){if(this.value == this.defaultValue){$(this).val('');}})
	$(this).bind ('blur',function(){if(this.value == ''){$(this).val(this.defaultValue);}})
	
	//alert($(this).attr('id'));
	

}


//plugin per cancellare form
	
	$.fn.clearForm = function() {
      return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        	if (tag == 'form')
          		return $(':input',this).clearForm();
        	if (type == 'text' || type == 'password' || tag == 'textarea')
          		this.value = '';
        	else if (type == 'checkbox' || type == 'radio')
          		this.checked = false;
        	else if (tag == 'select')
          		this.selectedIndex = -1;
      });
    };
	



//routine di convalida dei campi


function checkForm(fieldset, send, step){
	
	//send true/false per fare submit o meno da questa funzione

	 var $fieldset= $(fieldset);
	 var $els=$fieldset.find(':input') //get textbox and textarea elements
	 
	 validated=true  // l'area di validità della variabile è "global" per rendere compatibile la funzione con la form della domanda degli expo
		
	  
	  $els.each(function(){ //loop thru these elements
							
						
						//	if ($(this).hasClass('selectRequired') && $(this).val() === null  ) { // tendine con classe selectRequired
							
							//NEW
							//select negli step dove nn basta che ci sia la selezione ma si deve anche aver cliccato su aggiungi per popolare
							if ($(this).hasClass('selectRequiredWithArray')){
												 
												 
														 if( $(this).val()==0 || $(this).val() === null ) {  //la tendina è vuota
																
																//alert($(this).val())
																scrivi($(this).attr('id'), L, step); 
																$(this).focus();
																validated=false;
																//$(this).underline(validated);
																return false //break out
																
																
																
														 }else{// la tendina è popolata
										
															
															var $ar=eval($(this).parent().parent().attr('rif'))
															//alert(typeof($ar))
															//controllo che l'array sia popolato
															if($ar.length<=0){
																scrivi('checkAddVis', L)
																validated=false;
																//$(this).underline(validated);
																return false //break out
														
															}
															
													
														 }
								
								
							}
														
														
														
													
													
							
							
							if ($(this).hasClass('selectRequired') && $(this).val()==0 || $(this).hasClass('selectRequired') && $(this).val() === null ) {
														//alert($(this).val())
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													
							
							}
							
							
							if ($(this).hasClass('selectRequired1') && $(this).val() =="") { //tendine con classe selectRequired1  ho tolto lo zero dallo scegli se serve come valore di una option
														//alert($(this).val())
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													
							
							}
							
						
							if($(this).attr('type')=="text" && $(this).hasClass('required')){  //campi di input con classe required
							
													if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
							
							}
							
							
							
							
							if($(this).attr('type')=="radio" && $(this).hasClass('requiredChecked')){  //campi radio concontrollo solo su un radio
							
													//alert($(this).attr('checked'))
													
													
													
													if ($(this).attr('checked')!="checked"){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
							
							}
							
							
							//privacy0 = document.frmContact.privacy[0].checked;
							//privacy1 = document.frmContact.privacy[1].checked;
							//associatoIt
						


							if($(this).attr('type')=="radio" && $(this).parent().attr('id')=="associatoIt"){  //campi radio con controllo sul gruppo di radio associato
						
							associato0=document.frm_domanda_expo.associato[0].checked
							associato1=document.frm_domanda_expo.associato[1].checked
							
							//presuppongo che siano due e di conoscere gli attributi value...
							
							if(!associato0 && !associato1){
								
									
								scrivi($(this).attr('name'), L, step); 
								$(this).focus();
								validated=false;
								return false
							
								
							}
							
						
						}
						
						
						if($(this).attr('type')=="radio" && $(this).parent().attr('id')=="esenteiva"){  //campi radio con controllo sul gruppo di radio esente iva
						
							esente0=document.frm_domanda_expo.esente_iva[0].checked
							esente1=document.frm_domanda_expo.esente_iva[1].checked
							
							//alert('yep')
							
							//presuppongo che siano due e di conoscere gli attributi value...
							
							if(!esente0 && !esente1){
								
									
								scrivi($(this).attr('name'), L, step); 
								$(this).focus();
								validated=false;
								return false
									
								
								
							}
							
						
						
						}

						
						
						if($(this).attr('type')=="radio" && $(this).parent().attr('id')=="_pconfigurazionePrecedente"){  //campi radio con controllo sul gruppo configurazione stand step 5
						
							stand0=document.frm_domanda_expo.configurazione_stand[0].checked
							stand1=document.frm_domanda_expo.configurazione_stand[1].checked
							
							//alert('yep')
							
							//presuppongo che siano due e di conoscere gli attributi value...
							
							if(!stand0 && !stand1){
								
									
								scrivi($(this).attr('name'), L, step); 
								$(this).focus();
								validated=false;
								return false
									
								
								
							}
							
						
						
						}
						
						
						
						if($(this).attr('type')=="radio" && $(this).parent().attr('id')=="preferenzaBox"){  //campi radio con controllo sul gruppo di radio box form stampa
						
							box0=document.frm_domanda_expo.preferenza_box[0].checked
							box1=document.frm_domanda_expo.preferenza_box[1].checked
							
							//alert('yep')
							
							//presuppongo che siano due e di conoscere gli attributi value...
							
							if(!box0 && !box1){
								
									
								scrivi($(this).attr('name'), L, step); 
								$(this).focus();
								validated=false;
								return false
									
								
								
							}
							
						
						
						}





					
							
							
							
							
							if($(this).hasClass('required20')){  //textarea con classe required e conteggio parole = 20
							
											if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
													
											var maxNum=$(this).attr('value').split(/[\s\.\?]+/).length;
											
											
											if (maxNum>50){
												
											
											
														scrivi('max20', L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
											
												
											}
														
								
							}
							
							
							
							
							if($(this).hasClass('min_maxRequired')){  //textarea con classe min_maxRequired e conteggio caratteri ripreso dagli attributi minlength e maxlength del campo nella form
							
											
											var minNum=$(this).attr('minlength')
											var maxNum=$(this).attr('maxlength')
											
											//alert(minNum)
											//alert(maxNum)
											
											if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
											//alert($(this).attr('value').length)
											
											
											if($(this).attr('value').length<minNum || $(this).attr('value').length>maxNum){
												
												
														scrivi('badLength', L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
													
												
												
											}
											
																									
								
							}
							
							
							
							if($(this).hasClass('min_maxNoRequired')){  //textarea con classe min_maxRequired e conteggio caratteri ripreso dagli attributi minlength e maxlength del campo nella form ma nn obbligatorio se vuoto
							
											
											var minNum=$(this).attr('minlength')
											var maxNum=$(this).attr('maxlength')
											
											//alert(minNum)
											//alert(maxNum)
											
											/*if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi($(this).attr('id'), L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}*/
													
											//alert($(this).attr('value').length)
											
											
											if($(this).attr('value').length>maxNum){
												
												
														scrivi('badLength', L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
													
												
												
											}
											
											
											/*if($(this).attr('value').length<minNum){
												
												
														scrivi('badLength', L, step); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
													
												
												
											}*/
											
																									
								
							}
							
							
							
							
							
							if($(this).attr('type')=="text" && $(this).hasClass('requiredCapIT')){  //campi CAP italiano
							
													if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi("cap", L); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
													if(validateZipCodeIT($(this).val())==false){
														
														
														$(this).val=""
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false
														
													}
							
							}
							
							
							
							
							
							if($(this).attr('type')=="text" && $(this).hasClass('requiredNumber')){  //campi CAP italiano e numerici in generale
							
													if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi("isNumber", L); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
													
													
													if (isNaN($(this).val())){ //controllo che sia un numero
	
															scrivi("isNumber", L)
															$(this).focus();
															validated=false;
															//$(this).underline(validated);
															return false //break out 
				
													}
													
													
			
							
													
													
							
							}
							
							
							
							
							if($(this).attr('type')=="text" && $(this).hasClass('required16')){  //campo mq
							
													if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi("isNumber", L); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
													
													
													if (isNaN($(this).val())){ //controllo che sia un numero
	
															scrivi("isNumber", L)
															
															
															
															$(this).val(16);
															$(this).focus();
															//$(this).change(function(){
															checkSum('input#mq_richiesti', 'input#mqsopp_richiesti', 'select#num_angoli_richiesti', costoAccontoMQ, costoMqsopp, costoPerAngolo, feedAssociato, accontoExpoIndiretti, numExpoIndiretti);
															
															validated=false;
															//$(this).underline(validated);
															return false //break out 
				
														
													
													
													
													
													}else{
														
														
													
													//se < 16 nn va bene però.....
														if ($(this).val()<16){
															//alert("Please fill out the field "+$(this).attr('id'))
															scrivi("min16", L); 
															
															$(this).val(16);
															$(this).focus();
															//$(this).change(function(){
															checkSum('input#mq_richiesti', 'input#mqsopp_richiesti', 'select#num_angoli_richiesti', costoAccontoMQ, costoMqsopp, costoPerAngolo, feedAssociato, accontoExpoIndiretti, numExpoIndiretti);
																				//  })
								 
															validated=false;
															//$(this).underline(validated);
															return false //break out 
															
														}
													
													
														
													}
													
							
							}
							
							
							
							if($(this).attr('type')=="text" && $(this).hasClass('requiredNumberMinValue')){  //campo numerico con controllo rispetto ai sui mq richiesti per lo stand
							
													if ($(this).val()==""){
														//alert("Please fill out the field "+$(this).attr('id'))
														scrivi("isNumber", L); 
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
													

													
													if (isNaN($(this).val())){ //controllo che sia un numero
	
															scrivi("isNumber", L)
															$(this).focus();
															validated=false;
															//$(this).underline(validated);
															return false //break out 
				
													}
													
													
													//se è > 300 e stand >= 48 mq
													if($(this).val()>300 && $('input#mq_richiesti').val() <=48){ //max 300 expo per stand fino a 48 mq
													
														
														scrivi('max300', L)
														$(this).focus();
														$(this).attr('value',300);
														
														validated=false;
														return false //break out 
													
													
													
													}else if($(this).val()>600 && ($('input#mq_richiesti').val() >48 && $('input#mq_richiesti').val() <=96 )){ // se è > 600 e stand //stand oltre i 48 mq
													
													
														scrivi('max600', L)
														$(this).focus();
														$(this).attr('value',300);
														validated=false;
														return false //break out 
													
													}else if($(this).val() > 900 && $(this).val() >96){ //max 900  per stand oltre i 96 mq
													
													
														scrivi('max900', L)
														$(this).focus();
														$(this).attr('value',300);
														validated=false;
														return false //break out 
													
													
													
													}
 													
													
			
							
							}
							
							
							
													
							
							if($(this).attr('type')=="text" && $(this).hasClass('emailRequired')){  //email con classe emailRequired
							
													if ($(this).val()==""){
														
														scrivi("email", L); //ometto il paramtro i perchè il controllo delle mail p generico, non è legato a un id specifico
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false //break out 
														
													}
													
												
													
													if (ControllaMail($(this).val())==false){
														$(this).val=""
														$(this).focus();
														validated=false;
														//$(this).underline(validated);
														return false
													}
													
													
							
							}
							
							
							
						
						
						function ControllaMail(EmailAddr){
						  // EmailAddr = document.modulo.email.value;
							//Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
							Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z]{2,})+$/;
							if (Filtro.test(EmailAddr))
								return true;
							else
							{
								//alert("Controlla che l'indirizzo di e-mail inserito sia nella forma nome@xxx.it");
								scrivi("email1", L)
								$(this).focus();
								//$(this).underline(validated);
								return false;
							}
						}
		
			
							
						
						
						function validateZipCodeIT(elementValue){
							var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
							if(zipCodePattern.test(elementValue)){
							return true;
							
							}else{
								
							scrivi("cap1", L)
								$(this).focus();
								//$(this).underline(validated);
								return false;
							}	
								
								
								
								
						}
							
						
					$(this).blur(function(){
   							var value=$.trim( $(this).val() );
							$(this).val( value );
	
					});
	
	

					
							
							
	  }) //end loop
	  
	  
	  
	 //alert(validated)
	// if(modulo!="stepA"){ //se nn sono nella pagina di domanda iscrizione
		 
	 if(validated && send){ 
	 
		// if(modulo !="A"){ //NB, A è il modulo dell'areaRis expo in cui si trova la form della domanda che è a step, nn faccio qui il submit sennò me la invia ad ogni step
		 
				 $($fieldset).submit()
		// }
	 
	 }
	// }
	 return validated//if this variable returns false, user is prevented from going on to next form page
	 
	// 
}//end function
	




////////////end form






//Spezzo stringa
//http://plugins.jquery.com/project/cutstring


$.fn.cutString=function(options){
var defaults = { 
   length: 20, 
   ellipsisText: "..." 
  }; 
 
var options = $.extend(defaults, options); 
return this.each(function(){
   obj = $(this); 
   var str = $.trim(obj.text()),
   strLen=str.length,
   optLen=options.length,
   len=0;
  function cut(){
            for (var i=0; i<strLen; i++) {
                len += (str.charCodeAt(i) > 128) ? 2 : 1;
                if (len > optLen) return str.substring(0,i) + options.ellipsisText;
            }
   return str;
  }  
   obj.text(cut());  
});

};

//utilizzo: es: $(this).find('a#mailDist').cutString({length:35})

////////////////////


/*
* jQuery.fn.typewriter( speed, callback );
*
* Typewriter, writes your text in a flow
*
* USAGE:
* $('.element').typewriter( speed, callback );
*
*
* Version 1.0.1
* www.labs.skengdon.com/typewriter/
* www.labs.skengdon.com/typewriter/js/typewriter.min.js
*/
;(function($){
	$.fn.typewriter = function( speed, callback ) {
		if ( typeof callback !== 'function' ) callback = function(){};
		var write = function( e, text, time ) {
			var next = $(e).text().length + 1;
			if ( next <= text.length ) {
				$(e).text( text.substr( 0, next ) );
				setTimeout( function( ) {
					write( e, text, time );
				}, time);
			} else {
				e.callback();
			}
		};
		return this.each(function() {
			this.callback = callback;
			var text = $(this).text();
			var time = speed/text.length;
			
			$(this).text('');
			
			write( this, text, time )
		});
	}
}(jQuery));


/////////////////////CYCLE PLUGIN SLIDER GENERATOR/////////////////////////




	jQuery.fn.setCycleGallery=function(fx, speed, timeout, idNext, idBack, PTOP, PRIGHT, PBOTTOM, PLEFT, WMAIN, HMAIN, WBTN, HBTN, LEFTNEXT, TOPNEXT, LEFTBACK, TOPBACK, WCONT, HCONT, IDCONT, dataFile, classSelector, IMGBTNLEFT, IMGBTNRIGHT ){
		
		// fx cycle, esempio scrollVert o scrollHorz
		//speed e timeout valori del cycle plugin
		//idNext e back = id dei bottoni next e back
		//PRIGHT TOP LEFT E BOTTOM --> psdding del contenitore generale
		//WMAIN e HMAIN --> width e heightr del contenitore generale
		//WBTN e HBTN --> width e height dei bottoni next e back
		//LEFTNEXT, TOPNEXT, LEFTBACK, TOPBACK --> positioning dei due div che contengono i bottoni next e back
		//WCONT e HCONT -->width e height del div che contiene le immagini dello slide
		//IDCONT--> id a cui punto l'oggetto cycle
		//classSelector  eventuale stile
		//nomi file bottoni
		
		var shtml='';
		shtml+='<!--contenitore generale foto-->';
		shtml+='<div style="padding:'+PTOP+'px '+PRIGHT+'px '+PBOTTOM+'px '+PLEFT+'px; width:'+WMAIN+'px; height:'+HMAIN+'px; overflow:hidden; position:relative" class="'+classSelector+'">';
		//bottoni next e back
		shtml+='<div style="position:absolute; width:'+WBTN+'px; height:'+HBTN+'px; left:'+LEFTBACK+'px; top:'+TOPBACK+'px;"><a href="Javascript:return false;"  id="b_back"><img src="../style/'+IMGBTNLEFT+'" alt="" /></a></div>';
		shtml+='<div style="position:absolute; width:'+WBTN+'px; height:'+HBTN+'px; left:'+LEFTNEXT+'px; top:'+TOPNEXT+'px;"><a href="Javascript:return false;"  id="b_next"><img src="../style/'+IMGBTNRIGHT+'" alt="" /></a></div>';
		//
		shtml+='<!--contenitore blocchi immagine-->';
		shtml+='<div style="width:'+WCONT+'px; height:'+HCONT+'px; overflow:hidden; position:absolute" id="'+IDCONT+'">';
		//
		

		///Qui ci devo passare le immagini
		
		
		

		shtml+='<!--end cont. blocchi immagine-->';
		shtml+='</div>';
		shtml+='<!--end contenitore generale-->';
		shtml+='</div>';
		
		$(this).html(shtml);
		
		
		popolaSlider(IDCONT, dataFile, fx, speed, timeout, idNext, idBack);  //in proto.js
		
		//alert(shtml)
		
	}
	
	
	
	function popolaSlider(ID, FILE, FX, SPEED, TIMEOUT, IDNEXT, IDBACK){
		
		//alert (ID);
		var trg="../includes/slide_cycle/";
		var fileToInclude=FILE;
		var composta=trg+fileToInclude;
		//alert(ID)
		var id="div#"+ID
		//composta=trg+L+fileToInclude;
	
		$(id).load(composta, function(){  //carico le icone
												//alert('oo')
												$(this).cycle({ 
																fx:    FX, 
																speed:  SPEED, 
																timeout: TIMEOUT, 
																next:   IDNEXT, 
																prev:   IDBACK
															});
												
												
												$(this).find("a[rel^='prettySlide']").prettyPhoto({
														animation_speed: 'fast', /* fast/slow/normal */
														slideshow: false, /* false OR interval time in ms */
														opacity: 0.80, /* Value between 0 and 1 */
														show_title: false, /* true/false */
														allow_resize: true, /* Resize the photos bigger than viewport. true/false */
														default_width: 500,
														default_height: 344,
														counter_separator_label: ' - ', /* The separator for the gallery counter 1 "of" 2 */
														theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
														overlay_gallery: false
														
													});
												
												}												
								);
		
		
		
		
		
		
		
	}


//////////////END GENERATOR


//***************************ANCORE

	$('a[href*=#]').click(function(event) {
								   
		event.preventDefault();
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target   || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 800);
				return false;
	   		}
	 	}
  });





/////////////////////////////////////////////////////////// altri


$("a[rel^='prettyPhoto']").prettyPhoto({
				animation_speed: 'fast', /* fast/slow/normal */
				slideshow: false, /* false OR interval time in ms */
				autoplay_slideshow: false, /* true/false */
				opacity: 0.80, /* Value between 0 and 1 */
				show_title: false, /* true/false */
				allow_resize: true, /* Resize the photos bigger than viewport. true/false */
				default_width: 500,
				default_height: 344,
				counter_separator_label: ' - ', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
				hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
				wmode: 'opaque', /* Set the flash wmode attribute */
				autoplay: true, /* Automatically start videos: True/False */
				modal: false, /* If set to true, only the close button will close the window */
				overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
				keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
				changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
				callback: function(){} /* Called when prettyPhoto is closed */
			});




/////collegato al prettyPhoto

function passMeFiles(ar, title, alt){$.prettyPhoto.open(ar, title, alt);}
