$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	var totWidth=0;
	var positions = new Array();
	
	$('#slides .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += $(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;
		}
		
	});
	
	$('#slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#banner_menu ul li a').click(function(e,keepScroll){

			/* On a thumbnail click */

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var pos = $(this).parent().prevAll('.menuItem').length;
			
			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
			/* Start the sliding animation */
			
			e.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvl);
	});
	
	$('#banner_menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		
		$('#banner_menu ul li a').eq(current%$('#banner_menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var changeEvery = 5;

	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

	/* End of customizations */
	
	
	
	
	
	var totWidthSide=0;
	var positionsSide = new Array();
	
	$('.lt_slides .lt_slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positionsSide[i]= totWidthSide;
		totWidthSide += $(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;
		}
		
	});
	
	$('.lt_slides').width(totWidthSide);
	lt_total_width = totWidthSide;

	/* Change the cotnainer div's width to the exact width of all the slides combined */
	
	totWidthSide=0;
	$('.lb_slides .lb_slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positionsSide[i]= totWidthSide;
		totWidthSide += $(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;
		}
		
	});
	
	$('.lb_slides').width(totWidthSide);
	lb_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.slt_slides .slt_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.slt_slides').width(totWidthSide);
		slt_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------

	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.slm_slides .slm_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.slm_slides').width(totWidthSide);
		slm_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------

	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.slb_slides .slb_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.slb_slides').width(totWidthSide);
		slb_total_width = totWidthSide;	
	//-------------------------------------------------------------------------------------

	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.mt_slides .mt_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.mt_slides').width(totWidthSide);
		mt_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.mm_slides .mm_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.mm_slides').width(totWidthSide);
		mm_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.mb_slides .mb_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.mb_slides').width(totWidthSide);
		mb_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.mbl_slides .mbl_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.mbl_slides').width(totWidthSide);
		mbl_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.mbr_slides .mbr_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.mbr_slides').width(totWidthSide);
		mbr_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.rt_slides .rt_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.rt_slides').width(totWidthSide);
		rt_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.rm_slides .rm_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.rm_slides').width(totWidthSide);
		rm_total_width = totWidthSide;
	
	//-------------------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------------------
		totWidthSide=0;
		$('.rb_slides .rb_slide').each(function(i){
			
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			
			positionsSide[i]= totWidthSide;
			totWidthSide += $(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;
			}
			
		});
		
		$('.rb_slides').width(totWidthSide);
		rb_total_width = totWidthSide;

	//-------------------------------------------------------------------------------------
			
			/* Start the sliding animation */
	 
	var lt_side_current=0;
	var lb_side_current=0;
	var mt_side_current=0;
	var mm_side_current=0;
	var mb_side_current=0;
	var mbl_side_current=0;
	var mbr_side_current=0;
	var rt_side_current=0;
	var rm_side_current=0;
	var rb_side_current=0;
	var slt_side_current=0;
	var slm_side_current=0;
	var slb_side_current=0;
	
	function autoAdvanceSide()
	{
		
		var lt_slides_no_picture = lt_total_width / 205 - 1;
		if(lt_side_current < lt_slides_no_picture){
			lt_side_current++;
			$('.lt_slides').stop().animate({marginLeft:-(lt_side_current * 205)+'px'},450);
		}
		else {
			lt_side_current = 0;	
			$('.lt_slides').stop().animate({marginLeft:-(0 * 205)+'px'},450);
		}

		var lb_slides_no_picture = lb_total_width / 205 - 1;
		if(lb_side_current < lb_slides_no_picture){
			lb_side_current++;
			$('.lb_slides').stop().animate({marginLeft:-(lb_side_current * 205)+'px'},450);
		}
		else {
			lb_side_current = 0;
			$('.lb_slides').stop().animate({marginLeft:-(0 * 205)+'px'},450);
		}

		var mt_slides_no_picture = mt_total_width / 566 - 1;
		if(mt_side_current < mt_slides_no_picture){
			mt_side_current++;
			$('.mt_slides').stop().animate({marginLeft:-(mt_side_current * 566)+'px'},450);
		}
		else {
			mt_side_current = 0;
			$('.mt_slides').stop().animate({marginLeft:-(0 * 566)+'px'},450);
		}

		var mm_slides_no_picture = mm_total_width / 566 - 1;
		if(mm_side_current < mm_slides_no_picture){
			mm_side_current++;
			$('.mm_slides').stop().animate({marginLeft:-(mm_side_current * 566)+'px'},450);
		}
		else {
			mm_side_current = 0;
			$('.mm_slides').stop().animate({marginLeft:-(0 * 566)+'px'},450);
		}

		var mb_slides_no_picture = mb_total_width / 566 - 1;
		if(mb_side_current < mb_slides_no_picture){
			mb_side_current++;
			$('.mb_slides').stop().animate({marginLeft:-(mb_side_current * 566)+'px'},450);
		}
		else {
			mb_side_current = 0;	
			$('.mb_slides').stop().animate({marginLeft:-(0 * 566)+'px'},450);
		}

		var mbl_slides_no_picture = mbl_total_width / 283 - 1;
		if(mbl_side_current < mbl_slides_no_picture){
			mbl_side_current++;
			$('.mbl_slides').stop().animate({marginLeft:-(mbl_side_current * 283)+'px'},450);
		}
		else {
			mbl_side_current = 0;
			$('.mbl_slides').stop().animate({marginLeft:-(0 * 283)+'px'},450);
		}

		var mbr_slides_no_picture = mbr_total_width / 283 - 1;
		if(mbr_side_current < mbr_slides_no_picture){
			mbr_side_current++;
			$('.mbr_slides').stop().animate({marginLeft:-(mbr_side_current * 283)+'px'},450);
		}
		else {
			mbr_side_current = 0;	
			$('.mbr_slides').stop().animate({marginLeft:-(0 * 283)+'px'},450);
		}

		var rt_slides_no_picture = rt_total_width / 213 - 1;
		if(rt_side_current < rt_slides_no_picture){
			rt_side_current++;
			$('.rt_slides').stop().animate({marginLeft:-(rt_side_current * 213)+'px'},450);
		}
		else {
			rt_side_current = 0;
			$('.rt_slides').stop().animate({marginLeft:-(0 * 213)+'px'},450);
		}

		var rm_slides_no_picture = rm_total_width / 213 - 1;
		if(rm_side_current < rm_slides_no_picture){
			rm_side_current++;
			$('.rm_slides').stop().animate({marginLeft:-(rm_side_current * 213)+'px'},450);
		}
		else {
			rm_side_current = 0;
			$('.rm_slides').stop().animate({marginLeft:-(0 * 213)+'px'},450);
		}

		var rb_slides_no_picture = rb_total_width / 213 - 1;
		if(rb_side_current < rb_slides_no_picture){
			rb_side_current++;
			$('.rb_slides').stop().animate({marginLeft:-(rb_side_current * 213)+'px'},450);
		}
		else {
			rb_side_current = 0;			
			$('.rb_slides').stop().animate({marginLeft:-(0 * 213)+'px'},450);
		}

		var slt_slides_no_picture = slt_total_width / 205 - 1;
		if(slt_side_current < slt_slides_no_picture){
			slt_side_current++;
			$('.slt_slides').stop().animate({marginLeft:-(slt_side_current * 205)+'px'},450);
		}
		else {
			slt_side_current = 0;
			$('.slt_slides').stop().animate({marginLeft:-(0 * 205)+'px'},450);
		}

		var slm_slides_no_picture = slm_total_width / 205 - 1;
		if(slm_side_current < slm_slides_no_picture){
			slm_side_current++;
			$('.slm_slides').stop().animate({marginLeft:-(slm_side_current * 205)+'px'},450);
		}
		else {
			slm_side_current = 0;
			$('.slm_slides').stop().animate({marginLeft:-(0 * 205)+'px'},450);
		}

		var slb_slides_no_picture = slb_total_width / 205 - 1;
		if(slb_side_current < slb_slides_no_picture){
			slb_side_current++;
			$('.slb_slides').stop().animate({marginLeft:-(slb_side_current * 205)+'px'},450);
		}
		else {
			slb_side_current = 0;
			$('.slb_slides').stop().animate({marginLeft:-(0 * 205)+'px'},450);
		}
			
//		if(side_current < 2){
//			side_current++;
//			$('.lt_slides').stop().animate({marginLeft:-(side_current * 205)+'px'},450);
//			$('.lb_slides').stop().animate({marginLeft:-(side_current * 205)+'px'},450);
//			$('.mt_slides').stop().animate({marginLeft:-(side_current * 566)+'px'},450);
//			$('.mm_slides').stop().animate({marginLeft:-(side_current * 566)+'px'},450);
//			$('.mb_slides').stop().animate({marginLeft:-(side_current * 566)+'px'},450);
//			$('.mbl_slides').stop().animate({marginLeft:-(side_current * 283)+'px'},450);
//			$('.mbr_slides').stop().animate({marginLeft:-(side_current * 283)+'px'},450);
//			$('.rt_slides').stop().animate({marginLeft:-(side_current * 213)+'px'},450);
//			$('.rm_slides').stop().animate({marginLeft:-(side_current * 213)+'px'},450);
//			$('.rb_slides').stop().animate({marginLeft:-(side_current * 213)+'px'},450);
//		}
//		else{
//			side_current = -1;
//		}
		
	}

	// The number of seconds that the slider will auto-advance in:
	
	//var changeEvery = 6;

	var itvlSide = setInterval(function(){autoAdvanceSide();},changeEvery*1000);

	/* End of customizations */
});
