function chr (ascii)
{  
	return String.fromCharCode(ascii);
}

$q(document).ready(function()
{
	
	$q.ctrl = function(key, callback, args) 
	{
		$q(document).keydown(function(e) 
		{
			if(!args) args=[]; // IE barks when args is null
			if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) 
			{
				callback.apply(this, args);
				return false;
			}
		});
	};
	
	$q.ctrl(chr(37), function() { // left key
		if ($q('.button_left a').attr('href')) window.location.href = ($q('.button_left a').attr('href'));
	});
	

	$q.ctrl(chr(38), function() { // upper key
		if ($q('#button_tonews').attr('href')) window.location.href = ($q('#button_tonews').attr('href'));
	});

	$q.ctrl(chr(39), function() { // right key
		if ($q('.button_right a').attr('href')) window.location.href = ($q('.button_right a').attr('href'));
	});
	
	$q('.recipe_item .block span').click(function()
	{
		if ($q(this).attr('id') == 'sw_comments' && $q('#sw_comments').attr('class') == 'active') return;
		if ($q(this).attr('id') == 'sw_recipe'  && $q('#sw_recipe').attr('class') == 'active') return;
		
		$q('#sw_comments').toggleClass ('active');
		$q('#sw_recipe').toggleClass ('active');

		if ($q(".recipe_item .comments").css('display') == 'block')
		{
			
			$q(".recipe_item .comments").slideToggle("fast");
			$q(".recipe_item .recipe").slideToggle("slow");
		}
		else
		{
			$q(".recipe_item .recipe").slideToggle("fast");
			$q(".recipe_item .comments").slideToggle("slow");
		}

	});
	
	$q(window).scroll(function()
	{
		if ($q(window).scrollTop() > 140)
		{
			$q('body').addClass('fixed');
		}
		else
		{
			$q('body').removeClass('fixed');
		}
	}); 	

	$q(function showpodmenu() 
	{
		$q("#recipes_menu").bind('mouseenter', function (event) {
			$q(".recipe_menu").show();
			$q(".shadow").show();

		});
		$q(".recipe_menu").bind('mouseleave', function (event) {
			$q(".shadow").hide();
			$q(".recipe_menu").hide();
		});
	});
	
	if ($q.browser.msie && $q.browser.version == 6)
	{
		$q('.button_left a').html ('<img src="/@/fit/gallery_arrow_left.gif" width="23" height="37" alt="" />');
		$q('.button_right a').html ('<img src="/@/fit/gallery_arrow_right.gif" width="23" height="37" alt="" />');
	}
	
});
