// remap jQuery to $
(function($){})(window.jQuery);


/* trigger when page is ready */
$(document).ready(function (){

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
   

	$('nav.primary ul li').hoverIntent(  
	    function () {  
	        //show its submenu  
	        $('ul', this).show();  
	
	    },   
	    function () {  
	        //hide its submenu  
	        $('ul', this).fadeOut(200);           
	    }  
	);  



	$("*:contains('&')", document.body)
        .contents()
        .each(
            function() {
                if( this.nodeType == 3 ) {
                    $(this)
                        .replaceWith( this
                            .nodeValue
                            .replace( /&/g, "<span class='amp'>&</span>" )
                        );
                }
            }
        );
	

	$("#featured").zAccordion({ 
		easing: "easeInOutCubic",
		timeout: 7500,
		speed: 1000,
		open: function() {
			var currentSlide = $('#featured li.slide-open').attr('id'); 
			$('.slideCaptions').find('div').fadeOut();
			$('.slideCaptions').find('.'+currentSlide+'').fadeIn();
			$('#featured li.slide-open').find('.overlay').fadeOut();
		},
		close: function() {
			var currentSlide = $('#featured li.slide-open').attr('id'); 
			$('#featured li.slide-closed').find('.overlay').fadeIn();
		},
		afterBuild: function () {
			setTimeout(function(){  
				
				$('.slideCaptions').find('div.open').fadeIn(200);
				$('.slideCaptions').find('.intro').fadeIn(700).delay(4000).fadeOut(700);
				$('.slideCaptions .intro').find('span:eq(0)').delay(500).fadeIn(700).delay(3500).fadeOut(700);
				$('.slideCaptions .intro').find('span:eq(1)').delay(1000).fadeIn(700).delay(3000).fadeOut(700);
				$('.slideCaptions .intro').find('span:eq(2)').delay(1500).fadeIn(700).delay(2500).fadeOut(700);
				$('.slideCaptions .intro').find('span:eq(3)').delay(2000).fadeIn(700).delay(2000).fadeOut(700);
				var currentSlide = $('#featured li.slide-open').attr('id');
				
				$('.slideCaptions').find('.'+currentSlide+'').delay(5500).fadeIn();
				$('#featured li.slide-open').find('.overlay').delay(5500).fadeOut();
				$('.slideCaptions').find('div.open').delay(5500).fadeOut();
			}, 500);
			

		},
		slideWidth: 415,
		width: 600,
		height: 400
	});


	
	$('ul.tombstones li:even').addClass('even');

	$('ul.tombstones').masonry({
		itemSelector: 'li'
	});
	
	$("header nav ul li a.main").lettering();
	
	
	$('div.bridgeLists ul li').fadeTo(0, 0);
	
	$('div.bridgeLists ul:first li').each(function(index) {
	    $(this).delay(400*index).animate({
	    	top: '15px',
	    	opacity: 1
	    }, 300);
	});
	
	$('nav.bridgeLists ul li a').click(function(){
		var thisBridgeList = $(this).attr('class');
		//alert(''+thisBridgeList+'');
		$('nav.bridgeLists ul li').removeClass('active');
		$(this).parent().addClass('active');
		
		
		$('div.bridgeLists ul li').fadeTo(0, 0);
		$('div.bridgeLists ul li').css('top', '0');		
	    
		$('div.bridgeLists ul.'+thisBridgeList+' li').each(function(index) {
		    $(this).delay(400*index).animate({
		    	top: '15px',
		    	opacity: 1
		    }, 300);
		});
		$('table tr.active').removeClass('active');
		
		$('table tr#'+thisBridgeList+'').addClass('active');
		
		return false; 
	});
	
	
	$('.homeNewsNav a').click(function(){
		var homeNewsToggle = $(this).parent().attr('class');
		
		$('a.more').attr('href','');
		if (homeNewsToggle == 'news') {
			$('a.more').attr('href','news/index.php');
		} else {
			$('a.more').attr('href','about/representative-transactions.php');
		}
		
		
		$('.homeNewsNav a').removeClass('active');
		$(this).addClass('active');
		
		//alert(''+homeNewsToggle+'')
		$('.newsTeaser table').hide();
		$('.newsTeaser table.'+homeNewsToggle+'').show();
		
		return false; 
	
	});

	
	


});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/

