//  GALLERY (Jquery Cycle plugin)
$(function() {
	//update the URL with the slide number
	var index = 0, hash = window.location.hash;
	if (hash) {
		index = /\d+/.exec(hash)[0];
		index = (parseInt(index) || 1) - 1; // slides are zero-based
	}
	
$('#gallery').cycle({ 
    fx: 'fade', 
    startingSlide: index, 
    speed:  '100', 
    prev:".prev",
    next:".next",    
    timeout: 0, 
    after: onAfter,
    pagerAnchorBuilder: function(idx, slide) { 
    // return selector string for existing anchor 
    return '#gallery-thumbs li:eq(' + idx + ') a'; 
    } 
});
			// put the slide number and total slide count in the #num   
			function onAfter(curr,next,opts) {
				var num = (opts.currSlide + 1) + ' of ' + opts.slideCount;
				$('#num').html(num);
				window.location.hash = opts.currSlide + 1;
			}
});


	// Keyboard control 
	    $(document).keydown(function (k) {
	// NEXT: right arrow key is 39 
		if (k.keyCode == 39 || k.charCode == 39) { 
			$(".next").click();
					return false;
	}
	// PREV: left arrow key is 37
		if (k.keyCode == 37 || k.charCode == 37) { 
			$(".prev").click();
					return false;
	}
});




