(function($){

	$.fn.shuffle = function() {
		return this.each(function(){
			var items = $(this).children().clone(true);
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}
	
	$.shuffle = function(arr) {
		for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	}
	
})(jQuery);
						$(".js-image-pod").shuffle();
						var jsPodCurrent = 1;
						var timeout = null;
						var working = false;
						var state = 'started';

						$('.left-pod').fadeTo(0,.3);
						$('.left-pod:first-child').fadeTo(0,1);
						$('.js-image-pod').hide();
						$('#js-image-pod-1').show();
						$('.js-image-pod img').hide();
						$('.js-image-pod img:first-child').show().addClass('selectedImg');
						setFlavorText($('#js-image-pod-1 img:first-child').attr('alt'));
						buildControls(1);
						play(5000);
						$('#js-pause').click(function(){
							if(state=='started')
							{	stop();
							}else
							{	play(0);								
							}
						});
						$('.left-pod').click(function()
						{	stop();
							clickedNum = $(this).attr('id').charAt(3);
							if(clickedNum != jsPodCurrent)	scrollPodTo(parseInt(clickedNum));
						});
	
						
						function stop()
						{	clearTimeout(timeout);
							$('#js-pause').attr('src','/+cms/templates/home/images/js-pod/play.png');
							state = 'stopped';					
						}
						function play(to)
						{	$('#js-pause').attr('src','/+cms/templates/home/images/js-pod/pause.png');
							timeout = setTimeout('move()',to);
							state = 'started';
						}
						function move()
						{	if(jsPodCurrent >= 5)
							{	scrollPodTo(1);								
							}else
							{	scrollPodTo(jsPodCurrent+1);								
							}
							timeout = setTimeout('move()',5000)
							state='started';
						}
						
						function scrollPodTo(i)
						{	$('#js-image-pod-'+i+' img').hide().removeClass('selectedImg');
							$('#js-image-pod-'+i+' img:first-child').show().addClass('selectedImg');
							$('#js-'+jsPodCurrent).fadeTo(800,.3);	
							newEl = $('#js-'+i);
							$('#js-pause').fadeOut(400,function(){$(this).css('top',newEl.position().top).fadeIn(400)});
							newEl.fadeTo(800,1);
							$('#jsPodHeading').text(newEl.attr(('alt')));
							$('#js-image-pod-'+jsPodCurrent).fadeOut(800);
							$('#js-image-pod-'+i).fadeIn(800);
							setFlavorText($('#js-image-pod-'+i+' img:first-child').attr('alt'),400);
							buildControls(i);
							jsPodCurrent =  i;							
						}
						function setFlavorText(msg,timeout)
						{ 	parts = msg.split('|');
							if(parts.length > 1)
							{	msg = '<a href="'+parts[1]+'">'+parts[0]+'</a>';
							}else
							{	msg = parts[0];								
							}
							if(timeout == undefined)
							{	
								$('#js-flavor-text').html(msg);
							}else
							{	setTimeout(function(){$('#js-flavor-text').html(msg);},timeout);							
							}						
						}
						function buildControls(podNo)
						{	imageCount = $('#js-image-pod-'+podNo+' img').length;
							$('#js-controls').html('');	
							for(var i = 1;i <= imageCount;i++)
							{	button = $('<div class="js-button" id=></div>').css('backgroundPosition','-'+((i-1)*32)+'px 0').data('img',i);
								if(i == 1)
								{	button.css('backgroundImage','url(\'/+cms/templates/home/images/js-pod/image-controls-over.png\')');							
								}
								button.click(function(){
									if(!working)
									{	stop();
										gotoImage($(this).data('img'));
									}
								});
								$('#js-controls').append(button);
							}				
						}
						function gotoImage(imageNo)
						{	if(!$($('#js-image-pod-'+jsPodCurrent+' img')[imageNo - 1]).hasClass('selectedImg'))
							{	working = true;
								$('#js-image-pod-'+jsPodCurrent+' img.selectedImg').fadeOut(400).removeClass('selectedImg');
								newPod = $($('#js-image-pod-'+jsPodCurrent+' img')[imageNo - 1]);
								newPod.fadeIn(400,function(){working=false}).addClass('selectedImg');
								setFlavorText(newPod.attr('alt'),200);
								$('#js-controls div').css('backgroundImage','url(\'/+cms/templates/home/images/js-pod/image-controls.png\')');
								$($('#js-controls div')[imageNo - 1]).css('backgroundImage','url(\'/+cms/templates/home/images/js-pod/image-controls-over.png\')');
							}
														
						}
