
// Replace the slideshow image.
function replace_img () {
	// Get the slide number.
//	n = parseInt($('#slide_number').val());
	// Replace the image.
	$('#slideshow_img').attr('src', img[n][0]);
	$('#slideshow_img').attr('alt', img[n][1]);
	$('#slideshow_img_link').attr('href', img[n][2]);
	// Set the colors for the selected image.
	$('.slideshow_image_button').css('color', non_selected_color);
	$('#slideshow_image_button_' + n).css('color', selected_color);
}

// Function to turn the slide show on and off.
function slideshow () {
	// Find out if the slide show is playing or not.
	control = $('#slideshow_controller_button_img').attr('src');
	if (control == pause_button) {
		on = true;
	}
	else {
		on = false;
	}
	// Set an infinite loop if the slideshow is turn on.
	if (on == true) {
		// If the counter is higher than the number of images than start over otherwise add one to the count.
		if ((n + 1) >= img.length) {
			n = 0;
		}
		else {
			n++;
		}
		// Replace the image.
		replace_img ();
		// Loop the event.
		setTimeout ("slideshow ()", 5000);		
	}
}

// Start once the document is ready.
$(document).ready(function(){
	
	// Start an array of images. img[] = new Array ('src', 'alt', 'href');
	img = new Array();
	img[0] = new Array ('http://www.westhillscollege.com/Images/Common/2009_job_searching_workshop.jpg', '2009 Job Searching Workshop', 'http://westhillscollege.com/documents/2009_job_searching_workshop.pdf');
	img[1] = new Array ('http://www.westhillscollege.com/Images/Common/great_college.jpg', '2009 Great College To Work For', 'http://westhillscollege.com/documents/2009_great_colleges_to_work_for.pdf');
	img[2] = new Array ('http://www.westhillscollege.com/announcements/fin_aid.png', '2009-2010 Financial Aid Forms Now Available!', 'http://www.westhillscollege.com/lemoore/financial_aid/forms.asp');
	img[3] = new Array ('http://www.westhillscollege.com/Images/Common/direct_deposit.jpg', 'Get Your Financial Aid Refund Direct Deposited!!!', 'http://www.westhillscollege.com/documents/eft_notice.pdf');
	img[4] = new Array ('http://www.westhillscollege.com/lemoore/announcements/nursing.jpg', 'Looking for a rewarding and challenging career in Nursing?  If so: click here.', 'http://www.westhillscollege.com/lemoore/academics/health/adnp.asp');
	img[5] = new Array ('http://www.westhillscollege.com/announcements/galleries.jpg', 'Photo Galleries', 'http://www.kodakgallery.com/westhillscollege');
	img[6] = new Array ('http://www.westhillscollege.com/announcements/online_login.jpg', 'Online Login Help', 'http://www.westhillscollege.com/mywesthills/helpdesk.asp');
	img[7] = new Array ('http://www.westhillscollege.com/announcements/online.jpg', 'Is online right for you?', 'http://www.westhillscollege.com/whconline/about/assessment_quiz/technology.asp');

	// Set the play and pause buttons.
	play_button = 'http://www.westhillscollege.com/Images/Common/play_button.jpg';
	pause_button = 'http://www.westhillscollege.com/Images/Common/pause_button.jpg';
	
	// Set the colors for the bullets.
	non_selected_color = '#999999';
	selected_color = '#134B8E';
	
	// Start a counter.
	n = img.length;
	
	// Set the html for the slideshow.
	slideshow_html = '';
	
	// Start by writing an image for the default image above.
	if (img.length > 0) {
		if (img[0].length > 2) {
			slideshow_html += '<a id="slideshow_img_link" href="' + img[0][2] + '"><img id="slideshow_img" src="' + img[0][0] + '" alt="' + img[0][1] + '" /></a><ul id="slideshow_nav">';
		}
		else if (img[0].length = 2) {
			slideshow_html += '<img id="slideshow_img" src="' + img[0][0] + '" alt="' + img[0][1] + '" /><ul id="slideshow_nav">';
		}
		else {
			slideshow_html += '<img id="slideshow_img" src="' + img[0][0] + '" /><ul id="slideshow_nav">';
		}
	}
	
	// Add the pause button.
	if (img.length > 0) {
		slideshow_html += '<li><a id="slideshow_controller_button" href="' + pause_button + '"><img id="slideshow_controller_button_img" src="' + pause_button + '" alt="Press to pause the slideshow." />';
	}
	
	// Add the navigation.
	for (i = 0; i < img.length; i++) {
		slideshow_html += '<li><a id="slideshow_image_button_' + i + '" class="slideshow_image_button" href="' + img[i][0] + '">&bull;</a></li>';
	}
	
	// Finish the html.
	if (img.length > 0) {
		slideshow_html += '</ul>';
	}

	// Write the slideshow information onto the page.
	$('#slideshow').html(slideshow_html);
	
	// Start the slide show.
	slideshow ();

	// If a slideshow button is pushed then go to that image.
	$('.slideshow_image_button').click(function (){
		// Get the image id.
		n = $(this).attr('id');
		n = parseInt(n.substr(23));
		// Replace the image with the selected one.
		replace_img ();
		// Click the toggle once if the image was playing from the slideshow, so users only have to click once to restart it.
		use_toggle = $('#slideshow_controller_button_img').attr('src');
		if (use_toggle == pause_button) {
			$('#slideshow_controller_button').click();
		}
		return false;
	});
	
	// If the pause button is clicked then pause the slideshow and change the button.
	$('#slideshow_controller_button').toggle(
		function (){
			// Change the button to become the play button.
			$('#slideshow_controller_button_img').attr('src', play_button);
			$('#slideshow_controller_button_img').attr('alt', 'Click to play the slideshow');
			$(this).attr('href', play_button);
			return false;
		},
		function () {
			// Change the button to become the pause button.
			$('#slideshow_controller_button_img').attr('src', pause_button);
			$('#slideshow_controller_button_img').attr('alt', 'Click to pause the slideshow');
			$(this).attr('href', pause_button);
			slideshow ();
			return false;
		}
	);
});



