/* move USPS shipping method to number 3 on the list */
/*
jQuery(document).ready(function (){
	jQuery('dl.sp-methods li:eq(0)').insertAfter(jQuery('dl.sp-methods li:eq(2)'));
});
*/
/* fancy box for the gallery and FAQ */

jQuery(document).ready(function(){
		jQuery(".fancybox").fancybox({
			'width': 800,
			'height': 620,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe'
		});
});

jQuery(document).ready(function(){
	
	
jQuery(".accordion dd").css ({
	"display": "none"
	});

jQuery(".accordion dt").css ("border-bottom" , "1px solid #b2aa7e");

jQuery(".accordion dt").hover (
	function () {                                                                      
		jQuery(this).addClass("hover");
		document.body.style.cursor="pointer";
	},
	function () {
		jQuery(this).removeClass("hover");
		document.body.style.cursor="auto";
	});

jQuery(".accordion dt").click (function () {
	jQuery(".accordion dd").slideUp("fast");
	jQuery(".accordion dt").removeClass("active");
	jQuery(".accordion dt").css ("border-bottom" , "1px solid #b2aa7e");
	
	if (jQuery(this).next().is(":hidden")) {
		jQuery(this).css ("border-bottom" , "0px solid #b2aa7e");	
		jQuery(this).addClass("active").siblings("dt").removeClass("active");
		jQuery(this).next().slideDown("fast");
	} else {
		jQuery(this).next().slideUp("fast");
		jQuery(this).removeClass("active");
		jQuery(this).css ("border-bottom" , "1px solid #b2aa7e");	
		}
	});
});






/* Scripts for flavors */

/*


String.prototype.startsWith = function(str){
    return (this.indexOf(str) === 0);
}

function setLimitSelection(){
    var strSize = jQuery("#attribute130 option:selected").text();
    jQuery('.super-attribute-select select').attr('disabled', (strSize == 'Choose an Option...' ? 'disabled' : ''));
    var FlavorLimit = 4;
    
    if (strSize.startsWith('1 lb'))
        FlavorLimit = 4;
    else if (strSize.startsWith('2 lbs'))
        FlavorLimit = 8;
        
    jQuery('.options-Flavors input').unbind('click.limitSelection');
	jQuery('.options-Flavors input').limitSelection(
			{
				// number of items to limit to
				limit: FlavorLimit,
				// on error, do this
				onfailure: function (n){
					jQuery("#flavor-error").html(
						"* Please choose up to " + n + " of your favorite flavors."
					);
					return false;
				},
				// on success, do this
				onsuccess: function (n){
					$("#flavor-error").html("");
					return false;
				}
			}
		);
		var optFlavor = jQuery('.options-Flavors input');
   		optFlavor.setValue(optFlavor.getValue().split(',').slice(0, FlavorLimit));
    
}
jQuery(document).ready(function (){
	jQuery(".options-Flavors > dt").before('<div id="flavor-message" style="color: #f00;">Limit four(4) flavors per pound.</div>');
    jQuery(".options-Flavors").after('<div id="flavor-error" style="color: #f00;"></div>');
    jQuery("#attribute130").change(function(){setLimitSelection()});
    setLimitSelection();
});

jQuery(document).ready(function(){
  jQuery(".options-Flavors").css ("display" , "none");
  jQuery("#attribute141").change(function (){
     if (jQuery("#attribute141 option:selected").text().startsWith("Pick Your Own")){
        jQuery(".options-Flavors").slideDown("fast");
        //jQuery(".options-Flavors ul li input").addClass("validate-one-required-by-name");
     } else {
        jQuery(".options-Flavors").slideUp("fast");
     }
  });
});
*/

String.prototype.startsWith = function(str){
    return (this.indexOf(str) === 0);
}

function setLimitSelection(){
	jQuery("#flavor-error").html("");
    var strSize = jQuery("#attribute130 option:selected").text();
    jQuery('.super-attribute-select select').attr('disabled', (strSize == 'Choose an Option...' ? 'disabled' : ''));
    var FlavorLimit = 20;
    
    if (strSize.startsWith('1 lb'))
        FlavorLimit = 4;
    else if (strSize.startsWith('2 lbs'))
        FlavorLimit = 8;
    else if (strSize.startsWith('3 lbs'))
        FlavorLimit = 12;
	else if (strSize.startsWith('5 lbs'))
        FlavorLimit = 20;
        
    jQuery('.options-Flavors input').unbind('click.limitSelection');
	jQuery('.options-Flavors input').limitSelection(
			{
				// number of items to limit to
				limit: FlavorLimit,
				// on error, do this
				onfailure: function (n){
					jQuery("#flavor-error").html(
						"* Please choose up to " + n + " of your favorite flavors."
					);
					return false;
				},
				// on success, do this
				onsuccess: function (n){
					jQuery("#flavor-error").html("");
					return false;
				}
			}
		);
		var optFlavor = jQuery('.options-Flavors input');
   		optFlavor.setValue(optFlavor.getValue().split(',').slice(0, FlavorLimit));
    
}
jQuery(document).ready(function (){
	jQuery(".options-Flavors > dt").before('<div id="flavor-message" style="color: #f00;">Limit four(4) flavors per pound.</div>');
    jQuery(".options-Flavors").after('<div id="flavor-error" style="color: #f00;"></div>');
    jQuery("#attribute130").change(function(){setLimitSelection()});
    setLimitSelection();
});

jQuery(document).ready(function(){
  jQuery(".options-Flavors").css ("display" , "none");
  jQuery("#attribute141").change(function (){
     if (jQuery("#attribute141 option:selected").text().startsWith("Pick Your Own")){
        jQuery(".options-Flavors").slideDown("fast");
        //jQuery(".options-Flavors ul li input").addClass("validate-one-required-by-name");
     } else {
        jQuery(".options-Flavors").slideUp("fast");
     }
  });
});





jQuery(document).ready(function(){
       if (typeof(productAddToCartForm) != 'undefined'){
               window.originalProductSubmit = productAddToCartForm.submit;
               productAddToCartForm.submit = function(form){
               if (jQuery("#attribute141 option:selected").text() == 'Pick Your Own' &&
                       jQuery(".options-Flavors input:checked").length < 1){
                       alert('Please select at least one flavor!');
                       return false;
               }
                       window.originalProductSubmit(form);
               }
       }
});
 



/* six satchels */
jQuery(document).ready(
	
	
	function setLimitSelection(){
		jQuery(".options-Satchel").after('<div id="flavor-error" style="color: #f00;"></div>');
		jQuery('.options-Satchel input').limitSelection(
			{
				// number of items to limit to
				limit: 6,
				// on error, do this
				onfailure: function (n){
					jQuery("#flavor-error").html(
						"You can not select more than " + n + " satchels."
					);
					return false;
				},
				// on success, do this
				onsuccess: function (n){
					jQuery("#flavor-error").html("");
					return false;
				}
			}
		);

	}
	
);


/* Add a message to the account */

jQuery(document).ready(function (){
	jQuery(".customer-account-index .main .welcome-msg").before('<div id="order-message">Please know, all orders placed before 9/23/2011 will be re-calculated using our current prices. There are no additional charges to past orders or your account. Thanks for understanding. We hope you enjoy our new site.</div>');
	
	/* add message to Cart page */
	jQuery(".checkout-cart-index .page-title").after('<div id="checkout-message">Please note: You will be able to assign product shipping addresses during the next step of the checkout process.</div>');
	/* add message to shipping page */
	/*jQuery(".checkout-multishipping-addresses .page-title").after('<div id="checkout-message">You have the option to ship products to separate addresses. Please select shipping address for applicable items. Please click on Enter a New Address to add recipients. You can edit existing addresses during the next step.</div>');*/
	/* add message to Login Page */
	jQuery(".customer-account-login .page-title").after('<div id="checkout-message">Register with JamesCandy.com to receive special savings and simplify the shopping process. If you’re already registered with our site, be sure to sign up for special offers.</div>');  
	/* add "Remove" to the "Ship to Multiple Addresses" page */
	jQuery('tr.first th:last').html('Remove');
});



/* Add Category descriptions */

jQuery(document).ready(function (){
	jQuery(".category-salt-water-taffy .page-title").after('<p class="category-desc">Enoch James and Joseph Fralinger are the most famous names in Salt Water Taffy. We proudly continue their traditions and carry all their creations, from “cut-to-fit-the-mouth” and “long-shape” to Chocolate Sealed and Filled Center taffy. </p>');
	jQuery(".category-macaroons .page-title").after('<p class="category-desc">The Macaroons made by James Candy Company follow the traditional recipes of Enoch James and Joseph Fralinger. From Almond through Coconut, mouthfuls to minis, you’ll find them all here. </p>');
	jQuery(".category-fudge .page-title").after('<p class="category-desc">Fun, flavorful fudge as only Enoch James and Joseph Fralinger would make it. Boardwalk and Sea Foam Fudge available in traditional flavors and exciting new ones, too. </p>');
	jQuery(".category-mints .page-title").after('<p class="category-desc">Sweet, flavorful and refreshing. Find Fralinger’s Creamy Mint Sticks, James’ Cream and Butter Mint Rolls, and great gift ideas that bring all our treats together. </p>');
	jQuery(".category-chocolates .page-title").after('<p class="category-desc">Many believe that Bayard’s Chocolates are among the best in the world. And after you try Bayard’s Almond Butter Crunch, Chocolate Covered Pretzels, and innovative chocolate confections, we’re sure you’ll agree. </p>');
	jQuery(".category-chews-centers-toffee .page-title").after('<p class="category-desc">Fun, flavorful candies filled with surprises. That’s what you’ll find here. Try Fralinger’s Peanut Butter Chews, Filled Centers, Signature Caramellows, and more. </p>');	
	jQuery(".category-sugar-free-candy .page-title").after('<p class="category-desc">Everyone should enjoy the sweet side of life. James Candy Company offers an array of sugar-free confections. From James’ and Fralinger’s Salt Water Taffy to flavorful fudge, you’ll find it all here. </p>');
	jQuery(".category-nuts .page-title").after('<p class="category-desc">Almond Butter Crunch, Peanut Brittle, and Fralinger’s Famous Peanut Butter Chews — get them all here.</p>');
	jQuery(".category-keepsake-tins-souvenirs .page-title").after('<p class="category-desc">Enoch James and Joseph Fralinger not only took pride in their products, but also their packaging. Enjoy their classic confections arriving inside keepsake tins and souvenirs.  </p>');	
	jQuery(".category-gift-baskets-boxes .page-title").after('<p class="category-desc">Whether it’s birthdays, anniversaries, weddings, or simply because, there’s no better gift to give (or receive) than James’, Fralinger’s, or Bayard’s. Gift Baskets and Boxes are available in traditional or sugar-free assortments. </p>');
	jQuery(".category-gift-towers .page-title").after('<p class="category-desc">James’ Candy Company Gift Towers bring together all your favorite confections. Enjoy Chocolate Gift Towers, Seashore and Summer Favorites, and much, much, more. </p>');		
	jQuery(".category-corporate-gifts .page-title").after('<p class="category-desc">Show your clients how much you care and recognize the employees who go above and beyond with our Corporate Gift Baskets. From the simple to the extraordinary, we have them all. </p>');
});


/* change language for Delivery date module */

jQuery(document).ready(function (){
	jQuery("#checkout-shipping-method-load").after('<p style="margin-top: 10px;">Orders take 2-3 days to process for shipment.  Orders placed after 1 pm ET are processed the following day, please take this into account when choosing expedited shipping methods. Orders are shipped in-full and may be held to manufacture out-of-stock items.  Allow extra time for orders during our holiday season, November 15-December 31.</p><p>Orders being shipped to PO Boxes need to be sent by USPS Priority Mail.</p>');
	jQuery(".multiple-checkout .gift-messages").after('<p style="margin-top: 10px;">Orders take 2-3 days to process for shipment.  Orders placed after 1 pm ET are processed the following day, please take this into account when choosing expedited shipping methods. Orders are shipped in-full and may be held to manufacture out-of-stock items.  Allow extra time for orders during our holiday season, November 15-December 31.</p><p>Orders being shipped to PO Boxes need to be sent by USPS Priority Mail.</p>');
	jQuery(".multiple-checkout #shipping_method_form .input-box").before('<h3>Shipping Date</h3>');
});

jQuery(document).ready(function (){
	jQuery('.sort-by option:first').html('Default');
});



jQuery(document).ready(function (){
	/*jQuery("#discount-coupon-form label").after('<div id="current-code"><p>Save 10% on all orders <span>21WE1110</span><br>Save 15% on orders over $50 <span>21WE1115</span><br />Save 20% on orders over $75 <span>21WE1120</span><p></div>');*/
});




/* Pop up window */

jQuery(document).ready(function() {	

		var id = '#dialog';
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		jQuery('#mask').fadeIn(100);	
		jQuery('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/1);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(100); 	
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		jQuery('#mask').hide();
		jQuery('.window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});		
	
});
