$(document).ready(function() {

/* Add Tweet This Button */
/* This feature was removed at the request of Katherine
	$('div#latest-from p').each(function() {
		var original = $(this).html().replace(/ /g,'+');
		var tweetLink = '<div class="share-box"><a class="share" href="http://www.twitter.com/?status=RT+@medeavodka+' + original + '" target="_blank">Tweet This</a></div>';
				
		$(tweetLink).prependTo(this).css('display', 'none');
	});
	
	$('div#latest-from p').hover(function() {
		$(this).find('div.share-box').show(400);
	}, function() {
		$(this).find('div.share-box').hide(400);
	});
*/


/* Logic for "flag as inappropriate" button on aspirations */
	// $('#latest-from div.items div.aspiration form').hide(0);
	// $('#latest-from div.aspiration').hover(function() {
	// 	$(this).find('form').show('slow');
	// }, function() {
	// 	$(this).find('form').hide('slow');
	// });
	
	$('#latest-from div.items div.aspiration form input.flag').click(function() {
		var answer = confirm ("Are you sure you want to flag this content?  This action can't be undone.");
		if (answer) {
			return true;
		} else {
			return false;
		}
	});
	

/* Toggle Newsletter Form */

	$('#social #newsletter').hover(function() {
		$('#social #newsletter-form').slideToggle(500);
		$('#social #newsletter').css('height', '90px');
	}, function() {
		$('#social #newsletter-form').slideToggle(500);
		$('#social #newsletter').css('height', '20px');
	});


/* Open links in new tab/window */

	$('a[rel*=blank]').click(function(){
		this.target = "_blank";
	});


/* Insert Browser Specific Stylesheets */

	if ($.browser.opera) {
		$('head').append('<link rel="stylesheet" href="/css/opera.css" type="text/css" />');
	}


/* Age Verification Stuff */

	$('div#age-verification #no, div#age-verification #yes').fadeTo(0, .25);

	$('div#age-verification #no, div#age-verification #yes').hover(function() {
		$(this).stop().fadeTo(500, 1);
	}, function() {
		$(this).stop().fadeTo(500, .25);		
	});
	
	
/* Homepage Stuff */
	
	$('#inner-ticker').css('left', '660px');

	$('#inner-ticker img').load(scrollWords());

	function scrollWords(){
		$('#inner-ticker').css('left', '640px');
		$('#inner-ticker').animate({left: '-27000'}, 147000, 'linear', scrollWords2);
	}
	
	function scrollWords2(){
		$('#inner-ticker').css('left', '640px');
		$('#inner-ticker').animate({left: '-27000px'}, 147000, 'linear', scrollWords);
	}

	
/* Aspirations Stuff */

	$('div#latest-from p:odd').removeClass('am').addClass('want');

	// initialize scrollable  
	$('div.scrollable').scrollable({ 
		vertical:true,  
		size: 10 
		 
	// use mousewheel plugin 
	}).mousewheel();   
	
	
/* Tastings Stuff */	

	$('div.tastings table tr:nth-child(odd)').addClass('even'); 
	
	$('div.tastings tr td:nth-child(1)').css('width', '215px');
	$('div.tastings tr td:nth-child(2)').css('width', '155px');
	$('div.tastings tr td:nth-child(3)').css('width', '258px');
	
	
/* How To Tick Stuff */

	if (!($.browser.msie && $.browser.version=="6.0")) {
		$('span.diagram2').hover(function(){
			$('img.diagram1, img.diagram3, img.diagram4, img.diagram5').css('z-index', '0').css('display', 'none');
			$('img.diagram2').css('z-index', '10').css('display', 'inline');
		}, function(){
			$('img.diagram2').css('z-index', '0').css('display', 'none');
			$('img.diagram1').css('z-index', '10').css('display', 'inline');
		});
		
		$('span.diagram3').hover(function(){
			$('img.diagram1, img.diagram2, img.diagram4, img.diagram5').css('z-index', '0').css('display', 'none');
			$('img.diagram3').css('z-index', '10').css('display', 'inline');
		}, function(){
			$('img.diagram3').css('z-index', '0').css('display', 'none');
			$('img.diagram1').css('z-index', '10').css('display', 'inline');
		});
		
		$('span.diagram4').hover(function(){
			$('img.diagram1, img.diagram3, img.diagram2, img.diagram5').css('z-index', '0').css('display', 'none');
			$('img.diagram4').css('z-index', '10').css('display', 'inline');
		}, function(){
			$('img.diagram4').css('z-index', '0').css('display', 'none');
			$('img.diagram1').css('z-index', '10').css('display', 'inline');
		});
		
		$('span.diagram5').hover(function(){
			$('img.diagram1, img.diagram3, img.diagram2, img.diagram5').css('z-index', '0').css('display', 'none');
			$('img.diagram5').css('z-index', '10').css('display', 'inline');
		}, function(){
			$('img.diagram5').css('z-index', '0').css('display', 'none');
			$('img.diagram1').css('z-index', '10').css('display', 'inline');
		});
	};
	
	
/* Contact Us Stuff */

	$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$('#message').slideUp(750,function() {
		$('#message').hide();
		
 		$('#submit')
			.after('<img src="/images/ajax-loader.gif" class="loader" />')
			.attr('disabled','disabled');
		
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			phone: $('#phone').val(),
			subject: $('#subject').val(),
			comments: $('#comments').val(),
			verify: $('#verify').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
				$('#contactform #submit').attr('disabled',''); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});
	
	
/* Fix sidebar height problem in IE6 */

	if ($.browser.msie && $.browser.version == 6.0) {
		if ($(document).height() > $(window).height()) {
			var documentHeight = $(document).height() + 'px';
			
			$('#sidebar').css('height', documentHeight);
			
			// Take care of an image sizing and loading problem
		}
	}
	
});