KrispyKreme = {};
LFD = {};

/**
 * Rounds number to the specified number of decimal places
*/
LFD.roundNumber = function (number, decimal_places){ 
	return (number).toFixed(decimal_places);
}


jQuery(document).ready(function($) {

	// Navigation menu dropdowns
	$j("ul.kk-default").superfish ({
	    hoverClass:    "wpm-hover",        
	    delay:         500,                
	    animation:     {}, 
	    speed:         "slow",         
	    autoArrows:    true,               
	    dropShadows:   false,               
	    disableHI:     true
	});

	// This script determines which page you're on and will append the 'selected' class to the
	// main navigation menu
	jQuery(function() {
		var current_link, current_location, regex;

	    jQuery('.kk-default a').each(function() {
	    	current_location = window.location.pathname;
	    	current_link = jQuery(this).attr('href')
			regex = new RegExp( current_link );

	        if (  jQuery(this).attr('href')  ===  current_location || (regex.test(current_location) && current_link !== '/' && current_link !== '' && typeof current_link != 'undefined'  ) ) {
	         	jQuery(this).parents('li').addClass('selected');
		        if(current_link == '/store/customer/account/create/'){
		        	jQuery('a[href="/store/"]').parents('li').removeClass('selected');	
		        }
	        }
		});
    });
}); 

KrispyKreme.get_param = function(param) {
   var search = window.location.search.substring(1);
   if(search.indexOf('&') > -1) {
      var params = search.split('&');
      for(var i = 0; i < params.length; i++) {
          var key_value = params[i].split('=');
          if(key_value[0] == param) return key_value[1];
      }
   } else {
      var params = search.split('=');
      if(params[0] == param) return params[1];
   }
   return null;
};

