/*
 * jquery.flexislider.js v0.1 - jQuery script
 * Copyright (c) 2009 Barry Roodt (http://calisza.wordpress.com)
 *
 * Licensed under the New BSD license.
 *
 * This script slides a list of images from right to left across the window.
 * An example can be found at http://flexidev.co.za/projects/flexislider
 * Please check http://code.google.com/p/flexidev/downloads/ for the latest version
 *
 */

	var speed = 20;
	var width1 = 136;
	var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 

$(window).load(function(){
	$('#slider').show();
	pic = $("#slider").children(".photo"); /* selector */
	numImgs = pic.length; /* numImgs = number of items called for by the "pic" variable */
	arrLeft = new Array(numImgs); /* creates an array called "arrLeft" which holds the number of images */
	for (i=0;i<numImgs;i++){ /* loop while there are items (selected from line 17) */
		
		totalWidth=0; /* reset total width of the container to 0 */
		for(n=0;n<i;n++){ /* loop while there are items (while "n" is less than "i", which represents the number of selected items */
			totalWidth += width1; /* get total width by looping +137px for as many items are selected (10 items = 1370px) */
		}
		
		arrLeft[i] = totalWidth; /* set arrLeft[i] to equal total width from line 24 */
		$(pic[i]).css("left",totalWidth); /* change the css for the currently selected (indicated by "i") image in the "pic" array to show left:***, where left = total width */
										  /* this allows the images to be aligned to the right of the starting point. img 1 = left:0px; img 2 = left:136px; and so on */
	}
	
	myInterval = setInterval("flexiScroll()",speed); /* make the scrolls happen */
	$('#imageloader').hide(); /* then hide the image loader gif */
	$(pic).show();	/* and show the items */
});

function flexiScroll(){ /* declare the flexiScroll function */

	for (i=0;i<numImgs;i++){ /* for as many items as there are... */
		arrLeft[i] -= 1; /* decrement arrLeft[i] by one - rinse & repeat */		

		if (arrLeft[i] == -width1) {	/* if arrLeft[i] ever gets to -136... */
			totalWidth = 0;	 /* reset totalWidth to 0 */
			for (n=0;n<numImgs;n++){ /* as long as "n" is less than the number of items in the array, loops this */
				if (n!=i){	
					totalWidth += $(pic[n]).width();
				}			
			}	
			arrLeft[i] =  totalWidth;	
		}					
		$(pic[i]).css("left",arrLeft[i]);
	}
}
