$(document).ready(function() {

		// clear inputs onclick
		$.fn.clear = function() {
			return this.focus(function() {
				if( this.value == this.defaultValue )
					this.value = "";
			}).blur(function() {
				if( !this.value.length )
					this.value = this.defaultValue;
			});
		};
		$("input[type='text']").clear();	

		//homepage
		$("#home-nav span:not(.current)").css("opacity","0");
		$("#home-nav span").hover(function () {			
			$("#home-nav span").not(this).stop().animate({opacity : 0}, 'fast'); // nav remove rollover from others
			$(this).stop().animate({opacity: 1}, 500); // nav rollover
			$("#bubbles div." + $(this).parents('li').attr('class')).stop(true, true).fadeIn(500).siblings('div').fadeOut('fast');// show/hide bubbles
		});
		
		$("#rudi-slideshow").cycle();
				
		//product page		
		$("#nutritional-info a").fancybox({overlayShow: false, transitionIn: 'elastic'});
		$("a.iframe").fancybox({overlayShow: false, transitionIn: 'elastic', width: '80%', height: '80%'});
				
		$("div.results div.result").click(function() {
			var d = $(this).find('h3 a').attr('href');
			window.location = d;
		});		
		
		$("#social>li>a").click(function(event) {
			$("#social").find('.popup').hide();
			$(this).parent().find('div.popup').show();
			return false;
		});
	
		$('body').click(function() {
			$("#social").find('div.popup').hide();
		});
	
		// split page for news + faqs
		$("#content div.hidden").hide();	
		$("#content-filter a").click(function() {
			var d = $(this).attr('href').replace('#', '');
			$("div#" + d).fadeIn().siblings('div').hide();
			$(this).addClass('current').parent('li').siblings('li').children('a').removeClass('current');
			return false;
		});
		
		// where to buy
		$("#select-category").change(function() {
			$("select.productnum").each(function(i) {
				this.selectedIndex = 0;
			});
			
			var v = $(this).val();
			$('select.hidden').hide();	
			$("#select-"+v).fadeIn();
		});	
		
		$("#category-select label").click(function() {
			var v = $(this).children('input').val();
			$("#"+v+"-lists").show().siblings('.filter-list').hide();
		});	
		
		// organic product nav
		$("#organic-product-list>ul>li>a.product-type").click(function(){
			$("#organic-product-list>ul>li>ul").slideUp();
			$(this).parent('li').children('ul').stop().slideToggle();
			return false;
		});	
			
});
