$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	/* SERVICIOS */
	
	var serviciostotWidth=0;
	var serviciospositions = new Array();
	
	$('#servicios .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		serviciospositions[i]= serviciostotWidth;
		serviciostotWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#servicios').width(serviciostotWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#serviciosnav ul li a').click(function(e1,keepScroll1){

			/* On a thumbnail click */

			$('#serviciosnav li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var serviciospos = $(this).parent().prevAll('.menuItem').length;
			
			$('#servicios').stop().animate({marginLeft:-serviciospositions[serviciospos]+'px'},450);
			/* Start the sliding animation */
			
			e1.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll1) clearInterval(serviciositvl);
	});
	
	$('#serviciosnav ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var servicioscurrent=1;
	function serviciosautoAdvance()
	{
		if(servicioscurrent==-1) return false;
		
		$('#serviciosnav ul li a').eq(servicioscurrent%$('#serviciosnav ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		servicioscurrent++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var servicioschangeEvery = 6;

	var serviciositvl = setInterval(function(){serviciosautoAdvance()},servicioschangeEvery*1000);

	/* End of customizations */
	
	/* CATALOGO */
	
	var catalogototWidth=0;
	var catalogopositions = new Array();
	
	$('#catalogo .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		catalogopositions[i]= catalogototWidth;
		catalogototWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#catalogo').width(catalogototWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#catalogonav ul li a').click(function(e2,keepScroll2){

			/* On a thumbnail click */

			$('#catalogonav li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var catalogopos = $(this).parent().prevAll('.menuItem').length;
			
			$('#catalogo').stop().animate({marginLeft:-catalogopositions[catalogopos]+'px'},450);
			/* Start the sliding animation */
			
			e2.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll2) clearInterval(catalogoitvl);
	});
	
	$('#catalogonav ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var catalogocurrent=1;
	function catalogoautoAdvance()
	{
		if(catalogocurrent==-1) return false;
		
		$('#catalogonav ul li a').eq(catalogocurrent%$('#catalogonav ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		catalogocurrent++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var catalogochangeEvery = 4;

	var catalogoitvl = setInterval(function(){catalogoautoAdvance()},catalogochangeEvery*1000);

	/* End of customizations */
	
	/* CONSUMIBLES */
	
	var consumiblestotWidth=0;
	var consumiblespositions = new Array();
	
	$('#consumibles .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		consumiblespositions[i]= consumiblestotWidth;
		consumiblestotWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#consumibles').width(consumiblestotWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#consumiblesnav ul li a').click(function(e3,keepScroll3){

			/* On a thumbnail click */

			$('#consumiblesnav li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var consumiblespos = $(this).parent().prevAll('.menuItem').length;
			
			$('#consumibles').stop().animate({marginLeft:-consumiblespositions[consumiblespos]+'px'},450);
			/* Start the sliding animation */
			
			e3.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll3) clearInterval(consumiblesitvl);
	});
	
	$('#consumiblesnav ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var consumiblescurrent=1;
	function consumiblesautoAdvance()
	{
		if(consumiblescurrent==-1) return false;
		
		$('#consumiblesnav ul li a').eq(consumiblescurrent%$('#consumiblesnav ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		consumiblescurrent++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var consumibleschangeEvery = 3;

	var consumiblesitvl = setInterval(function(){consumiblesautoAdvance()},consumibleschangeEvery*1000);

	/* End of customizations */
	
	/* DISEnO */
	
	var disenototWidth=0;
	var disenopositions = new Array();
	
	$('#diseno .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		disenopositions[i]= disenototWidth;
		disenototWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#diseno').width(disenototWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#disenonav ul li a').click(function(e4,keepScroll4){

			/* On a thumbnail click */

			$('#disenonav li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var disenopos = $(this).parent().prevAll('.menuItem').length;
			
			$('#diseno').stop().animate({marginLeft:-disenopositions[disenopos]+'px'},450);
			/* Start the sliding animation */
			
			e4.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll4) clearInterval(disenoitvl);
	});
	
	$('#disenonav ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var disenocurrent=1;
	function disenoautoAdvance()
	{
		if(disenocurrent==-1) return false;
		
		$('#disenonav ul li a').eq(disenocurrent%$('#disenonav ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		disenocurrent++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var disenochangeEvery = 5;

	var disenoitvl = setInterval(function(){disenoautoAdvance()},disenochangeEvery*1000);

	/* End of customizations */
});
