/**
 * @paquete Archivo de aplicacion
 * @Archivo sidebar.js	
 * @ruta includes/js/
 * @copyright 2011
 * @contacto richard@masfusion.com
 * @version 1.0
**/

// Quotes.
function quotes(quote_tab, automatic){	
	
	// Hide all information visible in the carousel.
	jQuery(".selected_opinion").fadeOut(700, function(){				 
		
		current_quote_tab = quote_tab;				

		// If it comes to final, return the carousel to the beginning.
		if(quote_tab < (jQuery(".opinions .opinion").length) && quote_tab >= 0){
			next_quote_tab = quote_tab + 1;	
		} else if(quote_tab < 0){
			current_quote_tab = jQuery(".opinions .opinion").length - 1;	
		}  else {
			next_quote_tab = 1;	
			current_quote_tab = 0;
		}

		// Show quoye info.
		jQuery(".selected_opinion").html(jQuery(".opinions .opinion").eq(current_quote_tab).html()).fadeIn(700, function(){
		
			// Information height.			
			var info_height = jQuery(".content_information").parent().height();
			jQuery(".content_information .col").each(function(){	
				jQuery(this).height(info_height);
			});					
		
		});	
		
		// Stop carousel when click a tab.
		if(automatic){
			if(jQuery(".opinions .opinion").length > 1){
				cont_quotes = setTimeout("quotes(next_quote_tab, true)",5000);
			}
		} else {
			clearTimeout(cont_quotes);	
		}		
		
	});
	
}

// General DOM Ready.
jQuery(function(){

	// Quotes.
	if(jQuery(".opinions .opinion").length == 1){
		jQuery(".nav_quotes").hide();	
	} else {
		jQuery(".nav_quotes").show();		
	}
	
	// Handler for quotes tabs.
	jQuery(".prev").click(function(){
		quotes(current_quote_tab - 1, false);	
	});	
	jQuery(".next").click(function(){
		quotes(current_quote_tab + 1, false);	
	});
	
});
