<!--
// The script for the pass it on slide viewer works in multiples of 4, 16 slides, 20 slides, etc.
// SET THE PASS IT ON MONTH THUMBNAIL THAT IS DISPLAYED ON PAGE LOAD.
// 1 = Sep. 09, 2 = Oct, 09, 3 = Nov. 09, etc.
var initializeTheMonth = 13;
//	=====================================
//	DON'T CHANGE ANYTHING BELOW THIS LINE
//	=====================================



// ==============================
// SET VARIABLES
// ==============================

// ==============================
// RUN ALL ONLOAD JQUERY COMMANDS
// ==============================
$(document).ready(function() {
	if (jQuery.browser.msie && (jQuery.browser.version == '6.0' || jQuery.browser.version == '7.0')) {
		$('#mainNav > ul > li').mouseover(function() {
			$(this).addClass('ieon');								  
		});
		$('#mainNav > ul > li').mouseout(function() {
			$(this).removeClass('ieon');						  
		});
	}
	// Set some vars
	var numberOfThumbnails = $('div#slider ul li');
	//alert(numberOfThumbnails.length);
	var scrollDistance = 644;
	var animationRunning = false;
	var minScrollDistance = 0;
	var maxScrollDistance = (161 * 12) * -1;
	if (initializeTheMonth > 15) {
		initializeTheMonth = 15;
	}
	
	$('div#slider').css('left',((initializeTheMonth * 161) - 161) * -1);
	
	// Respond to the right scroll button
	$('img.rightScroll').mouseup(function() {
		// Capture the current left edge position
		var currScrollLeft = $('div#pioThumbs #slider').css('left');
		currScrollLeft = Number(currScrollLeft.substr(0,currScrollLeft.indexOf('p',0)));
		
		// If the movement is not already maxed out and the animation is NOT running
		// Execute the animation
		if (currScrollLeft > maxScrollDistance && !animationRunning) {
			animationRunning = true;
			var newScrollLeft = currScrollLeft - scrollDistance;
			// Prevent the thumbnails from scrolling too far.
			// If we're at the max, over right the calulated scroll postion with the hardcoded max
			if (newScrollLeft < maxScrollDistance) {
				newScrollLeft = maxScrollDistance + 'px';
			} else {
				newScrollLeft = newScrollLeft + 'px';
			}			
			$('div#pioThumbs #slider').animate({left:newScrollLeft}, 1000, '', function(){animationRunning = false;});
		}
	});
	
	// Respond to the left scroll button
	$('img.leftScroll').mouseup(function() {
		// Capture the current left edge position
		var currScrollLeft = $('div#pioThumbs #slider').css('left');
		currScrollLeft = Number(currScrollLeft.substr(0,currScrollLeft.indexOf('p',0)));
			
		// If the movement is not already maxed out and the animation is NOT running
		// Execute the animation
		if (currScrollLeft < 0 && !animationRunning) {
			animationRunning = true;
			var newScrollLeft = currScrollLeft + scrollDistance;
			// Prevent the thumbnails from scrolling too far.
			// If we're at the minumum, over right the calulated scroll postion with the miniumm, 0px
			if (newScrollLeft > 0) {
				newScrollLeft = 0 + 'px';
			} else {
				newScrollLeft = newScrollLeft + 'px';
			}
			
			$('div#pioThumbs #slider').animate({left:newScrollLeft}, 1000, '', function(){animationRunning = false;});
		}
	});
	
	// Turn off and on the slides
	$('#pioThumbs #slider ul li img').mouseup(function() {
		var target = 'div#pioSlide div.s' + $(this).attr('title');
		// First turn off all slides
		for (i=1; i<=16; i++) {
			$('div#pioSlide div.s' + i).hide();
		}
		// Then turn on the selected slide
		$(target).show();
	});
	
	// IE6 and 7 Right Border Fix
	$('#mainNav > ul > li:eq(4)').css('width','141px'); 
	
	
	/*	====================
		RANDOM RESULTS BOXES
		====================*/
	/*	$('#results table.results').hide();
		$('#results table.results:eq(' + (randomRange(1, $('#results table.results').length) - 1) + ')').show();*/
		
	/* ======================
		Begin loading tweets
		=====================*/
	/*
	$(".tweet").tweet({
            loading_text: "loading tweets..."
    });
	*/
});

// Must be positive integers, no zeros.
function randomRange(minNum,maxNum) {
	var randomnumber=Math.floor(Math.random() * (maxNum - 1 + minNum)) + minNum;
	return randomnumber;
}
