$(document).ready(function() {

	if($('#myList').length){
		$('#myList').listnav();
	}

	
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//QUICK JUMP FUNCTIONALITY
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    //set up tab options
	var tabOpts = {
	  fx: {
		opacity: "toggle",
		duration: "fast" 
	  }, 
	  collapsible: true, 
	  selected: null
	};
	
	if($("#tabs").length){
		$("#tabs").tabs(tabOpts); 
	}
	$("#tabs-2").tabs(tabOpts);
	//$('#tabs-2" > ul').tabs();	


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//NAV FUNCTIONALITY
/////////////////////////////////////////////////////////////////////////////////////////////////////////

	if($.browser.mozilla || $.browser.safari || $.browser.chrome || $.browser.msie && $.browser.version >= 7) {

		//nav hover states
		$('#mainNav li.products a').hover(function() {
														
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_products_ro.png)');
				
			}, function() {
				
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_products.png)');
			}
		);
		
		$('#mainNav li.recipes a').hover(function() {
														
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_recipes_ro.png)');
				
			}, function() {
				
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_recipes.png)');
			}
		);
		
		$('#mainNav li.dietary a').hover(function() {
														
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_dietary_ro.png)');
				
			}, function() {
				
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_dietary.png)');
			}
		);
		
		$('#mainNav li.thai a').hover(function() {
														
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_thai_ro.png)');
				
			}, function() {
				
				$(this).parent().css('background-image', 'url(/public/thaikitchen/images/bkg_mainNav_thai.png)');
			}
		);
		
		setFontStyles();

	}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//SEARCH FUNCTIONALITY
/////////////////////////////////////////////////////////////////////////////////////////////////////////


	//hide the search box 
	$('#form').children().hide();
	$('#close').hide();
	
	//search box down on hover
	$('#search').hover(function() {
									
			$(this).animate({height: "85px"}, 350);
			$('#searchBackground').animate({height: "85px"}, 340, 
				
				function(){ 
				
				$('#form').children().fadeIn(150);
				$('#close').fadeIn(150);
				
			});
				
	});
	
	//close the search box
	$('#close').click(function() {
			
			$('#search').animate({height: "9px"}, 250);
			
			$('#close').fadeOut(50, 
				
				function(){ 
				
				$('#searchBackground').animate({height: "38px"}, 250);
			$('#form').children().fadeOut(110);
				
			});
			
	});
	
	
	
	//clear default values on search form
	(function($){
		$.fn.clearDefault = function(){
			return this.each(function(){
				var default_value = $(this).val();
				$(this).focus(function(){
					if ($(this).val() == default_value) {
						$(this).val("");
					}
				});
				$(this).blur(function(){
					if ($(this).val() == "") {
						$(this).val(default_value);
					}
				});
			});
		};
	})(jQuery);

	$('input.txtSearchC').clearDefault();
	
	
	
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//VARIOUS CYCLERS
/////////////////////////////////////////////////////////////////////////////////////////////////////////


//homepage recipes
	$('#cycler').cycle({ 
		fx:     'scrollHorz', 
		speed:  600, 
		next:   '#next', 
		prev:   '#prev', 
		timeout: 5000, 
		cleartypeNoBg: true,
		// callback fn to remove auto pager anchors
		pagerAnchorBuilder: function(idx, slide) { return ''; }
		
	});

//homepage heros images
	$('#cyclerHero').cycle({ 
		fx:     'fade', 
		speed:  500, 
		next:   '#next', 
		prev:   '#prev', 
		timeout: 5000, 
		cleartypeNoBg: true,
		cleartype:  1,
		// callback fn to remove auto pager anchors
		pagerAnchorBuilder: function(idx, slide) { return ''; }
		
	});
	
//product landing page products 
	$('#cyclerProducts').cycle({ 
		fx:     'scrollHorz', 
		speed:  600, 
		next:   '#next', 
		prev:   '#prev', 
		timeout: 5000, 
		cleartypeNoBg: true,
		// callback fn to remove auto pager anchors
		pagerAnchorBuilder: function(idx, slide) { return ''; }
		
	});


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//SORT RECIPES BY PRODUCT DROP DOWN
/////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('#productList').hide();

	$('#sort').hover(function() {		 
		 $('#productList').slideDown('fast');
	}, function() {
		$('#productList').slideUp('fast');
		 
	});
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//VOTING STARS
/////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('.star').hover(function(){
		$(this).fadeTo('fast', 0.5);
	}, function() {
		$(this).fadeTo('fast', 1);
	});




});


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//FONT REPLACEMENT - CALLED AFTER DOCUMENT READY - NOT A JQUERY DEPENDENCY
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function setFontStyles(){

  	Cufon.replace('#mainNav a', {hover: true});
	Cufon.replace('#cyclerNav span');
	Cufon.replace('#cycler .recipe span');
	Cufon.replace('#types span');
	Cufon.replace('#recipeOverview li span');
	Cufon.replace('#recipeUtilities', {hover: true});
	Cufon.replace('#recipeInfo h4');	


};

