$(document).ready(function() {
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
	$('#play').click(function() { $('#slideshow').cycle('resume'); return false; });
	// $('#slideshow').hover(
	// 	function() { $('#controls').fadeIn(); },
	// 	function() { $('#controls').fadeOut(); }
	// );

	// start slideshow 
	$('#slideshow').cycle({ 
		fx: 'fade',
		speed: 1000,
		timeout: 4000,
		next: '#next,.pics',
		prev: '#prev',
		before: onBefore
	}); // .cycle('pause');

	// hack for photo credits
	var basedir = "images/cycle/"
	var cyclegallery = {
		"1":["redfang6.jpg" , "&copy;Rexroad-Higgins"],
		"2":["redfang2.jpg" , "Stevil Kinevil"],
		"3":["redfang13.jpg" , "Shannon Corr"],
		"4":["redfang16.jpg" , "Justina Villanueva"],
		"5":["redfang5.jpg" , "Stevil Kinevil"],
		"6":["redfang14.jpg" , "Shannon Corr"],
		"7":["redfang17.jpg" , "Jason McQuilliams"],
		"8":["redfang3.jpg" , "Stevil Kinevil"],
		"9":["redfang4.jpg" , "Jason Luchka"],
		"10":["redfang11.jpg" , "Ryan Stowe"],
		"11":["redfang1.jpg","Alicia J. Rose"],
		"12":["redfang7.jpg" , "Whitey McConnaughy"],
		"13":["redfang8.jpg" , "Whitey McConnaughy"],
		"14":["redfang9.jpg" , "Todd Warnock"],
		"15":["redfang10.jpg" , "Chris Coyle"],
		"16":["redfang18.jpg" , "Justina Villanueva"]}
	
	var c=0;
	for (var k in cyclegallery) {
	    if (cyclegallery.hasOwnProperty(k)) {
	       ++c;
	    }
	}
	 
	var totalSlideCount = c;
 	var currentImageNum = $('#slideshow img').size();
	// alert ($('#slideshow img').size());
	function onBefore(curr, next, opts) { 
		// on the first pass, addSlide is undefined (plugin hasn't yet created the fn); 
		// when we're finshed adding slides we'll null it out again 
		if (!opts.addSlide) 
			return; 
			
		// on Before arguments: 
		//  curr == DOM element for the slide that is currently being displayed 
		//  next == DOM element for the slide that is about to be displayed 
		//  opts == slideshow options 

		currentImageNum+=1;
		if (currentImageNum == totalSlideCount+1) {
			// final slide in our slide slideshow is about to be displayed 
			// so there are no more to fetch 
			opts.addSlide = null; 
			return; 
		} 

		// add our next slide
		item = cyclegallery[currentImageNum];
		slide = cyclegallery[currentImageNum][0];
		if (cyclegallery[currentImageNum][1] != null && cyclegallery[currentImageNum][1] != "" ) {
			credits = "photo - "+cyclegallery[currentImageNum][1];
		} else {
			credits = '';
		}
		// alert(slide);
		opts.addSlide('<div><img src="'+basedir+slide+'" />'+credits+'</div>');
	};
}); 

