Cufon.replace('#main_nav', {hover: {textShadow: '1px 1px rgba(0, 0, 0, 0.2)'} })
.replace('.home_theme h2', {
	fontStretch: '96%',
	textShadow: '0.5px -0.5px #000',
	color: '-linear-gradient(#515151, #999999)'
})
.replace('#side_nav h3, #wine_buttons, #fruit h3, #sidebar h3, #contact #side_info h2')
// the following is for th wines page
.replace('#page_header h1', {
	fontStretch: '96%',
	textShadow: '-0.5px 0.5px #000',
	color: '-linear-gradient(#111111, #696969)'
});

jQuery(document).ready(function($){
	var $body = $('body'), bodyID = $body.attr('id');
	$body.removeClass('nojs').addClass('js');
	
	// animate footer corks
	$('#footer a.corked').hover(function(){
	  $(this).find('h1').stop().animate({backgroundPosition: '0px'}, 100, 'easeOutQuad', function(){
		$(this).animate({backgroundPosition: '12px'}, 100, 'easeInQuad', function(){
		  $(this).animate({backgroundPosition: '6px'}, 100, 'easeOutQuad');
		});
	  });
	},function(){});
	
	// animate footer button borders
	var $footer_buttons = $('#footer_buttons a'),
	$footer_button = $footer_buttons.filter(':first');
	$footer_button.data({
	  old_border_width: parseFloat($footer_buttons.css("borderLeftWidth")),
	  old_margin_left: parseFloat($footer_buttons.css("marginLeft"))
	});
	$footer_buttons.hover(function(){
	  var $this = $(this),
	  old_border_width = $footer_button.data().old_border_width,
	  old_margin_left = $footer_button.data().old_margin_left,
	  new_margin_left = old_margin_left - 4,
	  new_border_width = old_border_width + 4;
  
	  $this.animate({borderLeftWidth: new_border_width + 'px', marginLeft: new_margin_left + 'px'}, 200);
	  $this.animate({borderLeftWidth: old_border_width - 2 + 'px', marginLeft: old_margin_left + 2 + 'px'}, 200);    
	},function(){
	  $(this).stop().animate({borderLeftWidth: $footer_button.data().old_border_width + 'px', marginLeft: $footer_button.data().old_margin_left + 'px'}, 130);
	});
	
	if (bodyID == 'home' || 'wines') {
	  // animate side_nav/sidebar bullets
	  $('#side_nav ul li a, #sidebar ul li a').hover(function(){
		  $(this).stop().animate({backgroundPosition: '14px'}, 800, 'easeOutElastic');
	  },function(){
		  $(this).stop().animate({backgroundPosition: '10px'}, 800, 'easeOutBounce');
	  });
	}
	if (bodyID == 'home') {
	  // create gliding effect on wine buttons
	  var glider = $('<span class="glider"></span>');
	  glider.css('opacity','0').appendTo('#content_bottom');
	  $('#wine_buttons li a').hover(function() {
		  var pos, left;
		  pos = $('#wine_buttons li a').index(this);
		  if (pos != 0) { left = (163 * pos) + 'px'; } else { left = '0px'; }
		  glider.stop().animate({
			  opacity: 1,
			  left: left
		  }, 700, 'easeOutExpo');
	  }, function() {
		  glider.stop().animate({opacity: 0}, 300);
	  });
	  
	  // create passing glow effect
	  var slideshow_div = $('#slideshow');
	  slideshow_div.wrapInner('<div />');
	  $('<img id="pass_glow" src="images/pass_glow.png" width="349" height="232" />').appendTo(slideshow_div);
	  passGlow = function() {
		  $('#slideshow img#pass_glow').animate({left: slideshow_div.width()}, 2000, 'easeInOutCubic', function(){
			  $(this).css('left', '-350px');
		  });
	  }
	  setTimeout('passGlow()', 3000);
	  setTimeout("setInterval('passGlow()', 4500)", 3000);
	  // initiate slideshow
	  slideshow_div.find('div').cycle({
		  speed: 2000,
		  timeout: 4500,
		  random:  1
	  });
	  // animate happy spirits button
		var $span = $('#happy_spirits').find('span');
		$span.data({oldLeft: parseFloat($span.css('left'))})
		$('#happy_spirits').hover(function(){
			var left = $span.data().oldLeft + 4;
			$span.stop().animate({left: left + 'px'}, 400, '', function(){
				$span.animate({left: left - 3 + 'px'}, 220, 'easeOutQuad')
			});
		}, function(){
			var left = $span.data().oldLeft + 'px';
			$(this).find('span').stop().animate({left: left}, 'easeOutBack');
		});
	}
	else if (bodyID == 'wines') {
	  // extent .background_shadow to footer
		$('.background_shadow').css("minHeight", function(){
		  return $(window).height() - $('#footer').height() - $(this).offset().top + 'px';
		});
	  // animate wine categories hash scroll
		$('#sub_nav li a').click(function() {
		  var hash = $(this).attr('hash'),
		  html_body = $("html, body"),
		  // offset either $(hash) offset, or lowest scroll available
		  offset = Math.min($(hash).offset().top, $(document).height() - html_body.height()),
		  speed = Math.min((offset * 1.5), 1000);
		  html_body.animate({
			  scrollTop: offset
		  }, speed, 'easeOutExpo', function(){ window.location.hash = hash; });
		  return false;
		});
	  // fancybox
	    $('a.bottle').colorbox({
		  width: '450px',
		  maxHeight: function(){ return $(window).height(); },
		  scalePhotos: true,
		  transition: 'fade',
		  opacity: 0.8,
		  current: ""/*"Wine Bottle {current} of {total}"*/,
		  speed: 200,
		  title: function(){ return $(this).parent().find('h3').text(); }
		});
	}
});
