   BGC.track.init("UA-22382332-1");
	BGC.track();

	var HK_GRAVY = HK_GRAVY || {};

HK_GRAVY.Controller = {
	init: function () {
		HK_GRAVY.Tracking.init();
		HK_GRAVY.UI.Flash.init();
	}
};

// start document ready
$(document).ready(function () {
	// initialize controller
	HK_GRAVY.Controller.init();
	
		// Carousel nav
  		jQuery('#right_arrow').click(function(e){
  			rightArrow();
			e.preventDefault();
		});
		jQuery('#left_arrow').click(function(e){
			e.preventDefault();
			if(!$.browser.msie){
				$(this).fadeOut(250);
			}else{
				$(this).css('display', 'none');
			}
			$('#slide').animate({marginLeft: '36px'}, 1000, function(){
				if(!$.browser.msie){
					$('#right_arrow').fadeIn(250);
				}else{
					$('#right_arrow').css('display','block');
				}			
			});
		});
		
		 // Modal Overlays
        jQuery('.modalLink').click(function (e) {
            e.preventDefault();
            var modalID = '#' + $(this).attr('rel');
            jQuery(modalID).dialog("open");
        });
        jQuery('.modalOverlay').each(function(){
        		$(this).dialog({
            	autoOpen: false,
            	width:$(this).css('width'),
            	open: function (event, ui) {
                	jQuery('#mask').css('display', 'block');  // adding mask separately, as 'modal' setting locks up ie7
            	},
            	close: function (event, ui) {
                	jQuery('#mask').css('display', 'none');
                	jQuery('.iframe').each(function(){
                		if($(this).html != ''){
                			$(this).html();
                		} 
                	
                	})
           		 }
        		});
			});
					
				
	jQuery('a.flavor_recipe_image, a.recipe_item_image').hover(
  		function () {
  
    		$(this).siblings('.flavor_recipe_link, .recipe_item_link').addClass('imageHover');
  		}, 
  		function () {
    		$(this).siblings('.flavor_recipe_link, .recipe_item_link').removeClass('imageHover');
  		}
	);


	jQuery('a.flavor_recipe_link, a.recipe_item_link').hover(
  		function () {
    		$(this).siblings('.flavor_recipe_image, .recipe_item_image').addClass('textHover');
  		}, 
  		function () {
    		$(this).siblings('.flavor_recipe_image, .recipe_item_image').removeClass('textHover');
  		}
	);

	jQuery('a#stories_meta_link').hover(
  		function () {
    		$('#stories_meta_image').addClass('storiesTextHover');
  		}, 
  		function () {
    		$('#stories_meta_image').removeClass('storiesTextHover');
  		}
	);
});

HK_GRAVY.Tracking = {
	init: function () {
		// class-based GA tracking hooks
		// link tracking (finds and tracks links with class="track category|action|label" applied)
		$("a.track").live("click", function (e) {
			var ev = getEventString(this.className), target = null, callback = null, href = null;
			if (ev) {
				if (this.className.match(/action/)) { // use "action" rather than "event" tracking
					ev = "/" + ev.replace(/\|/g, "/");
				}
				target = this.target;
				if ( !target || target.match(/^_(self)|(top)$/i) ) {
					href = $(e.target).closest("a")[0].href;
					callback = function () {
						if ( target.match(/^_top$/i) ) {
							top.location.href = href;
						} else {
							location.href = href;
						}
					};
					e.preventDefault();
				}
				BGC.track(ev, callback);
			}
		});
		
		// form view/submit "action" (virtual pageview) tracking
		$("form.track").each(function () {
			var ev = getEventString(this.className).replace(/\|/g, "/");
			if (ev) {
				BGC.track(ev + "/view");
				$(this).submit(function (e) {
					if (Page_IsValid) { // only track the submit action if the .NET validation routine passed
						BGC.track(ev + "/submit");
					}
				});
			}
		});
		
		function getEventString (s) {
			var ev = "";
			s = s.split(" ");
			$.each(s, function () {
				if (this.indexOf("|") > -1) {
					ev = this.toString();
					return;
				}
			});
			return ev;
		}
	}
};


HK_GRAVY.UI = {
	
	Flash: {
		init: function () {
			$(".flash-replace").each(function () {
				flashembed( this, {
					src: this.getAttribute("data-swf"),
					version: getVersion(this),
					wmode: this.getAttribute("data-swf-wmode"),
					base: this.getAttribute("data-swf-base")
				}, jsonParse( this.getAttribute("data-flashvars") || "{}" ) );
				$(this).css('visibility', 'visible');
			}).removeClass("flash-replace"); // ensure flash replacement only happens one time!

			function getVersion (el) {
				var v = el.getAttribute("data-swf-version").split(",");
				$.each(v, function (i) {
					v[i] = parseInt(v[i], 10);
				});
				return v;
			}
		}
	}
	
};



function rightArrow(){
	if(!$.browser.msie){
		$('#right_arrow').fadeOut(250);
	}else{
		$('#right_arrow').css('display', 'none');
	}
	$('#slide').animate({marginLeft: '-750px'}, 1000, function(){
		if(!$.browser.msie){
			$('#left_arrow').fadeIn(250);
		}else{
			$('#left_arrow').css('display','block');
		}			
	});
};
		
function lastFive(){
	$('#right_arrow').css('display', 'none');
	$('#slide').css('margin-left','-750px');
	$('#left_arrow').css('display','block');
};

/**
 * @license 
 * jQuery Tools 1.2.0 / Flashembed - New wave Flash embedding
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/toolbox/flashembed.html
 *
 * Since : March 2008
 * Date  :    Tue Apr 20 19:26:58 2010 +0000 
 */ 
(function() {
		
	var IE = document.all,
		 URL = 'http://www.adobe.com/go/getflashplayer',
		 JQUERY = typeof jQuery == 'function', 
		 RE = /(\d+)[^\d]+(\d+)[^\d]*(\d*)/,
		 GLOBAL_OPTS = { 
			// very common opts
			width: '100%',
			height: '100%',		
			id: "_" + ("" + Math.random()).slice(9),
			
			// flashembed defaults
			allowfullscreen: true,
			allowscriptaccess: 'always',
			quality: 'high',	
			
			// flashembed specific options
			version: [3, 0],
			onFail: null,
			expressInstall: null, 
			w3c: false,
			cachebusting: false  		 		 
	};
	
	// version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
	if (window.attachEvent) {
		window.attachEvent("onbeforeunload", function() {
			__flash_unloadHandler = function() {};
			__flash_savedUnloadHandler = function() {};
		});
	}
	
	// simple extend
	function extend(to, from) {
		if (from) {
			for (key in from) {
				if (from.hasOwnProperty(key)) {
					to[key] = from[key];
				}
			}
		} 
		return to;
	}	

	// used by asString method	
	function map(arr, func) {
		var newArr = []; 
		for (var i in arr) {
			if (arr.hasOwnProperty(i)) {
				newArr[i] = func(arr[i]);
			}
		}
		return newArr;
	}

	window.flashembed = function(root, opts, conf) {
	
		// root must be found / loaded	
		if (typeof root == 'string') {
			root = document.getElementById(root.replace("#", ""));
		}
		
		// not found
		if (!root) { return; }
		
		if (typeof opts == 'string') {
			opts = {src: opts};	
		}

		return new Flash(root, extend(extend({}, GLOBAL_OPTS), opts), conf); 
	};	
	
	// flashembed "static" API
	var f = extend(window.flashembed, {
		
		conf: GLOBAL_OPTS,
	
		getVersion: function()  {
			var ver;
			
			try {
				ver = navigator.plugins["Shockwave Flash"].description.slice(16); 
			} catch(e) {
				
				try  {
					var fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
					ver = fo && fo.GetVariable("$version");	 
				} catch(err) {
					try { // ADDED BY T.D.
						var fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
						ver = fo && fo.GetVariable("$version");	 
					} catch (err) {
						ver = "0.0.0";
					}
					
				} 
			}
			
			ver = RE.exec(ver);
			return [ver[1], ver[3]];
		},
		
		asString: function(obj) { 

			if (obj === null || obj === undefined) { return null; }
			var type = typeof obj;
			if (type == 'object' && obj.push) { type = 'array'; }
			
			switch (type){  
				
				case 'string':
					obj = obj.replace(new RegExp('(["\\\\])', 'g'), '\\$1');
					
					// flash does not handle %- characters well. transforms "50%" to "50pct" (a dirty hack, I admit)
					obj = obj.replace(/^\s?(\d+\.?\d+)%/, "$1pct");
					return '"' +obj+ '"';
					
				case 'array':
					return '['+ map(obj, function(el) {
						return f.asString(el);
					}).join(',') +']'; 
					
				case 'function':
					return '"function()"';
					
				case 'object':
					var str = [];
					for (var prop in obj) {
						if (obj.hasOwnProperty(prop)) {
							str.push('"'+prop+'":'+ f.asString(obj[prop]));
						}
					}
					return '{'+str.join(',')+'}';
			}
			
			// replace ' --> "  and remove spaces
			return String(obj).replace(/\s/g, " ").replace(/\'/g, "\"");
		},
		
		getHTML: function(opts, conf) {

			opts = extend({}, opts);
			
			/******* OBJECT tag and it's attributes *******/
			var html = '<object width="' + opts.width + 
				'" height="' + opts.height + 
				'" id="' + opts.id + '"' + 
				'" name="' + opts.id + '"';
			
			if (opts.cachebusting) {
				opts.src += ((opts.src.indexOf("?") != -1 ? "&" : "?") + Math.random());		
			}			
			
			if (opts.w3c || !IE) {
				html += ' data="' +opts.src+ '" type="application/x-shockwave-flash"';		
			} else {
				html += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';	
			}
			
			html += '>'; 
			
			/******* nested PARAM tags *******/
			if (opts.w3c || IE) {
				html += '<param name="movie" value="' +opts.src+ '" />'; 	
			} 
			
			// not allowed params
			opts.width = opts.height = opts.id = opts.w3c = opts.src = null;
			opts.onFail = opts.version = opts.expressInstall = null;
			
			for (var key in opts) {
				if (opts[key]) {
					html += '<param name="'+ key +'" value="'+ opts[key] +'" />';
				}
			}	
		
			/******* FLASHVARS *******/
			var vars = "";
			
			if (conf) {
				for (var k in conf) { 
					if (conf[k]) {
						var val = conf[k]; 
						vars += k +'='+ (/function|object/.test(typeof val) ? f.asString(val) : val) + '&';
					}
				}
				vars = vars.slice(0, -1);
				html += '<param name="flashvars" value=\'' + vars + '\' />';
			}
			
			html += "</object>";	
			
			return html;				
		},
		
		isSupported: function(ver) {
			return VERSION[0] > ver[0] || VERSION[0] == ver[0] && VERSION[1] >= ver[1];			
		}		
		
	});
	
	var VERSION = f.getVersion(); 
	
	function Flash(root, opts, conf) {  
	                                                
		// version is ok
		if (f.isSupported(opts.version)) {
			root.innerHTML = f.getHTML(opts, conf);
			
		// express install
		} else if (opts.expressInstall && f.isSupported([6, 65])) {
			root.innerHTML = f.getHTML(extend(opts, {src: opts.expressInstall}), {
				MMredirectURL: location.href,
				MMplayerType: 'PlugIn',
				MMdoctitle: document.title
			});	
			
		} else {
			
			// fail #2.1 custom content inside container
			if (!root.innerHTML.replace(/\s/g, '')) {
				root.innerHTML = 
					"<h2>Flash version " + opts.version + " or greater is required</h2>" + 
					"<h3>" + 
						(VERSION[0] > 0 ? "Your version is " + VERSION : "You have no flash plugin installed") +
					"</h3>" + 
					
					(root.tagName == 'A' ? "<p>Click here to download latest version</p>" : 
						"<p>Download latest version from <a href='" + URL + "'>here</a></p>");
					
				if (root.tagName == 'A') {	
					root.onclick = function() {
						location.href = URL;
					};
				}				
			}
			
			// onFail
			if (opts.onFail) {
				var ret = opts.onFail.call(this);
				if (typeof ret == 'string') { root.innerHTML = ret; }	
			}			
		}
		
		// http://flowplayer.org/forum/8/18186#post-18593
		if (IE) {
			window[opts.id] = document.getElementById(opts.id);
		} 
		
		// API methods for callback
		extend(this, {
				
			getRoot: function() {
				return root;	
			},
			
			getOptions: function() {
				return opts;	
			},

			
			getConf: function() {
				return conf;	
			}, 
			
			getApi: function() {
				return root.firstChild;	
			}
			
		}); 
	}
	
	// setup jquery support
	if (JQUERY) {
		
		// tools version number
		$.tools = $.tools || {version: '1.2.0'};
		
		$.tools.flashembed = {  
			conf: GLOBAL_OPTS
		};	
		
		$.fn.flashembed = function(opts, conf) {		
			return this.each(function() { 
				$(this).data("flashembed", flashembed(this, opts, conf));
			});
		}; 
	} 
	
})();


