﻿/*
 * 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 flexSpeed = 90;
	var flexSpacing = 10;
	var flexPics, flexArrLeft; 

$(window).load(function(){
	flexPics = $("#homeGallery ul li img");
    var totalWidth;
	flexArrLeft = new Array(flexPics.length);
	
	for (var i=0;i<flexPics.length;i++){
		
		totalWidth=0;
		for(var n=0;n<i;n++){
			totalWidth += $(flexPics[n]).width() + flexSpacing;
		}
		
		flexArrLeft[i] = totalWidth;
		$(flexPics[i]).css("left",totalWidth);
		$(flexPics[i]).css("top",0);
	}
	
	var myInterval = setInterval("flexiScroll()",flexSpeed);
	//$('#imageloader').hide();
	$(flexPics).show();	
});

function flexiScroll(){
    var totalWidth;
	for (var i=0;i<flexPics.length;i++){
		flexArrLeft[i] -= 1;

		if (flexArrLeft[i] == -($(flexPics[i]).width())){	
			totalWidth = 0;	
			for (var n=0;n<flexPics.length;n++){
				if (n!=i){	
					totalWidth += $(flexPics[n]).width() + flexSpacing;
				}			
			}	
			flexArrLeft[i] =  totalWidth + flexSpacing;	
		}					
		$(flexPics[i]).css("left",flexArrLeft[i]);
	}
}