$(document).ready(function(){

	/* Product Spec Tabs */
	$(".product-spec-tabs").tabs("> div", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeInSpeed: 1000,
		fadeOutSpeed: 1000,

		// start from the beginning after the last tab
		rotate: true
	
	});	
	
	
	/* Product Thumbs */
	$("div.product-thumbs-scroll").scrollable({	
		items: '.product-thumbs-slide',
		item: '.product-thumb',
		next: '.product-thumbs-next',
		prev: '.product-thumbs-prev',
		size: 3,
		/*clickable: false,*/
		speed: 500
	});
	
	/* Product Image Frame */
	$(".product-thumbs-slide .product-thumb").click(function() {

		// see if same thumb is being clicked
		if ($(this).hasClass("active")) { return false; }

		// calclulate large image's URL based on the thumbnail URL (flickr specific)
		//var url = $(this).attr("src").replace("_t", "");
		var url = $(this).attr("href");

		// get handle to element that wraps the image and make it semi-transparent
		var wrap = $(".product-image-frame").fadeTo("medium", 0.5);

		// the large image from www.flickr.com
		var img = new Image();

		// call this function after it's loaded
		img.onload = function(){

			// make wrapper fully visible
			wrap.fadeTo("fast", 1);

			// change the image
			wrap.find("img").attr("src", url);

		};

		// begin loading the image from www.flickr.com
		img.src = url;

		// activate item
		$(".product-thumbs-slide .product-thumb").removeClass("active");
		$(this).addClass("active");
		
		return false;
		
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();
	

});
