﻿$(document).ready(function() {
    // ----- Artists: View Artworks Slideshow -----
    // Start our cycle
    $('#featslideshow').cycle({
            fx:     'scrollLeft',
            speed:  'slow',
            timeout: 6000,
               nowrap:  0,
        pager:  '#slidenav',
        pause: 0,
	after:   onAfter,

	pagerAnchorBuilder: function(idx, slide) {
		return '<li><a href="#">' + (idx + 1) + '<div class="slideshowthumb"><img src="' + slide.src + '" width="85" height="48" /></div></a></li>';
        	
    	} 
    });


$(".capicon").attr("src", "../images/slide-caption-close.png");
$('.captionholder').animate({width: 293}, {duration: 1000});

$('.captionholder').delay(3000).animate({width:0}, {duration: 1000}).queue(function(next) { $(".capicon").attr("src", "../images/slide-caption-open.png"); next(); $(".capicon").bind("click", function() {
      var src = ($(this).attr("src") === "../images/slide-caption-open.png")
                    ? "../images/slide-caption-close.png" 
                    : "../images/slide-caption-open.png";
      $('.capicon').attr("src", src);
	if (src == "../images/slide-caption-open.png") {
	      $('.captionholder').animate({width: 0}, {duration: 1000});
		$('#slideplaybtn').click();
}
	else {
		$('.captionholder').animate({width: 293}, {duration: 200});
		$('#slidepausebtn').click();
	}
});

 $(this).dequeue(); })


    
    // Pause the cycle
    $('#slidepausebtn').click(function() { 
        $('#featslideshow').cycle('pause');
        $(this).hide();
        $('#slideplaybtn').show();
        return false;
    });
    
    // Resume the cycle
    $('#slideplaybtn').click(function() { 
        $('#featslideshow').cycle('resume');
        $(this).hide();
        $('#slidepausebtn').show();
        return false;
    });
    

 


});//end ready function


function onAfter(curr,next,opts) {
	var scount = (opts.currSlide + 1) + '/' + opts.slideCount;
	$('#scount').html(scount);

        $('.caption').html(this.alt);

//	if ($('.capicon').attr("src") == "../images/slide-caption-close.png") {
//	      $('.captionholder').width(0);
//		$('.capicon').attr("src", "../images/slide-caption-open.png");
//	}

}
