/*
 * 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 scrollSpeed = 3000;
	var scrollDelay = 6000;
	var startPosition = 385; //in px
	var slideshowW = 1115; //in px
	
	var pic, numImgs,i, totalWidth, n, myInterval; 
	
	/* LOADING ANIMATION */
	var opts = {
	  lines: 12, // The number of lines to draw
	  length: 7, // The length of each line
	  width: 4, // The line thickness
	  radius: 10, // The radius of the inner circle
	  color: '#fff', // #rbg or #rrggbb
	  speed: 1, // Rounds per second
	  trail: 60, // Afterglow percentage
	  shadow: true // Whether to render a shadow
	};
	var target = document.getElementById('scroller');
	
$(window).load(function(){
	var spinner = new Spinner(opts).spin(target);

	pic = $("#scroller").children("img");
	numImgs = pic.length;
	
	for (i=0;i<numImgs;i++){
		
		totalWidth = startPosition;
		for(n=0;n<i;n++){
			totalWidth -= $(pic[n]).width();
		}
		
		$(pic[i]).css("left",totalWidth);
	}
	
	myInterval = setInterval("flexiScroll()",scrollDelay);
	spinner.stop();
	$(pic).show();	
	
	
	/* NEWS TICKER */
	$('#infobar ul').ticker(
		{
 	       speed: 0.10,           // The speed of the reveal
	        debugMode: true,
	        controls: false,
	        titleText: '',
	        pauseOnItems: 2000
		}
    );
	
});
	
function flexiScroll(){
			$(pic).animate(
				{
					left: '+='+slideshowW
				},
				{
					duration: scrollSpeed,
					easing: 'easeInOutQuad',
					complete: function()
					{
						if ($(this).position().left >= slideshowW){	
							if ($(this).index() == 0)
							{
									$(this).css("left", $(pic).last().position().left - $(this).width());
							}
							else
							{
								$(this).css("left",  $(pic).eq($(this).index()-1).position().left - $(this).width());
							}
						}
					}
				}
				);
}
