jQuery(document).ready(function(){
	jQuery(".table-first-last").each(function(){
		jQuery(this).find("tr td:first-child").addClass("first");
		jQuery(this).find("tr td:last-child").addClass("last");
	});
	
	/* Give equal heights to the content blurbs */
	var _content_blurb_max_height = 0;
	jQuery(".mod-content-blurbs").find("td.mod-content-blurb-section").each(function(){
		if(jQuery(this).find(".mod-content-blurb").outerHeight() > _content_blurb_max_height){
			_content_blurb_max_height = jQuery(this).find(".mod-content-blurb").outerHeight();
		}
	});
	jQuery(".mod-content-blurbs").find("td.mod-content-blurb-section").each(function(){
		jQuery(this).find(".mod-content-blurb").css({height:_content_blurb_max_height});
	});
	
	jQuery("#back-to-top p a").live("click",function(e){
		e.preventDefault();
					
		jQuery("html, body").animate({
			scrollTop: jQuery("#container").offset().top
		},1000);
	});

	jQuery('#body_home-404 #waist-content .slideshow').nivoSlider({
		controlNav: false,
		directionNav: true,
		effect: 'sliceDown',
		pauseTime: 7000
	});

	jQuery(".click-clear").each(function(){
		jQuery(this).data("placeholder",jQuery(this).val());
		
		jQuery(this).bind({
			focus: function(){
				if(jQuery(this).val() === jQuery(this).data("placeholder")){
					jQuery(this).val("");
				}
			},
			blur: function(){
				if(jQuery(this).val() === ""){
					jQuery(this).val(jQuery(this).data("placeholder"));
				}
			}
		});
	});

	jQuery("table.catalogueTable").each(function(){
		if(jQuery(this).find("td.catalogueItemNotFound").length > 0){
			jQuery(this).remove();
		}
	});
});

function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function stripNonNumeric(str){
	str += '';
	var rgx = /^\d|\.|-$/;
	var out = '';
	for( var i = 0; i < str.length; i++ ) {
		if( rgx.test( str.charAt(i) ) ){
			if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) || ( str.charAt(i) == '-' && out.length != 0 ) ) ){
				out += str.charAt(i);
			}
		}
	}
	return out;
}

