// JavaScript Document
$(document).ready(function() {

// remove empty images from image list
$('#imageList a[href=uploads/]').remove();

// fill the list and pace images into the spots

    // do first image
    var thumb = $('#imageList a:first').html();
	var large = $('#imageList a:first').attr('href');
	$('#imageBrowse1 img').attr('src', thumb);
	$('#imageBrowse1 a').attr('href', large);
	// do second image
    thumb = $('#imageList a:eq(1)').html();
	large = $('#imageList a:eq(1)').attr('href');
	if (thumb){  // make sure image is valid
		$('#imageBrowse2 img').attr('src', thumb);
		$('#imageBrowse2 a').attr('href', large);
	}
	// do third image
    thumb = $('#imageList a:eq(2)').html();
	large = $('#imageList a:eq(2)').attr('href');
	if (thumb){
		$('#imageBrowse3 img').attr('src', thumb);
		$('#imageBrowse3 a').attr('href', large);
	}
	// do fourth image
    thumb = $('#imageList a:eq(3)').html();
	large = $('#imageList a:eq(3)').attr('href');
	if (thumb) {
		$('#imageBrowse4 img').attr('src', thumb);
		$('#imageBrowse4 a').attr('href', large);
	}
	
	
	
$('#galleryBrowser .thumb a').click(function(evt) {  
// add an onclick function to each of the four gallery buttons that
// when clicked replaces the large image with the contents of this links
// image

	evt.preventDefault();

	var imgPath = $(this).attr('href');
	
	if (imgPath != "blank") {
		$('#bigPicture').attr('src', imgPath);
	}
	
	
})


$('#leftBrowsrButton a').click(function(evt) {
// rotate the hidden list of elements (remove top and place at end)
// then copy the first four elements into the thumbnail boxes
// along with their matching large image references
									 
	evt.preventDefault();

	$('#imageList a:last').prependTo('#imageList');  // get last element of list and move to front

// do first image
    var thumb = $('#imageList a:first').html();
	var large = $('#imageList a:first').attr('href');
	$('#imageBrowse1 img').attr('src', thumb);
	$('#imageBrowse1 a').attr('href', large);
	// do second image
    thumb = $('#imageList a:eq(1)').html();
	large = $('#imageList a:eq(1)').attr('href');
	if (thumb){
		$('#imageBrowse2 img').attr('src', thumb);
		$('#imageBrowse2 a').attr('href', large);
	}
	// do third image
    thumb = $('#imageList a:eq(2)').html();
	large = $('#imageList a:eq(2)').attr('href');
	if (thumb){
		$('#imageBrowse3 img').attr('src', thumb);
		$('#imageBrowse3 a').attr('href', large);
	}
	// do fourth image
    thumb = $('#imageList a:eq(3)').html();
	large = $('#imageList a:eq(3)').attr('href');
	if (thumb) {
		$('#imageBrowse4 img').attr('src', thumb);
		$('#imageBrowse4 a').attr('href', large);
	}

})
				 

$('#rightBrowseButton a').click(function(evt) {
									 
	evt.preventDefault();

	$('#imageList a:first').appendTo('#imageList');  // get first element in list and move to back of list
	
	// do first image
    var thumb = $('#imageList a:first').html();
	var large = $('#imageList a:first').attr('href');
	$('#imageBrowse1 img').attr('src', thumb);
	$('#imageBrowse1 a').attr('href', large);
	// do second image
    thumb = $('#imageList a:eq(1)').html();
	large = $('#imageList a:eq(1)').attr('href');
	if (thumb){
		$('#imageBrowse2 img').attr('src', thumb);
		$('#imageBrowse2 a').attr('href', large);
	}
	// do third image
    thumb = $('#imageList a:eq(2)').html();
	large = $('#imageList a:eq(2)').attr('href');
	if (thumb){
		$('#imageBrowse3 img').attr('src', thumb);
		$('#imageBrowse3 a').attr('href', large);
	}
	// do fourth image
    thumb = $('#imageList a:eq(3)').html();
	large = $('#imageList a:eq(3)').attr('href');
	if (thumb) {
		$('#imageBrowse4 img').attr('src', thumb);
		$('#imageBrowse4 a').attr('href', large);
	}
})


});