
(function($){

	$(document).ready(function(){

		/* save current recipe id for recent recipes. */
		(function(){
			var id = $('#recipe_detail > input[name=recipe_id]').val();
			if (id) {
				/* get stored recipe ids. */
				var cookie = getCookie('recentRecipeIds');
				var idList = cookie ? cookie.split('|') : [];

				/* remove same id. */
				idList = $.grep(idList, function(value){
					return value !== id;
				});

				/* append id & strip ids. */
				idList.push(id);
				idList = idList.slice(-12);

				/* save recent recipes. */
				setCookie('recentRecipeIds', idList.join('|'), {
					path: '/',
					expires: 365	/* 365 days. */
				});
			}
		})();

		/* open print window handler. */
		$('#main div.action li.print_recipe a').click(function(){
			window.open(this.href, 'ebaraPrintRecipe', 'scrollbars=yes,resizable=yes,width=810,height=810');
			return false;
		});

		/* send to mobile handler. */
		if ($.isFunction($.fn.colorbox)) {
			$('#main div.action li.send_mobile a').colorbox({
				iframe: true,
				innerWidth: 550,
				innerHeight: 550,
				opacity: 0.25
			});
		}

		/* select all permalink text. */
		$('#main div.action li.permalink input').click(function(){
			this.select();
		});

		/* navigate back handler. */
		$('#main div.back a').click(function(){
			history.back();
			return false;
		});
	});

})(jQuery);

