$(document).ready(function() 
	{

		$('a.menu-order').click(function() {
			$('.cart-throbber').fadeIn('slow');
		});
		$('a.tr').qtip({
			content: { text: function(api) { return $($(this).attr('rel')); } },
			position: { my: "top center", at: "bottom center" },
			style: { classes: 'ui-tooltip-c2f ui-tooltip-rounded' }
		});
		$('td.icons img').qtip({
			content: { attr: 'alt' },
			position: { my: "left center", at: "right center" },
			style: { classes: 'ui-tooltip-c2f ui-tooltip-rounded' }
		});
		$('input:submit, .button').button();
		if (jQuery().validate) {
			jQuery.validator.addMethod("divisibleBy", function(value, element, params) { 
				return this.optional(element) || value%params == 0;
				//var result = this.optional(element) || value%params == 0;
				//if (!result) {
				//	var goodQty = Math.floor(element.value/params)*params;
				//	element.value = goodQty;
				//}
				//return result;
			}, "Must order in multiples of {0}");
		}
	}
);
$(window).scroll(function() {
    $('.loading').css('top', ($(this).scrollTop()+50) + "px");
});

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function alignButtonToTableColumn(buttonSelector,tableSelector,columnNumber,extraOffset) {
	// aligns a button below a table with a desired column... like a button below QTY inputs, for example
	// buttonSelector and tableSelector are jQuery selector strings, columnNumber is an integer
	// use extraOffset to finetine adjust the position (as table might have margin, centered, etc). Can be a positive or negative integer (pixels)
	if (extraOffset == null){ // keep this from being a non-number if param not passed
		extraOffset = 0;
	}
	var buttonWidth = $(buttonSelector).outerWidth(false);
	var cells = $(tableSelector + " tr:first").children();
	var tableColumnCount = cells.length;
	var alignPoint = 0;
	cells.each(function(index) {
		if (index + 1 == columnNumber) {
			alignPoint = alignPoint + Math.round($(this).outerWidth(false) / 2);
		}
		if (index + 1 > columnNumber) {
			alignPoint = alignPoint + $(this).outerWidth(false);
		}
	});
	$(buttonSelector).css('margin-right', (alignPoint - Math.round(buttonWidth / 2) + extraOffset));
}
