
jQuery.fn.linkAllContents = function() {
	return this.each(function(){
		jQuery(this)
			.css('cursor', 'pointer')
			.click(function(){ jQuery(this).find('a').eq(0).click(); })
		;
	});
}



if (window.location.search.indexOf('nocufon') < 0)
doCufon();

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

	initIEHacks();
	addBreadCrumb();

	$('body.home ul.featured-product-lines > li, ul.submenu > li').linkAllContents();

//	$('#siteNav .mainMenu > ul').find('li:has(a):has(ul)').children('a').hoverfix();

	function initIEHacks () {
		if ($.browser.msie) {

			$('.global-tools form select')
				.focus(function(){
					$(this)
						.data("origWidth", $(this).css("width"))
						.css("width", "auto");
					})
				.blur(function(){
					$(this).css("width", $(this).data("origWidth"));
				})
			;
			
			if (Number($.browser.version.split('.')[0]) <= 7) {
				$('input.btn').val('');
			}

		}
	}
	
	function addBreadCrumb () {
		$("#siteNav .breadcrumb").appendBreadCrumbList("/", {
			delimAfter: " &raquo; "
			, docRootLabel: "Home"
			, labels: { 'about': 'about us', 'map': 'about us', 'how-to': 'learn', 'store': 'shop', 'recipes': 'make' }
		});
		$("#siteNav .menu ul li").indicateCurrentPage("sel", {
			overrides: {  }
		});
		cufonReplace('#siteNav .mainMenu a', 'CopperplateBold|12px', { }, true);
	}

});



function doCufon () {
	cufonReplace('#siteNav .mainMenu a', 'CopperplateBold|12px', { }, true);
	cufonReplace('body.home h1', 'CopperplateBold|||-2px', { textShadow: '#fff -1.5px 1.5px, #999 -3px 3px' });
	cufonReplace('body.chooser h1, body.about h1, body.search h1', 'RockSalt');
	cufonReplace('body.whats-new h1, body.specials h1', 'RockSalt', { padding: '10px' }, true);
	cufonReplace('body.whats-new h2, body.specials h2', 'CopperplateBold');
	cufonReplace('body:not(.home,.chooser,.about,.search,.product,.whats-new,.specials) h1', 'CopperplateBold');
	cufonReplace('body.home .section.welcome h2', 'CopperplateBold|||-2px');
	cufonReplace('body.home .section:not(.welcome) h2', 'RockSalt', { padding: '10px' }, true);
	cufonReplace('body.productline .illus .caption', 'RockSalt');
	cufonReplace('.productline h1, .adjacentNav h2 a', 'CopperplateBold|||', { textShadow: '#322b4c -3px 3px, #88632d -4px 4px, #b17f1b -5px 5px' });
	cufonReplace('.related h2', 'CopperplateBold');
	cufonReplace('body.recipe .section.recipe h2:first', 'RockSalt', { padding: '10px' }, true);
	cufonReplace('body.chooser .section.intro h2', 'CopperplateBold|||-2px');
	cufonReplace('body.chooser .section.choices h2', 'RockSalt', { padding: '10px' }, true);
	cufonReplace('body.chooser .section li a', 'CopperplateBold');
	cufonReplace('body.about h2', 'CopperplateBold');
	/*
	*/
}

function cufonReplace(sSelector, sFontSpecs, oOtherOpts, bShouldAllowHover) {
	var aFontSpecs = sFontSpecs.split('|');
	var replaceOpts = { fontFamily: aFontSpecs[0] };
	if (aFontSpecs[1] != undefined)		if (aFontSpecs[1].length > 0)	replaceOpts.fontSize = aFontSpecs[1];
	if (aFontSpecs[2] != undefined)		if (aFontSpecs[2].length > 0)	replaceOpts.lineHeight = aFontSpecs[2];
	if (aFontSpecs[3] != undefined)		if (aFontSpecs[3].length > 0)	replaceOpts.letterSpacing = aFontSpecs[3];
	$.extend(replaceOpts, oOtherOpts);
	if (bShouldAllowHover)			replaceOpts.hover = true;
	Cufon.replace(sSelector, replaceOpts);
}

