/*
 * Classe di gestione per i componenti della pagina
 * Tutti i componeti che necessitano una gestione interattivata devono essere registrati in questa classe
 * N.B.: Tutti gli item aggiunti a questa classe devono avere un attributo section e type valido per la loro identificazione
 */

 function compManager(){
 	this.items=new Array(); //Array che contiene tutti i componenti registrati sulla pagina
	
	this.addItem=addItem;
	this.getCompBySection=getCompBySection;
	this.getCompByType=getCompByType;
	this.getCompById=getCompById;
	
	function addItem(item){ //Aggiunge un nuovo componenete all'array principale
		this.items.push(item);
	}
	
	function getCompBySection(section){ //Ritorna un array con tutti i componenti di una sezione specifica
		var buffer_cmp=new Array();
		
		var i=0;
		for (i = 0; i < this.items.length; i++) {
			if(this.items[i].section==section){
				buffer_cmp.push(this.items[i]);
			}
		}
		
		return buffer_cmp;
	}
	
	function getCompByType(type){ //Ritorna un array con tutti i componenti di una sezione specifica
		var buffer_cmp=new Array();
		
		var i=0;
		for (i = 0; i < this.items.length; i++) {
			if(this.items[i].type==type){
				buffer_cmp.push(this.items[i]);
			}
		}
		
		return buffer_cmp;
	}
	
	function getCompById(id){ //Ritorna il componente con l'id specificato
		var i=0;
		for (i = 0; i < this.items.length; i++) {
			if(this.items[i].id==id){
				return this.items[i];
			}
		}
	}
 }
 
 var components=new compManager();
 
 $(document).ready(function(){
    if(show_menu=='no'){
        $(document).bind("contextmenu",function(e){
            return false;
        });
    }
    
    /*
 	 * Popup delle foto nei contenuti utente
 	 */
 	$("a.userPopup").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'autoDimensions':	true,
		'hideOnContentClick': true
	});
});
 
 /*
  * Definizione della funzione trim per le stringhe
  */
 String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

/*
 * Recupare i parametri di get dall'url della pagina
 */
function gup( name ){
     name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
     var regexS = "[\\?&]"+name+"=([^&#]*)";
     var regex = new RegExp( regexS );
     var results = regex.exec( window.location.href );
     if( results == null )
          return "";
     else
          return results[1];
} 

