/***************************************/
// jQuery Tabber
// By Jordan Boesch
// www.boedesign.com
// Dec 25, 2007 (Merry Christmas!)
/***************************************/

/***************************************/
// modified 
// By Emanuele De Cupis
// www.emaxart.com
// June 21, 2010 (happy summer!)
/***************************************/

(function(jQuery){
		  
	$.extend($, {
		jtabber: function(params){

	// parameters
				var navDiv = params.mainLinkTag;
				var selectedClass = params.activeLinkClass;
				var hiddenContentDiv = params.hiddenContentClass;
				var showDefaultTab = params.showDefaultTab;
				var showErrors = params.showErrors;
				var effect = params.effect;
				var effectSpeed = params.effectSpeed;
				
				// If error checking is enabled
				if(showErrors){
					if(!$(navDiv).attr('title')){
						alert("ERROR: The elements in your mainLinkTag paramater need a 'title' attribute.\n ("+navDiv+")");	
						return false;
					}
					else if(!$("."+hiddenContentDiv).attr('id')){
						alert("ERROR: The elements in your hiddenContentClass paramater need to have an id.\n (."+hiddenContentDiv+")");	
						return false;
					}
				}
				
				// If we want to show the first block of content when the page loads
				if(!isNaN(showDefaultTab)){
					showDefaultTab--;
					$("."+hiddenContentDiv+":eq("+showDefaultTab+")").css('display','block');
					$(navDiv+":eq("+showDefaultTab+")").addClass(selectedClass);	
				}
				

	//edc: variabili locali e private, utilizzate dalle funzioni di automazione
	this.cursor_index = 0;

	//timer
	this.timer = null
	
	var that = this;
	

	//edc: funzione che sposta l'indice del cursore
	var ShowNext = function(){
		that.cursor_index = (that.cursor_index + 1) % $(navDiv).length;
		var el = $(navDiv).get(that.cursor_index);
		ShowElement(el);
    
	}


	//edc: funzione che mostra un elemento a partire dal corrispindente elemento di navigazione
	var ShowElement = function(el){
	
		//edc: elemento selezionato
		var $this = $(el);

		// once clicked, remove all classes
		$(navDiv).removeClass();
		  
		// hide all content
		$("."+hiddenContentDiv).css('display','none');
						
		// now lets show the desired information
		$this.addClass(selectedClass);
		var contentDivId = $this.attr('title');
						
		if(effect != null){
							
			switch(effect){								
				case 'slide':
					$("#"+contentDivId).slideDown(effectSpeed);
					break;
				case 'fade':
					$("#"+contentDivId).fadeIn(effectSpeed);
					break;								
			}
								
		} else {
			$("#"+contentDivId).css('display','block');
		}
		
		return false;
	}

	var StartTimer = function(){
		that.timer = setInterval(ShowNext, params.auto);
	}
	var StopTimer = function(){
		clearInterval(that.timer);
	}
	

	 //edc: differenzio i comportamenti a seconda che sia in regime automatico o meno
	if(params.auto && !isNaN(params.auto)){ 
		//scateno l'automatismo
		StartTimer();
		//TODO: faccio in modo che l'hover interrompa temporaneamente il timer, utile per la lettura
		//gestisco la possibilità di spostarmi ad una slide arbitraria
		$(navDiv).click(function(){
			var $this = $(this);

			StopTimer();
			that.cursor_index = $(navDiv).index($this);
			ShowElement(this);
			StartTimer();
		});
		
	} else {
		$(navDiv).click(function(){
			ShowElement(this);
		});
	}
}

     

	})
	
})(jQuery);	


/***************************************/
// jQuery Tabber
// By Jordan Boesch
// www.boedesign.com
// Dec 25, 2007 (Merry Christmas!)
/***************************************/

/***************************************/
// modified 
// By Emanuele De Cupis
// www.emaxart.com
// June 21, 2010 (happy summer!)
/***************************************/

(function(jQuery){
		  
	$.extend($, {
		jtabber: function(params){

	// parameters
				var navDiv = params.mainLinkTag;
				var selectedClass = params.activeLinkClass;
				var hiddenContentDiv = params.hiddenContentClass;
				var showDefaultTab = params.showDefaultTab;
				var showErrors = params.showErrors;
				var effect = params.effect;
				var effectSpeed = params.effectSpeed;
				
				// If error checking is enabled
				if(showErrors){
					if(!$(navDiv).attr('title')){
						alert("ERROR: The elements in your mainLinkTag paramater need a 'title' attribute.\n ("+navDiv+")");	
						return false;
					}
					else if(!$("."+hiddenContentDiv).attr('id')){
						alert("ERROR: The elements in your hiddenContentClass paramater need to have an id.\n (."+hiddenContentDiv+")");	
						return false;
					}
				}
				
				// If we want to show the first block of content when the page loads
				if(!isNaN(showDefaultTab)){
					showDefaultTab--;
					$("."+hiddenContentDiv+":eq("+showDefaultTab+")").css('display','block');
					$(navDiv+":eq("+showDefaultTab+")").addClass(selectedClass);	
				}
				

	//edc: variabili locali e private, utilizzate dalle funzioni di automazione
	this.cursor_index = 0;

	//timer
	this.timer = null
	
	var that = this;
	

	//edc: funzione che sposta l'indice del cursore
	var ShowNext = function(){
		that.cursor_index = (that.cursor_index + 1) % $(navDiv).length;
		var el = $(navDiv).get(that.cursor_index);
		ShowElement(el);
    
	}


	//edc: funzione che mostra un elemento a partire dal corrispindente elemento di navigazione
	var ShowElement = function(el){
	
		//edc: elemento selezionato
		var $this = $(el);

		// once clicked, remove all classes
		$(navDiv).removeClass();
		  
		// hide all content
		$("."+hiddenContentDiv).css('display','none');
						
		// now lets show the desired information
		$this.addClass(selectedClass);
		var contentDivId = $this.attr('title');
						
		if(effect != null){
							
			switch(effect){								
				case 'slide':
					$("#"+contentDivId).slideDown(effectSpeed);
					break;
				case 'fade':
					$("#"+contentDivId).fadeIn(effectSpeed);
					break;								
			}
								
		} else {
			$("#"+contentDivId).css('display','block');
		}
		
		return false;
	}

	var StartTimer = function(){
		that.timer = setInterval(ShowNext, params.auto);
	}
	var StopTimer = function(){
		clearInterval(that.timer);
	}
	

	 //edc: differenzio i comportamenti a seconda che sia in regime automatico o meno
	if(params.auto && !isNaN(params.auto)){ 
		//scateno l'automatismo
		StartTimer();
		//TODO: faccio in modo che l'hover interrompa temporaneamente il timer, utile per la lettura
		//gestisco la possibilità di spostarmi ad una slide arbitraria
		$(navDiv).click(function(){
			var $this = $(this);

			StopTimer();
			that.cursor_index = $(navDiv).index($this);
			ShowElement(this);
			StartTimer();
		});
		
	} else {
		$(navDiv).click(function(){
			ShowElement(this);
		});
	}
}

     

	})
	
})(jQuery);	



