$(document).ready(function() {
  var offset = $('#nav_recipes').offset();
  $('#recipes-submenu').css({'top':offset.top+20, 'left':offset.left-20});

  var menu_to;
  var to = 500;
  $('#nav_recipes').mouseover(function() {
    clearTimeout(menu_to);
    $('#recipes-submenu').fadeIn('fast');
  });

  $('#nav_recipes').mouseout(function() {
    menu_to = setTimeout('hide_submenu()', to);
  });

  $('#recipes-submenu').mouseover(function() {
    clearTimeout(menu_to);
  });

  $('#recipes-submenu').mouseout(function() {
    menu_to = setTimeout('hide_submenu()', to);
  });
});

function hide_submenu() {
$('#recipes-submenu').css({'display':'none'});
}

function show_popup(href) {
  //window.location=href;

  $.ajax({
	    url: href,
	    type: 'GET',
	    dataType: 'html',
	    timeout: 10000,
	    error: function(){
	  alert('Could not locate content.');
	    },
		beforeSend: function(){
			//do nothing
		},
	    success: function(html){
			$('body').append('<div id="modal-window"><div id="lightbox"><div id="lightbox-content"></div></div><div id="mask"></div></div>');
			
			//Get the screen height and width
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
		
			//Set height and width to mask to fill up the whole screen
			$('#mask').css({'width':maskWidth,'height':maskHeight});
			$('#mask').css({opacity:0.35});
			$('#mask').click(function() {
				$('#modal-window').remove();
			});
			$(document).keyup(function(e) {
				if(e.keyCode == 27) {   
					$('#modal-window').remove();
				}   
			});
			
			//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width();
			
			if ($('.suggestions').length>=1)
				$('.suggestions').css({'display':'none'});
			
			$('#lightbox-content').append('<a href="javascript:void(0)" id="modal-window-close" onclick="\$(\'#modal-window\').remove();">Click here to close panel</a><div class="reset"></div>');
			
			$('#lightbox-content').append(html);
			
			//Set the popup window to center
			var lightboxTop = $(window).scrollTop()+((winH-$('#lightbox').height())/2);
			var lightboxLeft = (winW/2)-($('#lightbox').width()/2);
			
			if (lightboxTop<=0) {lightboxTop=10;}
			if (lightboxLeft<=0) {lightboxLeft=10;}
			
			$('#lightbox').css({'left':lightboxLeft,'top':lightboxTop});
			
			$('#mask').fadeIn(400);
			
			$('#lightbox').fadeIn(400);
			
			return false;
	    }
	});
return false;
}
