// var callbacks = $.Callbacks();
// callbacks.add(fixCaptions);

$(document).ready(function(){

    $(".carousel:not('#clearanceCarousel')").each(function() {
			$(this).jCarouselLite({
				btnNext: $(this).children('img')[1],
				btnPrev: $(this).children('img')[0],
				circular: true,
				visible: 3,
				scroll: 1
			});
    });

    $('#clearanceCarousel').jCarouselLite({
		btnNext: $('#clearanceCarousel').children('img')[1],
		btnPrev: $('#clearanceCarousel').children('img')[0],
		circular: true,
		visible: 3,
		scroll: 1,
		start: 0
    });
	
	// $('.carousel:not("#clearanceCarousel") ul img').jcaption();
	$('.carousel:not("#clearanceCarousel") ul img').jcaption();
	$('#clearanceCarousel ul img').jcaption();


	function fixCaptions() {
		$('.carousel:not("#clearanceCarousel") .caption p').each(function() {
			var text = $(this).text();
			var maker = text.split(": ")[0];
			var style = text.split(": ")[1];
			var newHTML = "<span class=\"captionTitle\">" + maker + "</span><br /><span class=\"captionStyle\">" + style + "</span>";
			$(this).html(newHTML);
		});

		$('#clearanceCarousel .caption p').each(function() {
			var text = $(this).text();
			var splitText = text.split(": ");
			var serial = splitText[0];
			var size = splitText[1];
			var wasPrice = splitText[2];
			var nowPrice = splitText[3];
			var newHTML =
				"<span class=\"clearCaptionSerial\">" + serial +
				"</span><span class=\"clearCaptionSize\">" + size +
				"</span><br /><span class=\"clearCaptionWasPrice\">" + wasPrice +
				"</span><br /><span class=\"clearCaptionNowPrice\">" + nowPrice +
				"</span>";
			$(this).html(newHTML);
		});
	}

	fixCaptions();

	$('a.lightbox').lightBox({
		imageLoading: 'images/loading.gif'
	});


	$('#fbDialog').jqm({
		overlay: 50
	});

	$("#clickhome, .carouselcont .logo3").click(function () {
		$("#collect, #appoint, #pre, #contact, #brides, #maids, #clear").delay( 100 ).fadeOut( 150 , function () {
			$("#home").delay( 160 ).fadeIn( 500 );
		});
	});
	
	$("#clickcollect").click(function () {
		$("#home, #appoint, #pre, #contact").delay( 100 ).fadeOut( 150 );
		$("#brides, #maids, #clear").delay( 100 ).fadeOut( 150 );
		$("#collect").delay( 160 ).fadeIn( 500 , function() {
			$("#clickbrides, #clickmaids, #clickclear").delay( 50 ).fadeIn( 500 );
		});
	});

	$("#clickappoint").click(function () {
		$("#collect, #home, #pre, #contact").delay( 100 ).fadeOut( 150 , function () {
			$("#appoint").delay( 160 ).fadeIn( 500 );
		});
	});


	$("#clickpre").click(function () {
		$("#collect, #appoint, #home, #contact").delay( 100 ).fadeOut( 150 , function () {
			$("#pre").delay( 160 ).fadeIn( 500 );
		});
	});


	$("#clickcontact").click(function () {
		$("#collect, #appoint, #pre, #home").delay( 100 ).fadeOut( 150 , function () {
			$("#contact").delay( 160 ).fadeIn( 500, function() { $('#fbDialog').jqmShow(); } );
		});
	});
	
	$('#collect, #brides, #maids, #clear').hide();
	
	$("#clickbrides").click(function () {
		$("#clickbrides, #clickmaids, #clickclear").delay( 100 ).fadeOut( 150 , function () {
			$("#brides").delay( 160 ).fadeIn( 500 );
		});
	});
	
	$("#clickmaids").click(function () {
		$("#clickbrides, #clickmaids, #clickclear").delay( 100 ).fadeOut( 150 , function () {
			$("#maids").delay( 160 ).fadeIn( 500 );
		});
	});
	
	$("#clickclear").click(function () {
		$("#clickbrides, #clickmaids, #clickclear").delay( 100 ).fadeOut( 150 , function () {
			$("#clear").delay( 160 ).fadeIn( 500 );
		});
	});

	$("#clickback1").click(function () {
		$("#brides").delay( 100 ).fadeOut( 150 , function () {
			$("#clickbrides, #clickmaids, #clickclear").delay( 200 ).fadeIn( 500 );
		});
	});
	
	$("#clickback2").click(function () {
		$("#maids").delay( 100 ).fadeOut( 150 , function () {
			$("#clickbrides, #clickmaids, #clickclear").delay( 200 ).fadeIn( 500 );
		});
	});
	
	$("#clickback3").click(function () {
		$("#clear").delay( 100 ).fadeOut( 150 , function () {
			$("#clickbrides, #clickmaids, #clickclear").delay( 200 ).fadeIn( 500 );
		});
	});

	
});


