jQuery(document).ready(function() {

  // Stripes page
  if (jQuery(".stripes").length > 0) {
    
    jQuery(".stripe").each(function() {
      overlay = jQuery('<div class="black-overlay"></div>').css('width', jQuery(this).width())
                                                           .css('height', jQuery(this).height());
      jQuery(this).prepend(overlay);
      jQuery(this).mouseover(function() {
        jQuery(this).find('.black-overlay').hide();
      }).mouseout(function() {
        jQuery(this).find('.black-overlay').show();
      });
      
    });
    
  }
  
  // Grid and category page
  if (jQuery(".grid").length > 0 || jQuery(".category").length > 0) {
    
    jQuery(".cell").each(function() {
      overlay = jQuery('<div class="black-overlay"></div>').css('width', jQuery(this).width())
                                                           .css('height', jQuery(this).height());
      jQuery(this).prepend(overlay);
      jQuery(this).mouseover(function() {
        jQuery(this).find('.black-overlay').hide();
      }).mouseout(function() {
        jQuery(this).find('.black-overlay').show();
      });
      
    });
  }
  
  // Home page
  if (jQuery(".home-page").length > 0) {
    
    jQuery(".square").each(function() {
      overlay = jQuery('<div class="black-overlay"></div>').css('width', jQuery(this).width())
                                                           .css('height', jQuery(this).height());
      jQuery(this).prepend(overlay);
      jQuery(this).mouseover(function() {
        jQuery(this).find('.black-overlay').hide();
      }).mouseout(function() {
        jQuery(this).find('.black-overlay').show();
      });
      
    });
  }
  
  setTimeout(function() {
    $(".scroll-pane").jScrollPane({
      mouseWheelSpeed: 0.4,
      verticalGutter: 10
    }, 200);
  });
  
  $("a[rel=facebox]").facebox();
  $(document).bind("reveal.facebox", function() {
      $("#facebox").css('top', $(document).height()/2 - $("#facebox").height() / 2);
  });
  
  $("a[title=home]").attr('href', home_page_url);
  
  $(".sub-menu").parent().addClass('with-submenu');
  $("a[title=planner]").click(load_planner);
  
//   if (current_lang != 'it') {
//     $(".localizable-link a").each(function() {
// //      $(this).attr('href', '/' + current_lang + $(this).attr('href').replace('http://www.gonellaliving.com/', '') + '/');
//     });
//   }
  
});

function show_menu(trash) {
//  jQuery("#menu .menu-item").hide();
  jQuery(".sub-menu").parent().show();
  jQuery(".sub-menu").show();
  jQuery(".sub-menu").find('.menu-item').show();
  jQuery(".sub-menu .sub-menu").hide();
  jQuery(".sub-menu .current-menu-item").find(".sub-menu").show();
  jQuery(".sub-menu .current-menu-ancestor").find(".sub-menu").show();
  jQuery(".sub-menu .current-menu-ancestor").find(".sub-menu").find(".menu-item").not('.current-menu-item').find(".sub-menu").hide();
  jQuery(".sub-menu .current-menu-item").find(".sub-menu").find(".sub-menu").hide();
  jQuery("#menu-main-menu .menu-item:first").show();
  jQuery("#menu-main-menu .menu-item:last").show();
  $(".current_page_item").closest('.sub-menu').show();
  $(".current-menu-item").find('a').first().addClass('menu-selected');
}

function load_planner() {
  swf_html = '<iframe style="overflow:hidden" scrolling="no" src="/planner_' + current_lang + '/planner.swf" width="720" height="440"></iframe>';
  $.facebox(swf_html);
}

function select_lang(lang, redirect_to) {
  $.cookie('gonellaliving-lang', lang);
  if (redirect_to) {
    location.href = redirect_to;
  }
}
