$(document).ready(function() { 
    $("#fp_slideshow").cycle({ fx: "fade", pause: 3, speed: 3000 });
    
    $("#restaurant_menu #submenu a:first").addClass("active");      
    
    $("#phone_reservations")
      .hover(
        function() { $(this).parent().css({ backgroundPosition: "0 -110px" }) }, 
        function() { $(this).parent().css({ backgroundPosition: "top left" }) }
      );
    
    $("#mail_reservations")
      .hover(
        function() { $(this).parent().css({ backgroundPosition: "left bottom" }) }, 
        function() { $(this).parent().css({ backgroundPosition: "left top" }) }
      );
    
    $("#primary_menu li")
      .hoverIntent({
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
        interval: 100, // number = milliseconds for onMouseOver polling interval
        over: function() {
          $(this).children("ul").show();
        },
        timeout: 700, // number = milliseconds delay before onMouseOut
        out: function() { 
          $(this).children("ul").hide();
        }
      })
      .find("ul").hide();          
    
    $("#fishes .from_our_menu, #fishes .menu_link")
      .append("<div class=\"corner tl_corner\"></div>")
      .append("<div class=\"corner tr_corner\"></div>")
      .append("<div class=\"corner bl_corner\"></div>")
      .append("<div class=\"corner br_corner\"></div>");      
      
    handleMenuList();
    
    handleGalleryList();
    
    $("#news h2, #contact h1, #reservation h1, #restaurant_menu h2, #fishes h1.decorated, #fishes h2, #bd #restaurant_menu.wines h3").jQIR();
 }); 

function handleMenuList() { 
  if($("#restaurant_menu").length > 0) {    
    $("#restaurant_menu .list")
      .append("<div class=\"rounded_top rounded_corners\"></div>")
      .append("<div class=\"rounded_bottom rounded_corners\"></div>")
      .append("<div class=\"content\"></div>")      
      .addClass("hidden")
      .children("*:not(div)").each(function() { $(this).appendTo($(this).parent().children(".content")) });          
    
    $("#restaurant_menu .list:first").removeClass("hidden").addClass("visible"); 

    $("#submenu a").click(function() {
      $("#submenu a").removeClass("active");
      $(this).addClass("active");
      if(/#/.test(this.href)) {
        var newId = this.href.substr(this.href.search(/#/) + 1);
        var currentId = $("#restaurant_menu .list:visible").attr("id");

        if(currentId != newId) {
          var originalPosition = $("#" + currentId).position();
          
          $("#" + currentId)
            .animate(
              { left: "-1000px" }, 
              200,
              "swing", 
              function() {
                $(this).removeClass("visible").addClass("hidden");
                $("#" + newId).animate({ left: 0, top: 0 }, 200, "swing").addClass("visible").removeClass("hidden");                                
              }
            );
        }
      }
      return false;
    });
  }
}

function hideReservationMessage()
{
  $("#fp_reservation").animate({
    "bottom": "-5em",
    "left": "30em"
  });
  $("#fp_msg").fadeIn(1500);
}

function showReservationMessage()
{
  $("#fp_msg").fadeOut(1500);
  $("#fp_reservation").animate({
    "bottom": 0,
    "left": 0
  });  
  setTimeout(hideReservationMessage, 5000);
}

function handleGalleryList() { 
  if($("#gallery #submenu a").length > 0) {
    $("#gallery .gallery").hide().css({ position: "absolute", top: "40px", left: 0 });
    $("#gallery .gallery:first").show();

    $("#submenu a").click(function() {
      $("#submenu a").removeClass("active");
      $(this).addClass("active");
      if(/#/.test(this.href)) {
        var newId = this.href.substr(this.href.search(/#/) + 1);
        var currentId = $("#gallery .gallery:visible").attr("id");

        if(currentId != newId) {
          $("#" + currentId).fadeOut("fast");
          $("#" + newId).fadeIn("fast");
        }
      }
      return false;
    });
    
    var galleryId = window.location.href.substr(window.location.href.indexOf("#") + 1);
    if(galleryId) {
      $(window).scrollTop(0);
      $("#gallery").scrollTop(0);
      $("#submenu a[href=\'#" + galleryId + "\']").trigger("click");
    }
  }
}

/* Wayfarer Tooltip
 * Version 1.0.3
 * Author Abel Mohler
 * URI: http://www.wayfarerweb.com/wtooltip.php
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 */
(function(a){a.fn.wTooltip=function(f,r){f=a.extend({content:null,ajax:null,follow:true,auto:true,fadeIn:0,fadeOut:0,appendTip:document.body,degrade:false,offsetY:10,offsetX:1,style:{},className:null,id:null,callBefore:function(t,p,o){},callAfter:function(t,p,o){},clickAction:function(p,o){a(p).hide()},delay:0,timeout:0,cloneable:false},f||{});if(!f.style&&typeof f.style!="object"){f.style={};f.style.zIndex="1000"}else{f.style=a.extend({border:"1px solid gray",background:"#edeef0",color:"#000",padding:"10px",zIndex:"1000",textAlign:"left"},f.style||{})}if(typeof r=="function"){f.callAfter=r||f.callAfter}f.style.display="none",f.style.position="absolute";var m,l,q,c,k={},b=true,e=false,n=false,s=document.createElement("div"),g=(typeof document.body.style.maxWidth=="undefined")?true:false,j=(typeof a.talk=="function"&&typeof a.listen=="function")?true:false;if(f.id){s.id=f.id}if(f.className){s.className=f.className}f.degrade=(f.degrade&&g)?true:false;for(var d in f.style){s.style[d]=f.style[d]}function i(o){if(o){if(f.degrade){a(s).html(f.content.replace(/<\/?[^>]+>/gi,""))}else{a(s).html(f.content)}}}if(f.ajax){a.get(f.ajax,function(o){if(o){f.content=o}i(f.content)})}function h(p){function t(u){if(m&&!f.content){u.title=m;m=null}}function o(){if(!e&&f.auto){clearInterval(c);if(f.fadeOut){a(s).fadeOut(f.fadeOut,function(){t(p)})}else{t(p);s.style.display="none"}}if(typeof f.callAfter=="function"){f.callAfter(s,p,f)}if(j){f=a.listen(f)}}if(f.timeout>0){q=setTimeout(function(){o()},f.timeout)}else{o()}}a(s).hover(function(){e=true},function(){e=false;h(k)});if(j){f.key=s;f.plugin="wTooltip";f.channel="wayfarer";a.talk(f)}i(f.content&&!f.ajax);a(s).appendTo(f.appendTip);return this.each(function(){this.onmouseover=function(t){var p=this;clearTimeout(q);if(this.title&&!f.degrade&&!f.content){m=this.title;this.title=""}if(f.content&&f.degrade){this.title=s.innerHTML}function o(){if(typeof f.callBefore=="function"){f.callBefore(s,p,f)}if(j){f=a.listen(f)}if(f.auto){var u;if(f.content){if(!f.degrade){u="block"}}else{if(m&&!f.degrade){a(s).html(m);u="block"}else{u="none"}}if(u=="block"&&f.fadeIn){a(s).fadeIn(f.fadeIn)}else{s.style.display=u}}}if(f.delay>0){l=setTimeout(function(){o()},f.delay)}else{o()}};this.onmousemove=function(y){var w=(y)?y:window.event,v=this;k=this;if(f.follow||b){var A=a(window).scrollTop(),B=a(window).scrollLeft(),x=w.clientY+A+f.offsetY,t=w.clientX+B+f.offsetX,z=a(f.appendTip).outerHeight(),p=a(f.appendTip).innerHeight(),o=a(window).width()+B-a(s).outerWidth(),u=a(window).height()+A-a(s).outerHeight();x=(z>p)?x-(z-p):x;n=(x>u||t>o)?true:false;if(t-B<=0&&f.offsetX<0){t=B}else{if(t>o){t=o}}if(x-A<=0&&f.offsetY<0){x=A}else{if(x>u){x=u}}s.style.top=x+"px";s.style.left=t+"px";b=false}};this.onmouseout=function(){clearTimeout(l);var o=this;b=true;if(!f.follow||n||(f.offsetX<0&&f.offsetY<0)){setTimeout(function(){c=setInterval(function(){h(o)},1)},1)}else{h(this)}};if(typeof f.clickAction=="function"){this.onclick=function(){f.clickAction(s,this)}}})}})(jQuery);

/*
*
* Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
* 
*/
/*
 * jQuery Image Replacement. An alternative to using CSS hacks
 * The id attribute (or class) is used for the filename
 *
 * @name     jQIR  
 * @param    Function onload  (optional) Function to run when image has loaded 
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $(".jqir").jQIR("png", "images/");
 * @before   <h1 id="heading1" class="jqir">Heading 1</h1>
 *           <h2 class="jqir {src:heading2.png}">Heading 2</h2>
 * @result   <h1 id="heading1" class="jqir"><img alt="Heading 1" src="images/heading1.png"></h1>   
 *           <h2 class="jqir {src:heading2.png}"><img alt="Heading 2" src="images/heading2.png"></h2>   
 * @example  $(".jqir").jQIR("gif"); // use same folder as page
 * @before   <h1 id="heading1" class="jqir">Heading 1</h1>
 * @result   <h1 id="heading1" class="jqir"><img alt="Heading 1" src="heading1.gif"></h1>   
 *
 */
jQuery.fn.jQIR = function(onload)
{
  if(!document.images) return this;
  path = "/replacement/";
  this.each(
    function()
    {
      var img = $("<img>"), el = jQuery(this);
      var file;
      var re = /(?:{src\:)(\S+)(?:})/i;
      var m = this.className.match(re);
      if(m)
      {
        file = path + m[1];
      }
      else
      {
        file = path + "index.php?type=" + this.className + "&text=" + escape($(this).html());
      }
      
      jQuery(img).attr(
      {
        src: file,
        alt: el.text()
      }).load(typeof onload == "function" ? onload : function(){} );
      var a = el.find("a");
      var toAppend = a.length ? a.empty().append(img) : img;
      el.empty().append(toAppend);
    }
  );
  return this;
}