/* --------------------------------------------------------------------
// Author: Patrick Forringer ( patrick@forringer.com )
// File info: JS for H&M site
// Ver: 0.1
// Last modified: 11-16-09
//
*/
$().ready(function(){
	
	// --------------------------------------------------------
	// Hover stuff for subpages in top navigation
	//

	$('.main-nav li:has(ul)').each(function(){
	
		$navul = $(this).find('ul');
		
		// get distance
		var dist_to = $navul.height();
		
		var rate = 40; // dist per 100 ms
		
		// calculate speed for hover		
		var ddspeed = ( dist_to/rate ) * 100 ;
		ddspeed = ( ddspeed > 400 ) ? 400 : ddspeed;
		
		$.data( this , 'nav_info', { dist: dist_to , speed: ddspeed, ptop: $navul.css('padding-top'), pbot: $navul.css('padding-bottom') } );
		//var dist = 
		$navul.height(0);
			
	}).hover(function(){
	
		$navul = $(this).find('ul');
		
		$(this).toggleClass('hov');
			
		nv_inf = $.data( this , 'nav_info');
		
		// Animate!
		$navul.stop( true, true ).animate({ height: nv_inf.dist, display: 'block', paddingTop: nv_inf.ptop, paddingBottom: nv_inf.pbot }, nv_inf.speed, 'swing' );
		
	},function(){
		
		nv_inf = $.data( this , 'nav_info');
		
		// Animate!
		$navul.stop( true ).animate({ height: 0, paddingTop: 0, paddingBottom: 0 }, nv_inf.speed, 'swing', function(){
			$(this).hide();
			$(this).parent('li').toggleClass('hov');
		});
		
	});
		
	// --------------------------------------------------------
	//  Search bar text
	//	
	var autofillop = {
		value: 'search our site',
		toValue: '',
		defaultTextColor: '#777',
		activeTextColor: '#222'
	}
	
	// autofill add url form
	$('#s').autofill(autofillop);
	
		
	// --------------------------------------------------------
	// create fav click
	//
	
	$('.fav').fav({name:'Woodlake Assembly of God'});
	
	
	// --------------------------------------------------------
	// events popup
	//
	
	var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over: callink_hover, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: callink_leave // function = onMouseOut callback (REQUIRED)    
	};
	
	function callink_hover(){
		var $popup = $(this).find('> span');
		
		if( $popup.find('div.event-content-break').length ){
			//alert('has');
			$popup.slideDown();
		}
	}
	
	function callink_leave(){
		var $popup = $(this).find('> span');
		$popup.slideUp();
	}

	$('span.calnk a').hoverIntent(config);
	
	$('span.calnk a span').hide();
		
});