$(document).ready(function() {
	
	$('body').removeClass("no-js");
	
	$('#language_nav .english a').click(function(e){
		e.preventDefault();
		clickTracking("Language", "SelectLanguage", "English", this.href);
	});
	$('#language_nav .espanol a').click(function(e){
		e.preventDefault();
		clickTracking("Language", "SelectLanguage", "Espanol", this.href);
	});
	
	$('#cheh_footer a').click(function(e){
		e.preventDefault();
		clickTracking("Footer", "OutboundLink", "ChildHungerEndsHere", this.href);
	});
	
	$('#cag_footer a').click(function(e){
		e.preventDefault();
		clickTracking("Footer", "OutboundLink", "ConAgraFoods", this.href);
	});
	
	$('#fb_footer a').click(function(e){
		e.preventDefault();
		clickTracking("Footer", "OutboundLink", "ChefFacebook", this.href);
	});
	
	$('#rse_footer a').click(function(e){
		e.preventDefault();
		clickTracking("Footer", "OutboundLink", "ReadySetEat", this.href);
	});
	
	$('.charity .bottom a').click(function(e){
		e.preventDefault();
		clickTracking("Charitable Giving Page", "OutboundLink", "ChildHungerEndsHere", this.href);
	});
	
	$('.fb-link a').click(function(e){
		e.preventDefault();
		clickTracking("Promotions Page", "OutboundLink", "Contest_Phase 1_Enter Contest", this.href);
	});
	
	/* View Nutrition Information link clicked */
	$('a.nutrition-links').click(function(e){
		e.preventDefault();
		var classList = $(this).attr('class').split(/\s+/);
		var clickClass = classList[1];
		var clickClassList = clickClass.split("_");
		var upc = clickClassList[1];
		
		var showEspanol = false;
		
		if (clickClassList[2] != null && clickClassList[2] == "spanish")
			showEspanol = true;

		if (showEspanol)
		 	displayLabelByUPC(upc, this, 'spanish');
		else
			displayLabelByUPC(upc, this);
	});

});



function clickTracking(category, action, label, url)
{
	var labelVal = '';
	if (label != null)
		labelVal = label;

	_gaq.push(['_trackEvent', category, action, label]);
	if (url != null && typeof (url) != "undefined" && url != "") {
		if (url.indexOf(document.domain) == -1 || endsWith(url, ".pdf")) {
			window.open(url);
		} else 
			setTimeout("window.location.href='" + url + "'", 500);
	}
}

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
