var loginIntervalID = 0;

$(document).ready(function(){
	//###############   Product Menu   ###############
	$('#product-nav li.toggler ul').hide();
	$('#product-nav li.toggler a').click(function() {  
		var $parent = $(this).parent();
		if( $parent.is('.toggler') ) {
			$(this).next().slideToggle("fast");
			if( $parent.is('.closed') ) {
				$parent.removeClass('closed').addClass('open');
			} else {
				$parent.removeClass('open').addClass('closed');
			}
			return false;
		}
	});
			
	//###############   Shopping Basket   ###############
	$('#shopping-basket h3').click(function() {  
		var $parent = $(this).parent();
		$(this).next().slideToggle("fast");
			if( $parent.is('.closed') ) {
				$parent.removeClass('closed');
				$parent.addClass('open');
			} else {
				$parent.removeClass('open');
				$parent.addClass('closed');
			}
		return false;
	});

	//###############   PRETTYPHOTO, Zoom functionality throughout content   ###############
	$("a[rel^='prettyPhoto']:not(#user-nav li a)").prettyPhoto({
		showTitle: false,
		allowresize: true
	});
			
	//###############   Homepage Image slideshow   ###############
	$('#slideshow').cycle({
		timeout:4500,
		speed:650,
		pause:1
	});

	//###############   Payment Process   ###############
	$("#order-process li:not(.active,.arrow)").hoverIntent(function() {
		$(this).find(".rollover").fadeIn("normal");
		$(this).find("p:not(.rollover)").hide();
		$(this).parent().find(".active p:not(.rollover)").show();
		$(this).parent().find(".active .rollover").hide();
	}, function() {
		$(this).find("p:not(.rollover)").fadeIn("normal");
		$(this).find(".rollover").hide();
		$(this).parent().find(".active .rollover").show();
		$(this).parent().find(".active p:not(.rollover)").hide();
	});

	$("#order-process li:not(.active,.arrow,.disabled)").click(function() {
		//$(this).find("a").click(); //###   Results in "too much recusrsion" error?!?
		top.location.href = $(this).find("a").attr("href");
	});

	//###############   Payment Login/Register Toggle   ###############
	$("#checkout #login-toggle").next().hide();
	$("#checkout #register-toggle").next().hide();
	$("#checkout #login-toggle").click(function () {
		$(this).next().fadeIn("normal");
		$("#checkout #register-toggle").next().fadeOut("normal");
	});
	$("#checkout .links a:eq(0)").click(function() {
		$("#checkout #login-toggle").trigger("click");
	});
	$("#checkout #register-toggle").click(function () {
		$(this).next().fadeIn("normal");
		$("#checkout #login-toggle").next().fadeOut("normal");
	});
	$("#checkout .links a:eq(1)").click(function() {
		$("#checkout #register-toggle").trigger("click");
	});

	//###   Quick Checkout is only accessible to JavaScript users at the moment, so hidden by CSS and shown here   ###
//	$("#checkout .links #quick-checkout").show();

	//###############   Payment - Further Information Delivery Address Toggle   ###############

	//###   Code is within it's own JavaScript file user-address-js

	//###############   Quick Checkout Delivery Address Toggle   ###############
	if ( $("#quick-checkout-form #delivery-same-address").attr("checked") ) {
		$("#quick-checkout-form #delivery-address").hide();
	}
	$("#quick-checkout-form #delivery-same-address").change(function() {
		if ( $(this).attr("checked") ) {
			$("#quick-checkout-form #delivery-address").fadeOut("normal");
		} else {
			$("#quick-checkout-form #delivery-address").fadeIn("normal");
		}
	});
			
	//###############   Product list rollover information - setup   ###############
//	$(".booklist .book-info:not(.booklist .no-image .book-info)").hide();	//###   Now done in CSS
//	$(".booklist .price:not(.booklist .no-image .price)").hide();

	isIE = /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
			
	$(".booklist .book-link:not(.booklist .no-image .book-link)").hover(function() {
		if (isIE) {
		} else {
		}
		jQuery("img", jQuery(this)).stop().fadeTo("slow", 0.3);
		jQuery(".book-info", jQuery(this).parent().parent()).stop().fadeTo("slow", 1);
		jQuery(".artist-info", jQuery(this).parent().parent()).stop().fadeTo("slow", 1);
		jQuery(".price", jQuery(this).parent().parent()).stop().fadeTo("slow", 1);

	}, function() {
		jQuery("img", jQuery(this)).stop().fadeTo("slow", 1);
		jQuery(".book-info", jQuery(this).parent().parent()).stop().fadeTo("slow", 0);
		jQuery(".artist-info", jQuery(this).parent().parent()).stop().fadeTo("slow", 0);
		jQuery(".price", jQuery(this).parent().parent()).stop().fadeTo("slow", 0);
	});
}); //###   End of DOM Ready   ###
