$(document).ready(function() {

  
  $('#navigation > li').hover(function() {
    $(this).addClass('hover');
    
    var pos = $(this).position();
    var navigation_width = $('#navigation').width();
    var submenu_width = $(this).find('.submenu').width();
    
    if((pos.left + submenu_width) > navigation_width) {
      pos_left = navigation_width - (pos.left + submenu_width);
      $(this).find('.submenu').css('left', pos_left);
    }
  }, function() {
    $(this).removeClass('hover');
  });
  
  $('.all_letters a').click(function() {
    $('.all_letters a').not(this).removeClass('active');
    $(this).addClass('active');
    
    var id = $(this).attr('href');
    $.scrollTo(id, {duration: 300, axis:"y"});
    
    return false;
  });
  
  $('.filter_row .filter_toggle_link').click(function() {
    var n = $('.filter_links', $(this).closest('.filter_row'));
    var t = $(this);
    
    if($(t).hasClass('expanded')) {
      $(n).slideUp('fast', function() {
        $(t).removeClass('expanded');
        $(n).removeClass('expanded');
      });
    } else {
      $(n).slideDown('fast', function() {
        $(t).addClass('expanded');
        $(n).addClass('expanded');
      });
    }
    
    return false;
  });
});

function showPopup(id) {
  var h = document.body.clientHeight;
  
  $('#overlay').fadeTo(500, 0.5);
  $('#zoom_popup').fadeTo(500, 1);
  
  return false;
}

/*
 * ScrollToElement 1.0
 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
 *  lauri.huovila@neovica.fi
 *  http://www.neovica.fi
 *  
 * Dual licensed under the MIT and GPL licenses.
 */

(function($) {
    $.scrollToElement = function( $element, speed ) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function( speed ) {
        speed = speed || "normal";
        return $.scrollToElement( this, speed );
    };
})(jQuery);

