/// <reference path="jquery-1.4.1-vsdoc.js" />

HERSHEYS.Kitchens = {};

HERSHEYS.Kitchens.loginCallback = function(){		
	window.location.href = '/recipes/my-kitchen.aspx';
};


HERSHEYS.Kitchens.initializations = {

    /* KITCHENS HOMEPAGE */
    'latino/kitchens/': function () {

		// Expandable banner on homepage: on click
		

		$("#collapse").hide();
		$("#learn_more").click(function(){
		  $("div#expand_banner").animate({height:'496px'}, 1000, function(){ //callback function to make css run AFTER shrink
			  	$("#collapse").show();
			});
		  $("#learn_more").hide();
		  
		});
		$("#collapse").click(function(){
		  $("div#expand_banner").animate({height:'262px'}, 1000, function(){
			  	$("#learn_more").show();
			});
		  $("#collapse").hide();
		});

	},

    /* HOMEPAGE */
    'recipes': function () {



    },

    /* ETC */

	'recipes/my-kitchen/submit-recipes-and-tips' : function(){
		
        function log(event, data, formatted) {
				$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
		}
		function formatItem(row) {
			return "<img src='/latino/kitchens/Image.ashx?type=submittedphoto&id=" + row[0] + "&s=sm' class='l' style='width: 50px; margin-right: 10px' />"  + "<strong>" + row[1] + "</strong>";
		}
		function formatResult(row) {
			return row[1];
		}
		$(".recipe_name_autocomplete").autocomplete('/latino/kitchens/AjaxServices.ashx?method=recipeautocomplete', {
			width: 289,
			multiple: false,
			matchContains: true,
			formatItem: formatItem,
			formatResult: formatResult
		}).result(function(event, item) {
		  	$('.txtRecipeId').attr('value', item[0]);
		});
		
	},
		
	'recipes/my-kitchen/my-grocery-list' : function(){
		
		$('.asset_list span a').bind('click', function(){
			$(this).parents('li').hide('puff', 1000);
			$(this).hide();
		});
	},
	'recipes/my-kitchen/my-recipe-box' : function(){
		
		$('.recipe_box_wrap a.remove').bind('click', function(){
			$(this).parents('.recipe_box_wrap').hide('puff', 1000);
			$(this).hide();
		});	
	}

};

HERSHEYS.Utility.doPageInits(HERSHEYS.Kitchens.initializations);


HERSHEYS.Kitchens.Analytics = HERSHEYS.Analytics.init({

    devAccount: 'hersheyglobaldev,hersheyintlatinodev',
    liveAccount: 'hersheyglobal,hersheyintlatino',
    tempLinkInternalFilters: 'javascript:,hersheys.com/latino/kitchens/',
    domain: 'Hersheys',
    businessUnit: 'latino',

    appendCampaignCodes: {

        /* EXTERNAL */
        'HG_ID=KHLATLAT001': '.hersheyskitchens-home .tools-nav li:eq(3) a',
        'HG_ID=BAK00010': '.hersheyskitchens-home .main-promo a',
        'HG_ID=BAK00011': '.hersheyskitchens-promotions a#bakesharepromo', /* add in anchor ID to top promo */
        'HG_ID=BAK00012': '.hersheyskitchens-promotions a#cookieexchange', /*add in anchor ID to third promo */

        /* INTERNAL */
        'ICID=KHLAT1369': '.hersheyskitchens-home .logo a',
        'ICID=KHLAT1370': '.hersheyskitchens-home .tools-nav li:eq(0) a',
        'ICID=KHLAT1371': '.hersheyskitchens-home .tools-nav li:eq(1) a',
        'ICID=KHLAT1372': '.hersheyskitchens-home .tools-nav li:eq(2) a',
        'ICID=KHLAT1373': '.hersheyskitchens-home .tools-nav li:eq(3) a',
        'ICID=KHLAT1374': '.hersheyskitchens-home .main-promo a',
        'ICID=KHLAT1375': '.hersheyskitchens-home .search-controls input.submit',
        /* KH1376-KH1425 fire on click */
        'ICID=KHLAT1426': '.hersheyskitchens-home .non_member_msg a',
        'ICID=KHLAT1427': '.hersheyskitchens-home .nav-type li:eq(1) a',
        'ICID=KHLAT1428': '.hersheyskitchens-home .nav-type li:eq(2) a',
        'ICID=KHLAT1429': '.hersheyskitchens-home .nav-type li:eq(3) a',
        'ICID=KHLAT1430': '.hersheyskitchens-home .nav-type li:eq(4) a',
        'ICID=KHLAT1431': '.hersheyskitchens-home .nav-type li:eq(5) a',
        'ICID=KHLAT1432': '.hersheyskitchens-home .nav-type li:eq(6) a',
        'ICID=KHLAT1433': '.hersheyskitchens-home .nav-type li:eq(7) a',
        'ICID=KHLAT1434': '.hersheyskitchens-home .nav-type li:eq(8) a',
        'ICID=KHLAT1435': '.hersheyskitchens-home .nav-type li:eq(9) a',
        'ICID=KHLAT1436': '.hersheyskitchens-home .nav-type li:eq(10) a',
        'ICID=KHLAT1437': '.hersheyskitchens-home .nav-type li:eq(11) a',
        'ICID=KHLAT1438': '.hersheyskitchens-home .nav-type li:eq(13) a',
        'ICID=KHLAT1439': '.hersheyskitchens-home .nav-type li:eq(14) a',
        'ICID=KHLAT1440': '.hersheyskitchens-home .nav-type li:eq(15) a',
        'ICID=KHLAT1441': '.hersheyskitchens-home .nav-type li:eq(16) a',
        'ICID=KHLAT1442': '.hersheyskitchens-home .nav-type li:eq(17) a',
        'ICID=KHLAT1443': '.hersheyskitchens-home .nav-occasion li:eq(0) a',
        'ICID=KHLAT1444': '.hersheyskitchens-home .nav-occasion li:eq(1) a',
        'ICID=KHLAT1445': '.hersheyskitchens-home .nav-occasion li:eq(2) a',
        'ICID=KHLAT1446': '.hersheyskitchens-home .nav-occasion li:eq(3) a',
        'ICID=KHLAT1447': '.hersheyskitchens-home .nav-occasion li:eq(4) a',
        'ICID=KHLAT1448': '.hersheyskitchens-home .nav-occasion li:eq(5) a',
        'ICID=KHLAT1449': '.hersheyskitchens-home .nav-occasion li:eq(6) a',
        'ICID=KHLAT1450': '.hersheyskitchens-home .nav-occasion li:eq(7) a',
        'ICID=KHLAT1451': '.hersheyskitchens-home .nav-occasion li:eq(8) a',
        'ICID=KHLAT1452': '.hersheyskitchens-home .nav-occasion li:eq(9) a',
        'ICID=KHLAT1453': '.hersheyskitchens-home .nav-occasion li:eq(10) a',
        'ICID=KHLAT1454': '.hersheyskitchens-home .nav-occasion li:eq(11) a',
        'ICID=KHLAT1455': '.hersheyskitchens-home .nav-occasion li:eq(12) a',
        'ICID=KHLAT1456': '.hersheyskitchens-home .nav-occasion li:eq(13) a',
        'ICID=KHLAT1457': '.hersheyskitchens-home .nav-occasion li:eq(14) a',
        'ICID=KHLAT1458': '.hersheyskitchens-home .nav-occasion li:eq(15) a',
        'ICID=KHLAT1459': '.hersheyskitchens-home .nav-occasion li:eq(16) a',
        'ICID=KHLAT1460': '.hersheyskitchens-home .nav-product li:eq(1) a',
        'ICID=KHLAT1461': '.hersheyskitchens-home .nav-product li:eq(2) a',
        'ICID=KHLAT1462': '.hersheyskitchens-home .nav-product li:eq(3) a',
        'ICID=KHLAT1463': '.hersheyskitchens-home .nav-product li:eq(4) a',
        'ICID=KHLAT1464': '.hersheyskitchens-home .nav-product li:eq(5) a',
        'ICID=KHLAT1465': '.hersheyskitchens-home .nav-product li:eq(6) a',
        'ICID=KHLAT1466': '.hersheyskitchens-home .nav-product li:eq(7) a',
        'ICID=KHLAT1467': '.hersheyskitchens-home li.leftnav-holiday a',
        'ICID=KHLAT1468': '.hersheyskitchens-home .nav-howto li:eq(0) a',
        'ICID=KHLAT1469': '.hersheyskitchens-home .nav-howto li:eq(1) a',
        'ICID=KHLAT1470': '.hersheyskitchens-home .nav-howto li:eq(2) a',
        'ICID=KHLAT1471': '.hersheyskitchens-home .nav-howto li:eq(3) a',
        'ICID=KHLAT1472': '.hersheyskitchens-home .nav-howto li:eq(4) a',
        'ICID=KHLAT1473': '.hersheyskitchens-home .nav-howto li:eq(5) a',
        'ICID=KHLAT1474': '.hersheyskitchens-home .nav-howto li:eq(6) a',
        'ICID=KHLAT1475': '.hersheyskitchens-home .nav-howto li:eq(7) a',
        'ICID=KHLAT1476': '.hersheyskitchens-home .nav-howto li:eq(8) a',
        'ICID=KHLAT1477': '.hersheyskitchens-home .nav-howto li:eq(9) a',
        'ICID=KHLAT1477': '.hersheyskitchens-home .nav-howto li:eq(10) a',
        'ICID=KHLAT1478': '.hersheyskitchens-home .sign-in a.loginButtonSubmit',
        'ICID=KHLAT1479': '.hersheyskitchens-home p.forgot a',
        'ICID=KHLAT1480': '.hersheyskitchens-home a#signupbutton', /* add anchor ID*/
        'ICID=KHLAT1481': '.hersheyskitchens-home a#familyfun', /* add anchor ID */
        'ICID=KHLAT1482': '.hersheyskitchens-home a#featuredproductname', /* add anchor ID */
        'ICID=KHLAT1483': '.hersheyskitchens-home a#featuredproductrecipes', /*add anchor ID */
        /* KH1484 fires on click */
        'ICID=KHLAT1485': '.hersheyskitchens-home a#joincommunity', /*add anchor ID */
        'ICID=KHLAT1486': '.hersheyskitchens-home a#promotionsforyou',
        'ICID=KHLAT1487': '.hersheyskitchens-home .r li:eq(1) a',
        'ICID=KHLAT1487': '.hersheyskitchens-home .r li:eq(2) a',
        'ICID=KHLAT1488': '.hersheyskitchens-home li.leftnav-myprofile a',
        'ICID=KHLAT1489': '.hersheyskitchens-home li.leftnav-myrecipes a',
        'ICID=KHLAT1490': '.hersheyskitchens-home li.leftnav-mygrocery a',
        'ICID=KHLAT1491': '.hersheyskitchens-home li.leftnav-mylibrary a',
        'ICID=KHLAT1492': '.hersheyskitchens-home li.leftnav-submittips a',
        'ICID=KHLAT1493': '.hersheyskitchens-home li.leftnav-mytips a',
        /* KH1494-KH1498 fire on click */
        'ICID=KHLAT1499': '.hersheyskitchens-promotions a#mykitchen' /*add anchor ID to second promo */
    },

    clickCampaignCodes: {

        /* INTERNAL */
        'KHLAT1376': '.hersheyskitchens-home .view-options li:eq(0) a',
        'KHLAT1377': '.hersheyskitchens-home .view-options li:eq(1) a',
        'KHLAT1378': '.hersheyskitchens-home .view-options li:eq(2) a',
        'KHLAT1379': '.hersheyskitchens-home .viewby-large li:eq(3) a',
        'KHLAT1380': '.hersheyskitchens-home .viewby-large li:eq(4) a',
        'KHLAT1381': '.hersheyskitchens-home .viewby-large li:eq(5) a',
        'KHLAT1382': '.hersheyskitchens-home .viewby-large li:eq(6) a',
        'KHLAT1383': '.hersheyskitchens-home .viewby-large li:eq(7) a',
        'KHLAT1384': '.hersheyskitchens-home .viewby-large li:eq(8) a',
        'KHLAT1385': '.hersheyskitchens-home .viewby-large li:eq(9) a',
        'KHLAT1386': '.hersheyskitchens-home .viewby-large li:eq(10) a',
        'KHLAT1387': '.hersheyskitchens-home .viewby-large li:eq(11) a',
        'KHLAT1388': '.hersheyskitchens-home .viewby-large li:eq(12) a',
        'KHLAT1389': '.hersheyskitchens-home .viewby-large li:eq(13) a',
        'KHLAT1390': '.hersheyskitchens-home .viewby-large li:eq(14) a',
        'KHLAT1391': '.hersheyskitchens-home .viewby-grid li:eq(0) a',
        'KHLAT1392': '.hersheyskitchens-home .viewby-grid li:eq(1) a',
        'KHLAT1393': '.hersheyskitchens-home .viewby-grid li:eq(2) a',
        'KHLAT1394': '.hersheyskitchens-home .viewby-grid li:eq(3) a',
        'KHLAT1395': '.hersheyskitchens-home .viewby-grid li:eq(4) a',
        'KHLAT1396': '.hersheyskitchens-home .viewby-grid li:eq(5) a',
        'KHLAT1397': '.hersheyskitchens-home .viewby-grid li:eq(6) a',
        'KHLAT1398': '.hersheyskitchens-home .viewby-grid li:eq(7) a',
        'KHLAT1399': '.hersheyskitchens-home .viewby-grid li:eq(8) a',
        'KHLAT1400': '.hersheyskitchens-home .viewby-grid li:eq(9) a',
        'KHLAT1401': '.hersheyskitchens-home .viewby-grid li:eq(10) a',
        'KHLAT1402': '.hersheyskitchens-home .viewby-grid li:eq(11) a',
        'KHLAT1403': '.hersheyskitchens-home .viewby-grid li:eq(12) a',
        'KHLAT1404': '.hersheyskitchens-home .viewby-grid li:eq(13) a',
        'KHLAT1405': '.hersheyskitchens-home .viewby-grid li:eq(14) a',
        'KHLAT1406': '.hersheyskitchens-home .viewby-grid li:eq(15) a',
        'KHLAT1407': '.hersheyskitchens-home .viewby-grid li:eq(16) a',
        'KHLAT1408': '.hersheyskitchens-home .viewby-grid li:eq(17) a',
        'KHLAT1409': '.hersheyskitchens-home .viewby-grid li:eq(18) a',
        'KHLAT1410': '.hersheyskitchens-home .viewby-grid li:eq(19) a',
        'KHLAT1411': '.hersheyskitchens-home .viewby-grid li:eq(20) a',
        'KHLAT1412': '.hersheyskitchens-home .viewby-grid li:eq(21) a',
        'KHLAT1413': '.hersheyskitchens-home .viewby-grid li:eq(22) a',
        'KHLAT1414': '.hersheyskitchens-home .viewby-grid li:eq(23) a',
        'KHLAT1415': '.hersheyskitchens-home .viewby-grid li:eq(24) a',
        'KHLAT1416': '.hersheyskitchens-home .viewby-grid li:eq(25) a',
        'KHLAT1417': '.hersheyskitchens-home .viewby-grid li:eq(26) a',
        'KHLAT1418': '.hersheyskitchens-home .viewby-grid li:eq(27) a',
        'KHLAT1419': '.hersheyskitchens-home .viewby-list li:eq(0) a',
        'KHLAT1420': '.hersheyskitchens-home .viewby-list li:eq(1) a',
        'KHLAT1421': '.hersheyskitchens-home .viewby-list li:eq(2) a',
        'KHLAT1422': '.hersheyskitchens-home .viewby-list li:eq(3) a',
        'KHLAT1423': '.hersheyskitchens-home .viewby-list li:eq(4) a',
        'KHLAT1424': '.hersheyskitchens-home .viewby-list li:eq(5) a',
        'KHLAT1425': '.hersheyskitchens-home .viewby-list li:eq(6) a',
        'KHLAT1484': '.hersheyskitchens-home a#newslettersignup', /* add anchor ID */
        'KHLAT1494': '.hersheyskitchens-home ul.featured_recipes li:eq(0) a',
        'KHLAT1495': '.hersheyskitchens-home ul.featured_recipes li:eq(1) a',
        'KHLAT1496': '.hersheyskitchens-home ul.featured_recipes li:eq(2) a',
        'KHLAT1497': '.hersheyskitchens-home ul.featured_recipes li:eq(3) a',
        'KHLAT1498': '.hersheyskitchens-home ul.featured_recipes li:eq(4) a',
        'KHLAT1500': 'a#large_facebook_link'
    }

});

HERSHEYS.Kitchens.Analytics.track = function(which, data){
	var s = s_gi(s_account);
	s.templtv = s.linkTrackVars;          /*Saving the original state of the variables*/
	s.templte = s.linkTrackEvents;         /*Saving the original state of the variables*/
	
	switch(which){

		case 'submitTip':
			/* recipeID, if present. */
			var recipeID = data;
			s.linkTrackVars = "events,eVar37,eVar39,eVar10,products";      /*Defining the list of variables that will be sent in the server call*/
			s.products      = ';' + recipeID;
			s.eVar10        = s.prop30 = recipeID;
			s.eVar37        = s.prop27 = 'tipsubmit';
			s.eVar39        = s.prop28 = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event17';
			s.tl(true,'o','tip submission');   /*Server call */
	        break;

		case 'submitRecipe':
		/* nothing to pass */
			s.linkTrackVars = "events,eVar37,eVar39";      /*Defining the list of variables that will be sent in the server call*/
			s.eVar37        = s.prop27 = 'recipesubmit';
			s.eVar39        = s.prop28 = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event17';
			s.tl(true,'o','recipe submission');   /* Server call */
		break;

		case 'saveRecipeBox':
		/* recipeID */
			var recipeID = data;
			s.linkTrackVars = "events,eVar39,eVar10,products";      /*Defining the list of variables that will be sent in the server call*/
			s.products      = ';' + recipeID
			s.eVar10        = s.prop30 = recipeID
			s.eVar39        = s.prop28 = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event6';
			s.tl(true,'o','recipe save');   /*Server call*/          
			break;
		
		case 'addToGroceryList':
		/* recipeID */
		var recipeID = data;
                 s.linkTrackVars = "events,eVar39,eVar10,products";      /*Defining the list of variables that will be sent in the server call*/
                 s.products      = ';' + recipeID
                 s.eVar10        = s.prop30          = recipeID
                 s.eVar39        = s.prop28          = '[loggedIn]';
                 s.events        = s.linkTrackEvents = 'scAdd';
                 s.tl(true,'o','recipe add to grocery list');   /*Server call */
                break;
		
		case 'rateRecipe':
		/* recipeID */
		var recipeID = data;
                s.linkTrackVars = "events,eVar39,eVar37,products";      /*Defining the list of variables that will be sent in the server call*/
                s.products      = ';' + recipeID
                s.eVar37        = s.prop27          = 'RateaRecipe:' + recipeID
                s.eVar39        = s.prop28          = '[loggedIn]';
                s.events        = s.linkTrackEvents = 'event17';
                s.tl(true,'o','rate recipe');   /*Server call */	              
                break;
		
		case 'nutritionalView':
		/* recipeID */
		var recipeID = data;
                s.linkTrackVars = "events,eVar39,eVar10,products";      /*Defining the list of variables that will be sent in the server call*/
                s.products      = ';' + recipeID
                s.eVar10        = s.prop30          = recipeID
                s.eVar39        = s.prop28          = HERSHEYS.IsLoggedIn ? '[loggedIn]' : '[unknown]';
                s.events        = s.linkTrackEvents = 'event11';
                s.tl(true,'o','nutrition view');   /*Server call */                     
              	break;
		
		case 'addNoteToRecipe':
		/* nothing to pass- ideally we'd know which recipe is saved, but they are all on the same page... */
                s.linkTrackVars = "events,eVar39,eVar37";      /*Defining the list of variables that will be sent in the server call*/
                s.eVar37        = s.prop27          = 'addnotestorecipe:' + recipeID /* if recipe ID is possible, if not, just pass string */
                s.eVar39        = s.prop28          = '[loggedIn]';
                s.events        = s.linkTrackEvents = 'event17';
                s.tl(true,'o','add note to recipe');   /*Server call */               
                break;
		
		case 'removeRecipeFromBox':
		/* recipeID */
			var recipeID = data;
			s.linkTrackVars = "events,eVar36,eVar10,eVar39,products";      /*Defining the list of variables that will be sent in the server call*/
			s.products      = ';' + recipeID;
			s.eVar36        = s.prop26          = 'Recipes:removefromrecipebox'
			s.eVar10        = s.prop30          = recipeID;
			s.eVar39        = s.prop28          = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event16';
			s.tl(true,'o','remove recipe from box');   /*Server call */
            break;
		
		case 'removeRecipeFromGrocery':
		/* recipeID */
			var recipeID = data;
			s.linkTrackVars = "events,eVar36,eVar10,eVar39,products";      /*Defining the list of variables that will be sent in the server call*/
			s.products      = ';' + recipeID;
			s.eVar36        = s.prop26          = 'Recipes:removefromrecipebox'
			s.eVar10        = s.prop30          = recipeID;
			s.eVar39        = s.prop28          = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event16';
			s.tl(true,'o','remove recipe from box');   /*Server call */               
			break;
		
		case 'saveToLibrary':
			s.linkTrackVars = "events,eVar36,eVar39,eVar37,products";      /*Defining the list of variables that will be sent in the server call*/
			s.eVar36        = s.prop26          = 'Recipes:howto:hosting cookie exchange';
			s.eVar37        = s.prop27          = 'Recipes:howto:hosting cookie exchange:savetolibrary';
			s.eVar39        = s.prop28          = HERSHEYS.IsLoggedIn ? '[loggedIn]' : '[unknown]';
			s.events        = s.linkTrackEvents = 'event16,event18';
			s.tl(true,'o','save to library');   /*Server call */
			break;
		
		case 'share':
		
			var source = data;	
			
			if (typeof OMNITURE_RECIPE_ID != 'undefined'){
					s.linkTrackVars = "events,eVar39,eVar36,products";      /*Defining the list of variables that will be sent in the server call*/
					s.products      = ';' + OMNITURE_RECIPE_ID;
					s.eVar39        = s.prop28          = '[loggedIn]';
					s.eVar36        = s.prop26          = 'Sharerecipe:[' + source + ']';
					s.events        = s.linkTrackEvents = 'event7,event16';
					s.tl(true,'o','recipe share');   /*Server call */
			}else{
					s.linkTrackVars = "events,eVar39,eVar36,products";      /*Defining the list of variables that will be sent in the server call*/
					s.products      = ';' + recipeID;
					s.eVar39        = s.prop28          = HERSHEYS.IsLoggedIn ? '[loggedIn]' : '[unknown]';
					s.eVar36        = s.prop26          = 'Recipes:howto:hosting cookie exchange';
					s.eVar37        = s.prop27          = 'Recipes:howto:hosting cookie exchange:savetolibrary';
					s.events        = s.linkTrackEvents = 'event18,event16';
					s.tl(true,'o','page share');   /*Server call */
			}
						
		break;
		
		case 'login':
			s.linkTrackVars = "events,eVar39";      /*Defining the list of variables that will be sent in the server call*/
			s.eVar39        = s.prop28          = '[loggedIn]';
			s.events        = s.linkTrackEvents = 'event19';
			s.tl(true,'o','login');   /*Server call */                     
			break;
		
		case 'inviteFriend':
			/* Start vs Complete */
			var action = data;
			if (action == 'start'){
                        s.linkTrackVars = "events,eVar36,eVar39";      /*Defining the list of variables that will be sent in the server call*/
                        s.eVar36        = s.prop26          = 'Recipe:invite friend';
                        s.eVar39        = s.prop28          = HERSHEYS.IsLoggedIn ? '[loggedIn]' : '[unknown]';
                        s.events        = s.linkTrackEvents = 'event15';
                        s.tl(true,'o','invite friend start');   /*Server call */                     
          			
			}else if (action == 'complete'){
                        s.linkTrackVars = "events,eVar36,eVar39";      /*Defining the list of variables that will be sent in the server call*/
                        s.eVar36        = s.prop26          = 'Recipe:invite friend';
                        s.eVar39        = s.prop28          = HERSHEYS.IsLoggedIn ? '[loggedIn]' : '[unknown]';
                        s.events        = s.linkTrackEvents = 'event16';
                        s.tl(true,'o','invite friend complete');   /*Server call */
			}
			break;
			
		case 'recipeFilter':
			/* filter type, filter */
			var filterType = data.type.toLowerCase();
			var filterName = data.name.toLowerCase();
			s.linkTrackVars = "events,eVar5,eVar1";      /*Defining the list of variables that will be sent in the server call*/
			s.eVar1         = s.prop18          = '[' + filterType + ':' + filterName + ']';
			s.eVar5         = s.prop32          = '[recipe filters]';
			s.events        = s.linkTrackEvents = 'event1';
			s.tl(true,'o','recipe filters');   /*Server call */
            break;	
	}
	
	if (s.templtv) {
		s.linkTrackVars = s.templtv;    /*reassigning the variables to the original state */
	}

	if (s.templte) {
		s.linkTrackEvents = s.templte;   /*reassigning the variables to the original state */
	}	
};

/* Keep this as false, when you popup a recipe set to true.
	This way we know when we load a recipe deeplinked (ie no popup), 
	we disable further popus
*/
	
HERSHEYS.Kitchens.DEEP_LINKED_RECIPE = false;
HERSHEYS.Kitchens.DOING_POPUP = false;

HERSHEYS.Kitchens.initDetailPage = function () {

    // tabs
    var tabContainers = $('.tab-wrap > div, #tab7, #tab8');

    $('.tabs li a').bind('click', function () {
        tabContainers.hide().filter(this.hash).show();
        $('.tabs li a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();

    $('.rating-link a').bind('click', function () {
        $('#tab1,#tab2,#tab3,#tab5,#tab6,#tab7').hide();
        $('#tab4').show();
        return false;
    });
    $('.comment-links .see_comments').bind('click', function () {
        $('#tab1,#tab2,#tab3,#tab4,#tab6,#tab7').hide();
        $('#tab5').show();
        return false;
    });
    $('.comment-links .make_comment').bind('click', function () {
        $('#tab1,#tab2,#tab3,#tab4,#tab5,#tab7').hide();
        $('#tab6').show();
        return false;
    });
    $('.recipe_back').bind('click', function () {
        $('#tab4,#tab5,#tab6,#tab7,#tab8').hide();
        $('#tab1').show();
        $('#tab-recipe a').addClass('selected');
        $('#tab-tips a,#tab-techniques a').removeClass('selected');
        return false;
    });

    $('#blog-link').live('click', function () {

        $.fancybox.close();
        $('.tab-wrap > div, #tab7, #tab8').hide();
        $('#tab8').show();
        copyPermalink()
        return false;

    });

    //copy permalink
    function copyPermalink() {
        var theField = $("#copy-permalink");
        theField.focus();
        theField.select();
    }

    // social media
    $('.recipe-tools li.share-link').hover(function () {
        $('.recipe-tools li ul').addClass('show');
    }, function () {
        $('.recipe-tools li ul').removeClass('show');
    });

    $('#lnkSaveRecipe').bind('click', function () {

        var _this = $(this);

        var recipeID = $(this).attr('recipeid');

        if (!recipeID) recipeID = $(this).parent().attr('recipeid');

        HERSHEYS.Services.saveToRecipeBox({
            'recipeID': recipeID,

            'success': function (returns) {

                HERSHEYS.Kitchens.Analytics.track('saveRecipeBox', recipeID);

                _this.html('Recipe Saved!');
                $('p.myrecipes-link').show();
            },
            'failure': function () {

                HERSHEYS.Kitchens.loginCallback = function () {
                    $('.mykitchen-link').toggleClass('selected');
                    $('.my-kitchen-fly').toggle('slide', 1000);
                    _this.click();
                };

                $('.mykitchen-link').toggleClass('selected');
                $('.my-kitchen-fly').toggle('slide', 1000);

            }
        });

        return false;

    });

    $('.addToGroceryList').bind('click', function () {

        var _this = $(this);
        var recipeID = $(this).attr('recipeid');

        if (!recipeID) recipeID = $(this).parent().attr('recipeid');

        HERSHEYS.Services.addToGroceryList({

            'recipeID': recipeID,

            'success': function (returns) {
                HERSHEYS.Kitchens.Analytics.track('addToGroceryList', recipeID);
                _this.html('Added to Groceries!');
            },
            'failure': function () {

                HERSHEYS.Kitchens.loginCallback = function () {
                    $('.mykitchen-link').toggleClass('selected');
                    $('.my-kitchen-fly').toggle('slide', 1000);
                    _this.click();
                };

                $('.mykitchen-link').toggleClass('selected');
                $('.my-kitchen-fly').toggle('slide', 1000);
            }
        });

        return false;

    });

    /* PAGINATION HANDLER - todo: clean up a bit and combine into one function to handle both tips and recipes */

    $('#tip_pagaination_wrapper .tips-sort-prev').unbind().bind('click', function () {

        var pageNumber = $(this).attr('pageNumber') || 1;
        var recipeID = OMNITURE_RECIPE_ID;
        var orderBY = $('#tip_pagaination_wrapper .sortby a.active').attr('title') == 'Newest' ? 'false' : 'true';
        var pageSize = 5;
        var nextPage = (pageNumber * 1) - 1;
        $(this).attr("pageNumber", nextPage);

        if (nextPage === 0)
            $('#tip_pagaination_wrapper .tips-sort-prev').css('visibility', 'hidden');

        $('#tip_pagaination_wrapper .tips-sort-next').attr("pageNumber", pageNumber + 1);
        $('#tip_pagaination_wrapper .tips-sort-next').css('visibility', 'visible');

        $('.tip').css({ 'opacity': .5 });

        $.getJSON('/latino/kitchens/AjaxServices.ashx?method=gettips&recipeid=' + recipeID + '&page=' + pageNumber + '&pagesize=' + pageSize + '&orderby=' + orderBY, function (data) {
            var hasMore = data.hasmore;
            var html = data.html;

            $('.tip').remove();
            $('#tab2').append(html);

        });

        return false;
    });

    $('#tip_pagaination_wrapper .tips-sort-next').unbind().bind('click', function () {
        var pageNumber = $(this).attr('pageNumber') || 2;
        var recipeID = OMNITURE_RECIPE_ID;
        var orderBY = $('#tip_pagaination_wrapper .sortby a.active').attr('title') == 'Newest' ? 'false' : 'true';
        var pageSize = 5;
        var nextPage = (pageNumber * 1) + 1;

        $(this).attr("pageNumber", nextPage);

        $('#tip_pagaination_wrapper .tips-sort-prev').attr("pageNumber", nextPage - 2);
        $('#tip_pagaination_wrapper .tips-sort-prev').css('visibility', 'visible');
        $('.tip').css({ 'opacity': .5 });


        $.getJSON('/latino/kitchens/AjaxServices.ashx?method=gettips&recipeid=' + recipeID + '&page=' + pageNumber + '&pagesize=' + pageSize + '&orderby=' + orderBY, function (data) {
            var hasMore = data.hasmore;
            var html = data.html;

            $('.tip').remove();
            $('#tab2').append(html);
            if (hasMore == 'false') {
                $('#tip_pagaination_wrapper .tips-sort-next').css('visibility', 'hidden');
            } else {
                $('#tip_pagaination_wrapper .tips-sort-next').css('visibility', 'visible');
            }
        });
        return false;
    });

    $('#reviews_pagaination_wrapper .tips-sort-prev').unbind().bind('click', function () {

        var pageNumber = $(this).attr('pageNumber') || 1;
        var recipeID = OMNITURE_RECIPE_ID;
        var orderBY = $('#reviews_pagaination_wrapper .sortby a.active').attr('title') == 'Newest' ? 'false' : 'true';
        var pageSize = 5;
        var nextPage = (pageNumber * 1) - 1;
        $(this).attr("pageNumber", nextPage);

        if (nextPage === 0)
            $('#reviews_pagaination_wrapper .tips-sort-prev').css('visibility', 'hidden');

        $('#reviews_pagaination_wrapper .tips-sort-next').attr("pageNumber", pageNumber + 1);
        $('#reviews_pagaination_wrapper .tips-sort-next').css('visibility', 'visible');

        $('.review').css({ 'opacity': .5 });

        $.getJSON('/latino/kitchens/AjaxServices.ashx?method=getcomments&recipeid=' + recipeID + '&page=' + pageNumber + '&pagesize=' + pageSize + '&orderby=' + orderBY, function (data) {
            var hasMore = data.hasmore;
            var html = data.html;

            $('.review').remove();
            $('#tab5').append(html);

        });

        return false;
    });

    $('#reviews_pagaination_wrapper .tips-sort-next').unbind().bind('click', function () {
        var pageNumber = $(this).attr('pageNumber') || 2;
        var recipeID = OMNITURE_RECIPE_ID;
        var orderBY = $('#reviews_pagaination_wrapper .sortby a.active').attr('title') == 'Newest' ? 'false' : 'true';
        var pageSize = 5;
        var nextPage = (pageNumber * 1) + 1;
        $(this).attr("pageNumber", nextPage);

        $('#reviews_pagaination_wrapper .tips-sort-prev').attr("pageNumber", nextPage - 2);
        $('#reviews_pagaination_wrapper .tips-sort-prev').css('visibility', 'visible');
        $('.review').css({ 'opacity': .5 });


        $.getJSON('/latino/kitchens/AjaxServices.ashx?method=getcomments&recipeid=' + recipeID + '&page=' + pageNumber + '&pagesize=' + pageSize + '&orderby=' + orderBY, function (data) {
            var hasMore = data.hasmore;
            var html = data.html;

            $('.review').remove();
            $('#tab5').append(html);
            if (hasMore == 'false') {
                $('#reviews_pagaination_wrapper .tips-sort-next').css('visibility', 'hidden');
            } else {
                $('#reviews_pagaination_wrapper .tips-sort-next').css('visibility', 'visible');
            }
        });
        return false;
    });

    $('.pagination_wrapper span.sortby a').live('click', function () {

        if ($(this).hasClass('active')) return false;
        $(this).siblings().removeClass('active');
        $(this).addClass('active');

        $(this).parents('.pagination_wrapper').find('.tips-sort-next').attr('pagenumber', 2);
        $(this).parents('.pagination_wrapper').find('.tips-sort-prev').attr('pagenumber', 1).click();

        return false;

    });

    /* Any link with a class of sharethis will trigger a fancybox share dialogue */
    $('a.sharethis').bind('click', function (e) {

        //We need to hold onto the initial state of the form popup so we can continously do the find and replace for new popups

        var popContent = $(this).attr("href");

        $("#email-link").show();
        if ($(e.target).hasClass("button_share")) {
            $("#blog-link").hide();
        } else {
            $("#blog-link").show();
        }

        if (typeof HERSHEYS.Kitchens.saveShareFormState == 'undefined') {
            HERSHEYS.Kitchens.saveShareFormState = $('#share_modal').html();
        }

        $('#share_modal').html(HERSHEYS.Kitchens.saveShareFormState);

        var title = $(this).attr('title');
        var url = $(this).attr('pageurl');

        if ($(this).attr('recipeid') != '') {
            $('#share_modal #email-link, #sendToFriend').attr('recipeid', $(this).attr('recipeid')); //.show();
        }

        $('.share_list a[id!=email-link]').each(function () {

            var href = $(this).attr('href');

            href = href.replace('[REPLACE_TITLE]', title).replace('[REPLACE_URL]', url);
            $(this).attr('href', encodeURI(href));

        });

        if (IS_MOBILE) {
            $.fancybox(
            //$('#share_modal').html(),
								{
								'href': popContent,
								'transitionIn': 'elastic',
								'transitionOut': 'elastic'
				}
						);
        } else {
            $.fancybox(
            //$('#share_modal').html(),
								{
								'href': popContent,
								'transitionIn': 'elastic',
								'transitionOut': 'elastic',
								'scrolling': 'no'
				}
						);
        }
        return false;
    });
    $('a.popup, .similar-recipes a').unbind().bind('click', function () {

        /* If we are deeplinked, don't do the popup, just go to the page */
        if (HERSHEYS.Kitchens.DEEP_LINKED_RECIPE) return true;


        HERSHEYS.Kitchens.doingPopup = true;

        var that = $(this);
        HERSHEYS.Kitchens.tempScrollSave = $('html,body').scrollTop();


        $('html').animate({ scrollTop: 0 }, 500, "easeInOutQuad", function () {
            HERSHEYS.Kitchens.doPopup(that.attr('href'));
        });

        return false;

    });
    //bind star ratings to go to review tab on recipe detail
    $(".recipe-assets .rating span").unbind().bind("click", function (e) {
        ratingClicked = e.target.nodeName;
        $(this).parent().parent().find(".recipe-link a").click();
    });
    $('#recipe_detail_transparency, #detail-close').bind('click', function () {

        /* Fade out the wrapper and the transparency */
        $('#recipe_detail_popup_wrapper').fadeOut(500, function () { $('#recipe_detail_popup_wrapper #recipe_detail_content').html(''); });
        $('#recipe_detail_transparency').fadeOut(500);

        /* After that, return window scroll position UNLESS the person has scrolled down the page already */
        if ($('html,body').scrollTop() == 0) {
            setTimeout(function () {
                $('html,body').animate({ scrollTop: HERSHEYS.Kitchens.tempScrollSave }, 300, "easeInOutQuad");
            }, 500);
        }

    });

    $('.submit_recipe_review').bind('click', function () {

        var _this = $(this);

        var recipeID = $(this).attr('recipeid');

        HERSHEYS.Services.reviewRecipe({

            'recipeID': recipeID,
            'reviewtext': $('.rate_entry textarea').attr('value') || '',
            'overallrating': $('#rate_overall input:checked').attr('value') || 0,
            'tasterating': $('#rate_taste input:checked').attr('value') || 0,
            'difficultyrating': $('#rate_difficulty input:checked').attr('value') || 0,
            'apperancerating': $('#rate_appearance input:checked').attr('value') || 0,

            'success': function (returns) {
                HERSHEYS.Kitchens.Analytics.track('rateRecipe', recipeID);
                $('#tab6').hide();
                $('#tab7').show();
            },
            'failure': function () {

                HERSHEYS.Kitchens.loginCallback = function () {
                    $('.mykitchen-link').toggleClass('selected');
                    $('.my-kitchen-fly').toggle('slide', 1000);
                    _this.click();
                };

                $('.mykitchen-link').toggleClass('selected');
                $('.my-kitchen-fly').toggle('slide', 1000);
            }
        });

        return false;

    });

};

var ratingClicked;
HERSHEYS.Kitchens.doPopup = function (which) {

    $('#recipe_detail_transparency').fadeTo("slow", 0.8);

    if ($('#recipe_detail_popup_wrapper #recipe_detail_content').html() != '') {
        $('#recipe_detail_popup_wrapper #recipe_detail_content').html('');
    }


    if (which.indexOf('?id=') != -1) {


        var pieceOne = which.split('?id=');

        if (pieceOne.length === 1) return false;

        var recipeID = pieceOne[1];
        recipeID = recipeID.split('&')[0];
        




    } else {

        var pieceOne = which.split('/recipes/');

        if (pieceOne.length === 1) return false;

        var recipeID = pieceOne[1].split('/')[0];
        //recipeID = recipeID.split('=')[1];

    }



    HERSHEYS.Kitchens.DOING_POPUP = true;

    
    // alert(recipeID);
    // recipeID = 13;
    $('#recipe_detail_popup_wrapper #recipe_detail_content').load('/latino/kitchens/recipe-detail-popup.aspx?ID=' + recipeID, function () {
        // alert("Binding");
        HERSHEYS.globalBinds();
        // alert("Init detail page");
        HERSHEYS.Kitchens.initDetailPage();

        $('#recipe_detail_popup_wrapper').fadeIn();

        if (typeof OMNITURE_RECIPE_ID == 'undefined') return true;

        HERSHEYS.Analytics.trackRecipeView({
            'recipeID': OMNITURE_RECIPE_ID,
            'associatedProducts': OMNITURE_ASSOCIATED_PRODUCTS
        });

        if (ratingClicked == "IMG") {
            $(".rating-link a").click();
            ratingClicked = "";
        }
    });
};


$(document).ready(function () {

	var targetLocation;

	$('form:first').attr('action', window.location.href);

	/* Bind login forms to ajax version */
	$('.sign-in .action .btn, .loginButtonSubmit').bind('click', function(){

		HERSHEYS.Services.login({
			'username' : $('.sign-in input:eq(0)').attr('value'),
			'password' : $('.sign-in input:eq(1)').attr('value'),
			'keepLoggedIn' : $('.sign-in input:eq(2)').attr('checked'),

			'success' : function(returns){
					$('.sign-in span.error').remove();
					$('.sign-in .forms').fadeOut().html('<span class="success">Welcome, ' + returns['username'] + '!</span>').fadeIn();
					$('.sign-in .forgot').attr('visibility' , 'hidden');

					HERSHEYS.Kitchens.Analytics.track('login');

					setTimeout(function(){
						$('.top_login_link').html('Logout');
						$('.loggedInFullNav').slideDown();
						$('.loginLeftNavButton').hide();
						HERSHEYS.Kitchens.loginCallback();
					}, 1000);
					if(targetLocation){
						window.location = targetLocation;
						targetLocation = '';
					}
			},
			'failure' : function(){
				$('.sign-in .inner').effect('shake', 150);
				$('.sign-in span.error').remove();
				$('.sign-in .forms').prepend('<span class="error">Incorrect Username / Password</span>');
			}
		});

	    return false;
	});
	
	/* Bind the enter key to the submit button instead of the full form submission */
	$('.sign-in input:eq(0), .sign-in input:eq(1)').keydown(function(event){
		  if(event.keyCode == 13){
		    $('.sign-in .action .btn, .loginButtonSubmit').click();
			return false;
		  }
	});
	
	
	/* BIND SHOW OF LOGIN LINKS */
	$('.mykitchen-link').bind('click', function(){

	    $('.mykitchen-link').toggleClass('selected');
	    $('.my-kitchen-fly').toggle('slide', 1000);
		return false;

	});
	$('.top_login_link').bind('click', function(){
		
		if ($(this).html() == 'Logout') return true;

	    $('.mykitchen-link').toggleClass('selected');
	    $('.my-kitchen-fly').toggle('slide', 1000);
		return false;

	});
	
	/* ADD FORM ELEMENTS FOR SEND TO FRIEND */
	$(".add").bind('click', function(){
		$(".add_friends").append("<li class='add_friend'><label for='friend_name'>Your Friend's Name:</label><input type='text' name='friend_name' class='txt med' /></li><li class='add_email'><label for='friend_email'>Your Friend's Email:</label><input type='text' name='friend_email' class='txt med' /></li>");
		$.fancybox.resize();
		return false;
	});
	
	 /* ADD FORM ELEMENTS FOR SUBMIT RECIPE */
	$(".enter_ingredient .add").bind('click',function(){
	
		$('.ingredients_table').append('<tr>' + $('.ingredients_table tr:last').html() + '</tr>');

		$('.ingredients_table tr:last input').each(function(i,v){

		    var name = $(this).attr('name').split('_');
		    var number = (name[1] * 1) + 1;

		    $(this).attr('name', name[0] + '_' + number);

		});
		
		return false;
	});

	$('.close_modal').bind('click', function(){

	    $('.mykitchen-link').removeClass('selected');
	    $(this).parents('.my-kitchen-fly').fadeOut();
		return false;
	});
	
	/* Invite Friends Modal Popup Binds */
		$('#addAnotherFriend').live('click', function(){

		    var newRow = $('#add_friends li:last').html();
		    $('#add_friends').append(newRow);
		    $('#add_friends li:last input').attr('value', '');
		    $.fancybox.resize();
		});
		
		$('#sendToFriend').live('click', function(){

					var _this = $(this);

				  	var names = [];
				    var emails = [];
					var yourName = [];
					var yourEmail = [];

				    $('#invite_friends_form .add_friends li input[name=friend_name]').each(function(){
				        names.push($(this).attr('value'));
				    }); 

				    $('#invite_friends_form .add_friends li input[name=friend_email]').each(function(){
				        emails.push($(this).attr('value'));
				    }); 

					$('#invite_friends_form input[name=name]').each(function(){
				        yourName.push($(this).attr('value'));
				    }); 

				    $('#invite_friends_form input[name=email]').each(function(){
				        yourEmail.push($(this).attr('value'));
				    });      

				    var emailList = emails.join(',');
				    var nameList = names.join(',');
				    var yourName = yourName.join(',');
				    var yourEmail = yourEmail.join(',');
				    var comment = $('#invite_friends_form #comment').attr('value');

					HERSHEYS.Services.inviteFriends({

						'name' : yourName,
						'email' : yourEmail,
						'friendName' : nameList,
						'friendEmail' : emailList,
						'comment' : comment,

						'success' : function(returns){

							$('#invite_friends_form').hide();
							$('#invite_friends_sucess').show();
							$.fancybox.resize();

							HERSHEYS.Kitchens.Analytics.track('inviteFriends', 'complete');

						},
						'failure' : function(){

							HERSHEYS.Kitchens.loginCallback = function(){
								$('.mykitchen-link').toggleClass('selected');
								$('.my-kitchen-fly').toggle('slide', 1000);
								_this.click();
							 };

							 $('.mykitchen-link').toggleClass('selected');
							 $('.my-kitchen-fly').toggle('slide', 1000);				
						}

					});

				    return false;

				});
	
	
	$('#sendRecipeToFriend').live('click', function(){
	
		var _this = $(this);
		
		/*var names = [];
		var emails = [];
		var yourName = [];
		var yourEmail = [];
		
		$('input[name=friend_name]').each(function(){
			names.push($(this).attr('value'));
		}); 
	
		$('input[name=friend_email]').each(function(){
			emails.push($(this).attr('value'));
		}); 
	
		$('input[name=name]').each(function(){
			yourName.push($(this).attr('value'));
		}); 
		
		$('input[name=email]').each(function(){
			yourEmail.push($(this).attr('value'));
		}); 

		var emailList = emails.join(',');
		var nameList = names.join(',');
		var yourName = yourName.join(',');
		var yourEmail = yourEmail.join(',');
		var comment = $('#invite_friends_form #comment').attr('value');*/

		var yourName = $("input#yourName").val(),
			yourEmail = $("input#yourEmail").val(),
			nameList = $("input#friendName").val(),
			emailList = $("input#friendEmail").val(),
			recipeID = $(this).attr('recipeid') || 0,
			src = 'kitchens';
		
		HERSHEYS.Services.shareRecipe({
			'name' : yourName,
			'email' : yourEmail,
			'friendname' : nameList,
			'friendemail' : emailList,
			'recipeid' : shareRecipeID,
			'src'	: src ? src : false,

			'success' : function(returns){

				$('#share_recipe .modal_form').hide();
				$('#share_recipe .modal_success').show();
				$.fancybox.resize();
				
				HERSHEYS.Kitchens.Analytics.track('inviteFriends', 'complete');
				
			},
			'failure' : function(){
				
				HERSHEYS.Kitchens.loginCallback = function(){
					$('.mykitchen-link').toggleClass('selected');
					$('.my-kitchen-fly').toggle('slide', 1000);
					_this.click();
				 };
				
				 $('.mykitchen-link').toggleClass('selected');
				 $('.my-kitchen-fly').toggle('slide', 1000);				
			}
			
		});

	return false;

	});
	
	
	HERSHEYS.Kitchens.autoCompleteCallbacks = {
		
		recipes : {
				url : '/latino/kitchens/AjaxServices.ashx?method=recipeautocomplete',
				log : function(event, data, formatted) {
					return "No match!";
				},
				formatItem : function(row) {
					return "<img src='/latino/kitchens/Image.ashx?type=submittedphoto&id=" + row[0] + "&s=sm' class='l' style='width: 50px; margin-right: 10px' />"  + "<strong>" + row[1] + "</strong>";
				},
				formatResult : function(row) {
					return row[1];
				}		
		},
		tips : {
				url : '/latino/kitchens/AjaxServices.ashx?method=tipsautocomplete',
				log : function(event, data, formatted) {
					return "No match!";
				},
				formatItem : function(row) {
					return "<strong>" + row[1] + "</strong>";
				},
				formatResult : function(row) {
					return row[1];
				}		
		}
		
	}
	
	/* Function called, inline, by fancy dropdown up top toggle recipe/tip autocomplete. Has to be inline so that fancy drop down works */
	HERSHEYS.Kitchens.swapAutoComplete = function(which){
		$('.topSearchText').hide();
		$('.' + which + 'Autocomplete').show();
	}		

	$(".search-controls input.recipeAutocomplete").autocomplete(HERSHEYS.Kitchens.autoCompleteCallbacks.recipes.url, {
		width: 224,
		selectFirst : false,
		multiple: false,
		matchContains: true,
		formatItem: HERSHEYS.Kitchens.autoCompleteCallbacks.recipes.formatItem,
		formatResult: HERSHEYS.Kitchens.autoCompleteCallbacks.recipes.formatResult
	}).result(function(event, item) {
	  	
		if (HERSHEYS.Kitchens.DEEP_LINKED_RECIPE){
		    window.location.href = '/latino/kitchens/recipes/' + item[0] + '/details.aspx';
		}else{
			var url = '/latino/kitchens/recipe-detail-popup.aspx?ID=' + item[0];
		    $('#recipe_detail_transparency').fadeTo("slow", 0.8);
		
				$('#recipe_detail_popup_wrapper #recipe_detail_content').load(url, function(){
					HERSHEYS.globalBinds();
					HERSHEYS.Kitchens.initDetailPage();
					$('#recipe_detail_popup_wrapper').fadeIn();
				});
		}
	});
	
	$(".search-controls input.tipsAutocomplete").autocomplete(HERSHEYS.Kitchens.autoCompleteCallbacks.tips.url, {
		width: 224,
		selectFirst : false,
		multiple: false,
		matchContains: true,
		formatItem: HERSHEYS.Kitchens.autoCompleteCallbacks.tips.formatItem,
		formatResult: HERSHEYS.Kitchens.autoCompleteCallbacks.tips.formatResult
	}).result(function(event, item) {
	    var url = '/latino/kitchens/recipes/how-to/baking-tip-library.aspx?id=' + item[0];
		window.location = url;
	});	
	
	
	HERSHEYS.Kitchens.initDetailPage();
	HERSHEYS.KitchensSignup.init('#kitchensSignup');
	
    // stylish select
    $("#filter-select").sSelect();
	$("#content .locator_wrap select").sSelect().resetSS();

    // grid rollovers
    $('.viewby-grid li,.viewby-large li').hover(function () {
        $(this).addClass('show');
    }, function () {
        $(this).removeClass('show');
    });

    // hide exclude terms in search filters
    $('.exclude_hide').bind('click', function () {
        $('.exclude').hide('slow');
		$(this).parents('.search_term').hide('blind', 400);
    });

    // show or hide search filter lists
    $('.filter_head').bind('click', function () {
        $(this).next('.filter_list').toggle('slow');
        $(this).toggleClass('close');
        return false;
    });

    // show/hide recipe/tip submit forms
    $('.tip_form').hide();
    $('.sr').bind('click', function () {
        $('.recipe_form').show();
        $('.tip_form').hide();
    });
    $('.st').bind('click', function () {
        $('.tip_form').show();
        $('.recipe_form').hide();
    });
	
    // toggle tip text on my recipes page
    $('.mr_expand').bind('click', function () {
        $(this).next('.tip_text').toggleClass('open');
        $(this).toggleClass('close');
        $(this).parent('.mt_list li').toggleClass('open');
        //$('.tip_text').toggleClass('open');
        //$('.mr_expand a').toggleClass('close');
        //$('.mt_list li').toggleClass('open');
        return false;
    });


	/* Any link with "checklogin" as a class should first see if the variable holding login state is true, and if not, prompt login then continue on */
	$('.checklogin').live('click', function(e){
		var _this = $(this);
		
		targetLocation = e.target;
		
		if (HERSHEYS.IsLoggedIn){
			
		}else{
			HERSHEYS.Kitchens.loginCallback = function(){
				$('.mykitchen-link').toggleClass('selected');
				$('.my-kitchen-fly').toggle('slide', 1000);
				_this.click();
			 };
			
		  	$('.mykitchen-link').toggleClass('selected');
		  	$('.my-kitchen-fly').toggle('slide', 1000);
			
			return false;
		}
	});
	
	/* Any link with .confirm, popup a window asking if they are sure, using the text from the title attribute */
		$('a.confirm').bind('click', function(){
			
			var answer = confirm($(this).attr('title'));
			if (answer){
				return true;
			}
			else{
				return false;
			}
		});
	
	$('#email-link').live('click', function(e){
		var popContent = $(this).attr("href");
		shareRecipeID = $(this).attr("recipeid");
		$(".modal_success").hide();
		$.fancybox(
		//$("#share_recipe_pop").html(),
		{
			'href' : popContent,
			'autoDimensions' : false,
			'width' : 550,
			'height' : 242,
			'onComplete' : function(){
				$('#fancybox-inner #share_options').hide();
				$('#fancybox-inner #share_recipe .modal_form').show();
			}
		});
		
		return false;
		
	});
	
	/* Analytics BINDS */
	
		$('#submit_tip_form .btn').live('click', function(){
		    var recipeID = $('.txtRecipeId').attr('value');	
			HERSHEYS.Kitchens.Analytics.track('submitTip', recipeID);
		});
		$('#submit_recipe_form .btn').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('submitRecipe', recipeID);
		});
		$('.nutrition-link a').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('nutritionalView', OMNITURE_RECIPE_ID);
		});
		$('.save_recipe_box_button').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('addNoteToRecipe');
		});
		$('.recipe_box_wrap a.remove').live('click', function(){
			var recipeID = $(this).parents('recipe_wrapper').attr('recipeid');	
			HERSHEYS.Kitchens.Analytics.track('removeRecipeFromBox', recipeID);
		});
		$('.grocery_subgroup a.remove').live('click', function(){
			var recipeID = $(this).parents('recipe_wrapper').attr('recipeid');	
			HERSHEYS.Kitchens.Analytics.track('removeRecipeFromGrocery', recipeID);
		});
		$('.cookie-exchange-hosting .save-link a.checklogin').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('saveToLibrary');			
		});
		$('.share-links-kitchens').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('share', $(this).attr('id'));	
		});
		$('#invite_friends_link').live('click', function(){
			HERSHEYS.Kitchens.Analytics.track('inviteFriends', 'start');	
		});
		$('.recipe_filter_panel input:not(.go_submit)').bind('click', function(){
			var filterType = $(this).parents('.refine_wrap').attr('id').split('filter_by_')[1];
			var filterName = $(this).siblings('label:first').html();
			HERSHEYS.Kitchens.Analytics.track('recipeFilter', { type : filterType, name : filterName});		
		});
		

		
	
	

});

// suckerfish functions for IE
sfHover = function () {
    var sfEls = document.getElementById("nav").getElementsByTagName("li");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function () {
            this.className += " sfhover";
        }
        sfEls[i].onmouseout = function () {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }

    $("#nav-kitchen li").bind('mouseover', function () {
        $(this).addClass('sfhover');
    }).bind('mouseout', function () {
        $(this).removeClass('sfhover');
    });

}
if (window.attachEvent) window.attachEvent("onload", sfHover);
