var i = 1;

$(document).ready(function(){

 function onAfter(curr, next, opts) {
   var index = $(this).parent().children().index(this);
   $('#prev')[index == 0 ? 'hide' : 'show']();
   $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
 }
	
function setFade(index){
   if (!index){index = 1};
 $('#images, #description').cycle({ 

    startingSlide: index -1,
 		 fx:     'fade', 
 		 prev:   '#prev', 
 		 next:   '#next', 
 		 after:   onAfter, 
 		 timeout: 0 
 });
}

// Slide Fx For Menu //
 $(".collapse").hide();
 
 $("#vertical h3").click(function(){
  $(this).next(".collapse").slideToggle(600);
 });
 
 $(".link a").click(function(){
  $(".collapse").slideUp(600);
 });

// Build Out AJAX Links //
$(".collapse-container ul li a, .link a, a.link").each(function(){
var link = $(this).attr("href");
$(this).bind("click",function(){
			$("#content_main").animate({opacity: 0},
				function(){
					$("#content_main").load("" + link + " #content", function() {
						pageChange($("#content").height(), link);
						setFade();
					});
			});
			
function onAfter(curr, next, opts) {
  var index = $(this).parent().children().index(this);
  $('#prev')[index == 0 ? 'hide' : 'show']();
  $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}
		return false;
		});
});

//  Generate Links for Thumbnails on the Fly
 $("#imagethumbs img").each(function (){
//  $(this).attr('alt', ''+i+'');
  $(this).addClass(''+i+'');
  i++;
 });

$("#imagethumbs img").click(function (){
// this is the dom element clicked
//var slide = $(this).attr('alt');
var slide = this.className;
$("#content_main").animate({opacity: 0},
	function(){
		$("#content_main").load("photography.php #content", function() {
			pageChange($("#content").height());
			setFade(slide);
		});
});
return false;
});

// Animations for Changing Pages //

function pageChange(){
$("#content_main").animate( 
{opacity: 1}, 
{duration: "slow"}, 
	function(){
		$("#content_main").fadeIn("slow");
	});		
}

});