// Function to preload images
$.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		$("<img>").attr("src", arguments[i]);
	}
}
$.preloadImages("/interface/images_ext/lifestyle/main-loading.gif","/interface/images_ext/lifestyle/detail-loading.gif","/interface/images_ext/lifestyle/overlay-bkg.gif","/interface/images_ext/lifestyle/detail-balloon.png","/interface/jquery/SNB-Outfits/main-bkg.png");
$(document).ready(function(){
	// Simple wrapper enabling setTimout within chained functions.
	$.fn.wait = function(time, type) {
			time = time || 1000;
			type = type || "fx";
			return this.queue(type, function() {
					var self = this;
					setTimeout(function() {
							$(self).dequeue();
					}, time);
			});
	};
	
	$('#thc').jcarousel({
		scroll: 1,
		wrap: null,
		itemVisibleInCallback: {
				onBeforeAnimation: function(carousel, item, idx, state) {
															if (state == 'init')// No animation on first load of the carousel
																return;
															$('img',item).hide().fadeIn('slow');
														}
		},
		itemVisibleOutCallback: {
				onBeforeAnimation: function(carousel, item, idx, state) {
															$('img',item).fadeOut('slow');
														}
		}
	});

	// Hide page content elements
	$('noscript').hide();
	$('#dtLoading').hide();
	$('#dtContent').hide();
	$('#dt').hide();
	$('#im').hide();
	$('.top').hide();
	$('.bottom').hide();

	// Animate loading of page
//	$('#mainImg').load(function(){ Waiting for image load causing problems, disabling this line
		$('#im').wait('1501').fadeIn("normal");
		$('.top').wait('2000').fadeIn("slow");
		$('.bottom').wait('2500').fadeIn("slow");
		$('#th').wait('3000').slideDown("slow");
//	});

	// Display product detail balloon on imagemap or product link mouseover
/*
	$('#outfitmap area, .pl a').hover(
		function(){
			// Show product detail balloon
			$('#dtContent').hide();
			$('#dt').show();

			// Position product detail balloon near mouse pointer
			$().mousemove(function(e){
				$('#dt').css("left",e.pageX + 5 +'px');
				$('#dt').css("top",e.pageY - 269 +'px');
			});

			// Retrieve product details via ajax
			$.ajax({
							method: "get",url: "/product-miniview.html",data: "sku="+$(this).attr('href'),
					beforeSend: function(){
												$('#dtLoading').show();
											}, //show loading when balloon displays
						complete: function(){
												$("#dtLoading").wait().fadeOut("fast");
											}, //stop showing loading and show content when the process is complete
						 success: function(html){ //so, if data is retrieved, store it in html
					$('#dtContent').html(html).wait('1510').fadeIn("fast"); //show the html inside #dtContent div
				}
			}); //close $.ajax(
		},
		function(){
			$('#dt').hide();
		} // Hide balloon when mouse leaves trigger area
	); // end area.hover
*/

}); // end document.ready
