jQuery(document).ready(function() {      
  jQuery("#menu-navigation li:last-child").addClass("last-child");
  
  jQuery("#menu-item-23 a").click(function(){
    jQuery(window).scrollTo('#home', 1000);
    
    jQuery('#menu-navigation').find('.active').css({"display" : "none", "opacity" : "0"}).removeClass("active");
    jQuery(this).next(".shadow").css("display", "block").addClass("active").animate({
      'opacity': 1
    }, 1000);
    
    return false;
  });
  
  jQuery("#menu-item-22 a, #link-2").click(function(){
    jQuery(window).scrollTo('#our-story', 1200);
    
    jQuery('#menu-navigation').find('.active').css({"display" : "none", "opacity" : "0"}).removeClass("active");
    jQuery(this).next(".shadow").css("display", "block").addClass("active").animate({
      'opacity': 1
    }, 1000);
    
    return false;
  });
  
  jQuery("#menu-item-21 a, #link-3").click(function(){
    jQuery(window).scrollTo('#menu', 1200);
    
    jQuery('#menu-navigation').find('.active').css({"display" : "none", "opacity" : "0"}).removeClass("active");
    jQuery(this).next(".shadow").css("display", "block").addClass("active").animate({
      'opacity': 1
    }, 1000);
    
    return false;
  });
  
  jQuery("#menu-item-20 a").click(function(){
    jQuery(window).scrollTo('#gallery', 1200);
    
    jQuery('#menu-navigation').find('.active').css({"display" : "none", "opacity" : "0"}).removeClass("active");
    jQuery(this).next(".shadow").css("display", "block").addClass("active").animate({
      'opacity': 1
    }, 1000);
    
    return false;
  });
  
  jQuery("#menu-item-19 a, #link-1").click(function(){
    jQuery(window).scrollTo('#contact-us', 1200);
    
    jQuery('#menu-navigation').find('.active').css({"display" : "none", "opacity" : "0"}).removeClass("active");
    jQuery(this).next(".shadow").css("display", "block").addClass("active").animate({
      'opacity': 1
    }, 1000);
    
    return false;
  });
  
  jQuery("#menu-navigation li").each(function(){
    jQuery(this).append('<div class="shadow" style="opacity: 0;z-index: -99999; position:absolute; display: none;"></div>');
  });
  
  function toggleShadow() {
    
  }
  
  jQuery("#foodmenu-container").jScrollPane({
    showArrows: true,
    verticalDragMinHeight: 103,
    verticalDragMaxHeight: 103
  });
  
  var x = jQuery(".gallery-horizontal ul").size();
  jQuery(".gallery-horizontal").css("width", 235*x);
  
  jQuery(".gallery-images").jScrollPane({
    showArrows: true,
    horizontalDragMinWidth: 104,
    horizontalDragMaxWidth: 104
  });
  
  jQuery( "#stores" ).accordion({autoHeight: false});
  
  jQuery( "#contact-info").accordion({autoHeight: false, active: 2});
  
  jQuery(".map").gMap({ 
    controls: false,
    scrollwheel: false,
    markers: [{ address: "350 Bourke St Melbourne 3000",
                html: "<strong>Ramen Ya at GPO</strong><br/>Shop 25G Melbourne's GPO<br/>350 Bourke St<br/>Melbourne 3000<br/>T (03) 9654 5838" },
              { address: "108 Bourke St Melbourne 3000",
                html: "<strong>Ramen Ya on Bourke</strong><br/>Shop 9 The Paramount<br/>108 Bourke St<br/>Melbourne 3000<br/>T (03) 9662 1001" }],
    icon: { image: "/wp-content/themes/ramenya/images/map-pointer.png", 
            iconsize: [29, 48],
            iconanchor: [12, 46],
            infowindowanchor: [12, 0] },
    zoom: 15 }); 
  
  jQuery("a.img-gallery").fancybox({
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'speedIn'   : 600, 
    'speedOut'    : 200, 
    'overlayShow' : true,
    'overlayColor' : '#000000',
    'titleShow' : false,
    'padding' : 0
  });
  
  jQuery(".slides img").each(function(){
    jQuery(this).css({'opacity' : '0', 'position' : 'absolute', 'top':'0', 'left':0});
  });
  
  jQuery("#feat-home li, #feat-link li").each(function() {
    jQuery(this).css('opacity', '0');
  });
  
  jQuery("#feat-home li:first-child, #feat-link li:first-child").each(function() {
    jQuery(this).css('opacity', '1').addClass("active");
  });
  
  jQuery(".slides img:first-child").css({'opacity' : '1', 'position' : 'absolute', 'top':'0', 'left': '0'}).addClass("active");
  
  jQuery("#feat-page li").click(function(){
    clearInterval(j);
    jQuery("#feat-page").find(".active").removeClass("active");
    jQuery(this).addClass("active");
    
    var id = jQuery(this).attr("id");
    if(id == 'nav-1') {
      if(jQuery("#feat-1").hasClass("active")) {
        return false;
      } else {
        showSlideOne();
      }
    } else if(id == 'nav-2') {
      if(jQuery("#feat-2").hasClass("active")) {
        return false;
      } else {
        showSlideTwo();
      }
    } else {
      if(jQuery("#feat-3").hasClass("active")) {
        return false;
      } else {
        showSlideThree();
      }
    }
    startSlide();
  });
  
  rotate = function(){
    i = jQuery('#feat-page li.active').attr("id");
    clearInterval(j);      
    if(i == 'nav-1') {
      showSlideTwo();
    } else if(i == 'nav-2') {
      showSlideThree();
    } else if(i == 'nav-3') {
      showSlideOne();
    }
    startSlide();
  }; 

  //Rotation  and Timing Event
  startSlide = function(){
    j = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
      rotate(); //Trigger the paging and slider function
    }, 8000);//Timer speed in milliseconds (7 seconds)
  };
  
  startSlide();
  
  function showSlideOne() {
    jQuery("#feat-home").find(".active").css('opacity', '0').removeClass("active");
    jQuery("#feat-link").find(".active").css('opacity', '0').removeClass("active");
    jQuery("#feat-1").addClass("active").animate({
      opacity: 1,          
    }, 1000);
    
    jQuery("#link-1").addClass("active").animate({
      opacity: 1,          
    }, 1000);
    
    jQuery(".slides").find(".active").css({'z-index' : '10', 'opacity' : '0'}).removeClass("active");
    jQuery(".banner-1").addClass("active");
    jQuery(".banner-1").animate({
      opacity: 1,          
    }, 2000);
    
    jQuery("#feat-page").find(".active").removeClass("active");
    jQuery("#nav-1").addClass("active");
  }
  
  function showSlideTwo() {
    jQuery("#feat-home").find(".active").css('opacity', '0').removeClass("active");        
    jQuery("#feat-link").find(".active").css('opacity', '0').removeClass("active");
    jQuery("#feat-2").addClass("active");
    jQuery("#feat-2").animate({
      opacity: 1,          
    }, 1000);
    jQuery("#link-2").addClass("active").animate({
      opacity: 1,          
    }, 1000);
    
    jQuery(".slides").find(".active").css({'z-index' : '10', 'opacity' : '0'}).removeClass("active");
    jQuery(".banner-2").addClass("active");
    jQuery(".banner-2").animate({
      opacity: 1,          
    }, 2000);
    
    jQuery("#feat-page").find(".active").removeClass("active");
    jQuery("#nav-2").addClass("active");
  }
  
  function showSlideThree() {
    jQuery("#feat-home").find(".active").css('opacity', '0').removeClass("active");
    jQuery("#feat-link").find(".active").css('opacity', '0').removeClass("active");
    jQuery("#feat-3").addClass("active");
    jQuery("#feat-3").animate({
      opacity: 1,
    }, 1000);
    
    jQuery("#link-3").addClass("active").animate({
      opacity: 1,          
    }, 1000);
    
    jQuery(".slides").find(".active").css({'z-index' : '10', 'opacity' : '0'}).removeClass("active");
    jQuery(".banner-3").addClass("active");
    jQuery(".banner-3").animate({
      opacity: 1,          
    }, 2000);
    
    jQuery("#feat-page").find(".active").removeClass("active");
    jQuery("#nav-3").addClass("active");
  }
  
  
  jQuery('.parallax-image').each(function(){
    jQuery(this).parallax({ 
      'coeff': jQuery(this).attr('data-offset'),
      'stop': jQuery(this).parents('.section').offset().top + jQuery(this).parents('.section').height(),
      'start': jQuery(this).parents('#our-story').offset().top - jQuery(window).height()
    });
  });
  
  jQuery(".menu-slides img").each(function(){
    jQuery(this).css({'opacity' : '0', 'position' : 'absolute', 'top':'0', 'left':'0', 'z-index' : '10'});
  });
  
  jQuery(".menu-slides img:first-child").css({'opacity' : '1', 'position' : 'absolute', 'top':'0', 'left': '0'}).addClass("active");
  
  jQuery("#foodmenu-list a").click(function(){
    var rel = jQuery(this).attr("rel");
    
    jQuery(".menu-slides").find(".active").css({'display' : 'none', 'z-index' : '10', 'opacity' : '0'}).removeClass("active");
    jQuery(".menu-slides").find("#menu-"+rel).css({'display': 'block', 'z-index' : 14}).addClass("active");
    jQuery(".menu-slides").find("#menu-"+rel).animate({
      opacity: 1,          
    }, 1000, function() {
      // Animation complete.
    });
    
    jQuery(".menu-description-wrapper").find(".active").css({'display' : 'none', 'z-index' : '10', 'opacity' : '0'}).removeClass("active");
    jQuery(".menu-description-wrapper").find("#description-"+rel).css({'display': 'block', 'z-index' : 14}).addClass("active");
    jQuery(".menu-description-wrapper").find("#description-"+rel).animate({
      opacity: 1,          
    }, 1000, function() {
      // Animation complete.
    });
    return false;
  });
  
  var onMouseOutOpacity = 0.4;
  
  jQuery('.gallery-wrapper li a').opacityrollover({
    mouseOutOpacity:   onMouseOutOpacity,
    mouseOverOpacity:  1.0,
    fadeSpeed:         'fast',
    exemptionSelector: '.selected'
  });
  
  jQuery(".menu-description-wrapper .menu-description").each(function() {
    jQuery(this).css({'opacity' : '0', 'position' : 'absolute', 'top':'20px', 'left':'20px', 'z-index' : '10'});
  });
  
  jQuery(".menu-description-wrapper .menu-description:first-child").css({'opacity' : '1', 'position' : 'absolute', 'top':'20px', 'left': '20px'}).addClass("active");
  
  function isMobile() {
    var uagent = navigator.userAgent.toLowerCase();
     if (uagent.search("android") > -1 || uagent.search("iphone") > -1 || uagent.search("ipod") > -1)
        return true;
     else
        return false;
  }
  
  if(isMobile()) {
    window.onscroll = function() {
      document.getElementById('footer').style.top =
         (window.pageYOffset + window.innerHeight - 47) + 'px';
      document.getElementById('navigation').style.top =
        (window.pageYOffset) + 'px';
    };
    
   
  }
  /*window.onload = function() {
    document.getElementById("navigation").style.width = document.body.offsetWidth + 'px';
    document.getElementById('footer').style.width = document.body.offsetWidth + 'px';
  };*/
 
});
