var hpCycle;

$(function() { 
		
	$('html').removeClass('no-js');


// Global Navigation Functions
				
	$('.nav-item').hoverIntent({ // Main Nav ROll Overs
		sensitivity: 1,
		timeout: 200,
		over: function() {		
			$(this).stop().animate({backgroundPosition:'0 -5px', time:1500}); // Show Nav Tab
			
			if($(this).hasClass('dropdown')) {										
				$(this).find('.subnav-holder').height($(this).find('.dropdown-nav').outerHeight()); // Expand Holder				
				$(this).find('.dropdown-nav').delay(100).animate({top:'0px', duration:900}); // Slide Down Nav
			}
			
		},
		out: function() {			
			if(!$(this).hasClass('active')) $(this).stop().animate({backgroundPosition:'0 100px', time:2}); // Hide Nav Tab	
			 		
			if($(this).hasClass('dropdown')) {
				$(this).find('.dropdown-nav').stop().animate({top:'-500px'}, {duration:500, complete:function() { $(this).parent('.subnav-holder').height('0px'); } }); // Slide Nav Up and Close Holder
			}	
		}
		
	});
	
	$('.dropdown-nav li, .inpage-nav li').hover( // Show and Hide Arrow BG
		function() {
			if(!$(this).hasClass('active')) {
				var arrow = $(this).find('.arrow');
				arrow.css({display:'block'});
				if($.support.opacity) arrow.animate({opacity:1}, {duration:400}); 
			}
		},
		function() { 
			if(!$(this).hasClass('active')) {			
				var arrow = $(this).find('.arrow');				
				if($.support.opacity) arrow.stop().animate({display:'none', opacity:0}, {duration:400}); 				
				else arrow.hide();
			}
		}
	);

// - END Global Nav	


// Home Page Feature
	if($('.hp-feature-nav').length > 0) {
		$('.hp-feature-nav a').click(hpFeature).bind('cycle', hpFeature);

	// Auto-cycle
		hpCycle = setTimeout(hpCycleFunc, 6000);
	}
// - END Home Page Feature
	
// Home Page Touts
	if($('#touts').length > 0) {
		$('.tout').hover(
			function() { $(this).find('img').stop().animate({bottom:'35px'}, {duration:300, easing:'easeOutCubic'}) },
			function() { $(this).find('img').stop().animate({bottom:'25px'}, {duration:200}) }
		);
	}
// - END Home Page Touts	


// Taco Club Page
	$('.taco-club-tout').hover(
		function() { var over = $(this).find('.rollover'), bottom=parseInt(over.data('bottomPos'))+5; over.stop().animate({bottom:bottom+10}, {duration:300, easing:'easeOutCubic'}) },
		function() { var over = $(this).find('.rollover'), bottom=parseInt(over.data('bottomPos')); over.stop().animate({bottom:bottom}, {duration:200}) }
	).find('.rollover').each(function() { 
		$(this).data('bottomPos', $(this).css('bottom').replace('px', ''))
	});
	
	$('#blu').hover(
		function() { $(this).stop(true).animate({top:-25}, {duration:800, easing:'easeInOutBack' });
		/*
			$('#bluHolder').rotate({ animateTo:10, dudration:300, easing: $.easing.easeOutExpo, callback:
					function() { $('#bluHolder').rotate({ animateTo:-14, duration:800, easing: $.easing.easeInOutQuint, callback:function() {							
							$('#bluHolder').rotate({ animateTo:0, duration:400, easing:$.easing.easeInOutExpo })							
						}					
					}) }
				})
		*/ 
			},
		function() { $(this).animate({top:0}, {duration:800, easing:'easeOutBack' }); }
	);
	
// - END Taco Club Page	

// Recipes Search Form 
	
	$('.recipeSearchField').focus(function() { 
		if($(this).val() == $(this).attr('placeholder')) $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val($(this).attr('placeholder'));
	});
	
	$('#recipe-search').submit(function() {
		$('.recipeSearchField').each(function() {
			if($(this).val() == $(this).attr('placeholder')) $(this).val(''); 
		});
	});
	
// - END Recipes Search Form

// Login Close
	/*
	$('#signin-form')
	//.bind('show', function() { $(document).bind('keydown', escSignin); })
	//.bind('hide', function() { $(document).unbind('keydown', escSignin); })
	.find('.close a').click(function(e) {
		e.preventDefault();
		$.colorbox.close();
	});
	*/
// - END Login Close	
	
});

function escSignin(e) {
	var code = (e.keyCode ? e.keyCode : e.which);
	if (code === 27) { $('#signin-form').find('.close a').click(); /*fadeOut(300).trigger('hide');*/ }
}

function hpFeature(e) {
		
	e.preventDefault();
	
	if(e.type == 'click') clearTimeout(hpCycle);	
	if($(this).hasClass('active')) return;
	
	var gap = Math.abs($('.hp-feature-nav .active').attr('data-rel') - $(this).attr('data-rel'));
	
	$('.hp-feature-nav .active').removeClass('active');
	$(this).addClass('active');
	
	$('#hp-feature-container').stop().animate({left:$(this).attr('data-rel')*(-1000)}, {duration:800, easing:'easeOutCubic'} );	
}

function hpCycleFunc() {
	clearTimeout(hpCycle);
	
	var next = $('.hp-feature-nav li:has(a.active)').is(':last-child') ? $('.hp-feature-nav li:first-child a') : $('.hp-feature-nav li:has(a.active)').next().find('a');
	next.trigger('cycle');
	hpCycle = setTimeout(hpCycleFunc, 6000);	
}



//Popup function

function popup(url) {
	newwindow=window.open(url,'name','height=430,width=570,scrollbars=no, resizable=0');
	if (window.focus) {newwindow.focus()}
	return false;
}


// END Popup function


