// GLOBAL VARIABLES for SLIDESHOW
var currentPos;
currentPos = 0;

$(document).ready(function() {

/* SLIDESHOW FUNCTIONALITY */	
	// set defaults
	$('#slideshowPanels li:first').css({ 'z-index': '5', opacity: '1' }); // sets panel 1 to a higher z-index by default
	$('#slideshowThumbs li a').eq(0).children('img').stop().animate({ top: '-10px' }).css({ border: '1px solid #ffcb00' }); // sets first list item to elevated position + yellow border by default

	// doing cross-browser compatible css setting	
	$('#slideshowThumbs li:first-child').css({ marginLeft: '10px' });
	$('#slideshowThumbs li:last-child').css({ marginRight: '0' });
	
	//Load the slideshow
	theRotator();
	
	// Complex animation! When each thumb is hovered it will animate up 10px, bring up it's companion large panel via z-index and then lower the other thumbnails and lower z-index for other panels
	$('#slideshowThumbs li a').each(function() {  
		$(this).hover(function() {
			var pos = $(this).parent().index();
			currentPos = pos; // store index of current hover
			$(this).children('img').stop().animate({ top: '-10px' }).css({ border: '1px solid #ffcb00' });
			$('#slideshowPanels li').eq(pos).stop().animate({ opacity: '1' }, 500).css({ zIndex: '6' });
			$('#slideshowThumbs li a').not(this).children('img').stop().animate({ top: '0px' }).css({ border: '1px solid #222' });
			$('#slideshowPanels li').not(':eq(' + pos + ')').stop().animate({ opacity: '0' }, 250).css({ zIndex: '2' });
		});
	});
});

function theRotator() {
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()', 8000);	

}

function rotate() {	
	//Get the first image
	var current = ($('#slideshowPanels li.show') ? $('#slideshowPanels li.show') : $('#slideshowPanels li:first'));

	current = $('#slideshowPanels li').eq(currentPos); // reset current to hover
	currentPos = currentPos + 1;
	
	var sspPos = 0;	// variable to store slideshowPanel index	
	if (current.index() >= 4) { sspPos = 0; currentPos=0; } else { sspPos = current.index() + 1; } // if slideshowPanel index is at end, resets index to 0	
	
	//Get next image, when it reaches the end, rotate it back to the first image
	var nextPanel = ( (current.next().length) ? ( (current.next().hasClass('show')) ? $('#slideshowPanels li:first') : current.next() ) : $('#slideshowPanels li:first') );
		
	// matches the slideshowThumbs to the current panel in the slideshow
	$('#slideshowThumbs li a').eq(sspPos).children('img').stop().animate({ top: '-10px' }).css({ border: '1px solid #ffcb00' });
	$('#slideshowThumbs li a').not(':eq(' + sspPos + ')').children('img').stop().animate({ top: '0px' }).css({ border: '1px solid #222' });
	
	//Set the fade in effect for the next image, the show class has higher z-index
	nextPanel.css({ opacity: '0' }).addClass('show').animate({ opacity: '1' }, 500);	

	//Hide the current image
	current.animate({ opacity: '0' }, 400).removeClass('show');
	
};

/* ************************************* 
09082010
************************************* */
var objWindow = null;

function popVideoWin(site) {
		var str;
		str = "";

		if (window.screen) {
			var ah = screen.availHeight - 30;
			var aw = screen.availWidth - 10;

			var xc = (aw - 800) / 2;
			var yc = (ah - 600) / 2;

			str += ",left=" + xc + ",screenX=" + xc;
			str += ",top=" + yc + ",screenY=" + yc;
		}

		objWindow = window.open(site, 'Video', "width=240,height=200,center,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0" + str);

}

