$(document).ready(function() {
	
	$("#promo-banners").cycle({
		timeout: 6000,
		speed: 2000,
		slideExpr: "div"
	});
	$("#promo").click(function() {
		window.location.href = $(this).find("a:visible").attr("href");
	});
	
	$(".slideshow").cycle({
		timeout: 1000,
		speed: 1000,
		slideExpr: "div img"
	});
	
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		if(currentArray[currentIndex].name) {
			return '<a href="' + currentArray[currentIndex].name + '">Download High Resolution</a><span>Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</span>';
		} else {
			return '<span>Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</span>';
		}	    
	}
	
	$(".photo-listing a, .shop-image").fancybox({
		autoScale: false,
		overlayColor: "#000000",
		overlayOpacity: "0.7",
		titleShow: true,
		titlePosition: "inside",
		titleFormat: formatTitle
	});
	
	// shop
	$("#product-info .photos").after('<div class="pagination"><a id="prev" href="#">&larr; Previous</a><span id="counter"></span><a id="next" href="#">Next &rarr;</div>').cycle({
		timeout: 0,
		speed: 250,
		prev: "#prev",
		next: "#next",
		after: function(curr, next, opts) {
			$("#counter").html("Image " + (opts.currSlide+1) + " of " + opts.slideCount);
		}
	});
	$("#product-info .photos a").fancybox({
		autoScale: false,
		overlayColor: "#000000",
		overlayOpacity: "0.7"
	});
	
});
