$(document).ready(function(){

  var menu_height = $('#global_navigation_menu').height();

  $('#global_navigation_menu').css({'opacity':0,'height':0});

  $('#global_navigation').hover(
                            function(e){
                              e.preventDefault();
                              $('#global_navigation_menu').stop().animate({'height':menu_height,'opacity':1});
                            },
                            function(e){
                              e.preventDefault();
                              $('#global_navigation_menu').stop().animate({'height':0,'opacity':0});
                            });

  $('#top_sellers tr:odd').addClass('odd')
                          .find('a:not(.browse_all)')
                          .addClass('round_all product');
                          
  $('#home h1').hide();

  $('#featured').loopedSlider({
    containerClick: false,
    pagination: 'preview',
    slidespeed: 1500,
    autoStart: 4000,
    restart: 6000
  });
  
  $('#listings tbody tr:odd, #data tbody tr:odd, #race-specials tbody tr:odd, #data tbody td:even').addClass('odd');

  $('.switcher').click(function(e){
    e.preventDefault();
    $this = $(this);
    $this.find('span:first').toggleClass('visible');
    $($this.attr('href')).find('img:first').toggleClass('visible');
  });

  $('#gallery a.thumb').colorbox({transition:'fade',
                                  rel:'find_detail',
                                  opacity: .5,
                                  maxHeight: '90%',
                                  maxWidth: '90%',
                                  scalePhotos: true});
                                
  $('#find .price a').colorbox({opacity:.5});

  $('#colorbox #contact form').live('submit', function(e){
    e.preventDefault();
    $form = $(this);
    $form.hide();
    $.post($form.attr('action'),
           $form.serialize(),
           function(data){
             $('#contact').empty().html(data).show();
           },
           "html");
  });

  $('a[href$=.pdf]').click(function(e){
    e.preventDefault();
    window.open($(this).attr('href'),'brochure');
  });

  $('#listings a.listing_title').ellipsis();

  $('#datetime').datepicker({
      duration: '',
      showTime: true,
      constrainInput: true,
      minDate:'+1D',
      maxDate:'+1Y'
   });

  $('#pickup-date, #dropoff-date').datepicker({
      duration: '',
      constrainInput: true,
      minDate:'+1D',
      maxDate:'+1Y'
   });
});

$(window).load(function(){
  var top_seller_details = $('#top_sellers_details div');
  $('#top_sellers a:not(.browse_all)').each(function(i){
    $(this).bubbletip(top_seller_details[i]);
  });
});
