

$(function() {
	
	//Set the opacity of all images to 0
	$('#slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#slideshow li:first').css({opacity: 1.0});
	

	
	$("#slideshow li:first").addClass('show');
	//INTIALIZE DOTS
	var t = $("#slideshow li:first").attr("id");

	var tArr = t.split("-");
	t=tArr[1];
	
	$("#dot-" + t).addClass('flash-dot-on');
	$("#dot-" + t).removeClass('flash-dot-off');		   
	
	var speedFlash = 8000;
	var timerFlash = setInterval('movePanel()', speedFlash);
	
	

	//  ADD MOUSEOVER TO FLASH DOT
	$('#flash-dots span').click(
		function() {
				selectPanel(this.id);
		}
	);
	
	//pause the slideshow on mouse ove
	
	$('#flash-dots').hover(
		function () {
			clearInterval(timerFlash);	
		}, 	
		function () {
			//movePanel();
			timerFlash = setInterval('movePanel()',speedFlash);			
		}
	);
	

	


});




function movePanel() {
	

		
	var current = ($('ul#slideshow li.show') ?  $('ul#slideshow li.show') : $('ul#slideshow li:first'));
	var next = ((current.next().length) ? current.next() : $('ul#slideshow li:first'));
	
	next.addClass('show');
	current.removeClass('show');
	
	changeDots(next, current);
	changeImage(next, current);
		
}

function changeDots(next, current) {
	var t = next.attr("id");
	var tArr = t.split("-");
	t=tArr[1];
	
	$("#dot-" + t).addClass('flash-dot-on');
	$("#dot-" + t).removeClass('flash-dot-off');
	
	var u = current.attr("id");
	var uArr = u.split("-");
	u=uArr[1];
	$("#dot-" + u).addClass('flash-dot-off');
	$("#dot-" + u).removeClass('flash-dot-on');
	
}


function changeImage(next, current) {
	
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 900);
	current.animate({opacity: 0.0}, 900).removeClass('show');	
}

function selectPanel(id) {

	var t = id;
	var tArr = t.split("-");
	t=tArr[1];
	
	var current = ($('ul#slideshow li.show') ?  $('ul#slideshow li.show') : $('ul#slideshow li:first'));
	var next = $('#flash-' + t);	
	
	next.addClass('show');
	current.removeClass('show');
	
	changeDots(next, current);
	changeImage(next, current);
}
