(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:250,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 ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){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.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<h3>'+status+'</h3>');
  }
  $('.loading').fadeOut(750, function() {
		$('#tweet-bubble').append($(statusHTML.join('')).hide().fadeIn(750));
	});
}

function onBefore() {
	var theClass = $(this).attr('useclass');
	$('#feature').removeClass().addClass(theClass);
	$('#slides li').removeClass().addClass(theClass);
}

$(document).ready(function() {
						   
						   

	$('#prev-slide').fadeTo("normal",0.40);
	$('#next-slide').fadeTo("normal",0.40);
	$('.post .social-news').fadeTo('normal',0.50);
	
	$('.transparent_class').hover(function() {
		$(this).stop().fadeTo("normal",1);
	},function() {
		$(this).stop().fadeTo("normal",0.40);	
	});
	
	$('#index-tabs').tabs({ fxFade: true, fxSpeed: 'slow' });
	
	$('header #search *').click(function() {
		$('header div#search').css({backgroundPosition: '0 -39px'});								  
	}).blur(function() {
		$('header div#search').css({backgroundPosition: '0 0'});
	});
	
	$('#slides').cycle({ 
		fx:     'fade', 
		timeout: 0,
		speedIn: 750,
		speedOut: 250,
		before: onBefore,
		cleartypeNoBg: true
	 });
	
	$('#port-slides').cycle({ 
		fx:     'fade', 
		timeout: 5000,
		speed: 750,
		cleartypeNoBg: true
	 });
	
	$('#dir-slides').cycle({ 
		fx:     'fade', 
		timeout: 0,
		speedIn: 750,
		speedOut: 250
	 });
	
	$('#test-slides').cycle({ 
		fx:     'fade', 
		timeout: 0,
		speedIn: 750,
		speedOut: 250,
		before: onBefore1
	 });
	
	function onBefore1() {
		//get the height of the current slide
		var ht = $(this).height();
		//set the container's height to that of the current slide
		$(this).parent().animate({height: ht}, 250);
	}
	
	$('#prev-slide').click(function() {
		$('#slides').cycle('prev');
		return false;
	});
	
	$('#next-slide').click(function() {
		$('#slides').cycle('next');
		return false;
	});
	
	$('#legal-directories .back a').click(function() {
		$('#dir-slides').cycle('prev');
		return false;
	});
	
	$('#legal-directories .next a').click(function() {
		$('#dir-slides').cycle('next');
		return false;
	});
	
	$('#testimonials .back a').click(function() {
		$('#test-slides').cycle('prev');
		return false;
	});
	
	$('#testimonials .next a').click(function() {
		$('#test-slides').cycle('next');
		return false;
	});
	
	
	var username = 'ejustice';
    $.getScript('http://twitter.com/statuses/user_timeline/' + username + '.json?callback=twitterCallback2&count=1');
	
	$('.campaign-tabs .tab li').hoverIntent(function() {
		$(this).append('<div class="micro-cta"><h4>Learn More Today, call 1-877-357-8423 or <a href="http://www.ejustice.com/contact.html">contact us</a>.</h4></div>');
		$('.micro-cta').stop().fadeIn(500);
	   },function() {
		$('.micro-cta').stop().fadeOut(500).remove();	   
	});
	
	$('nav li').hover(function(){
		   $(this).children('ul').fadeIn(250);
	}, function() {
		   $(this).children('ul').css({display: 'none'});
	});
	
	$('.print a').click(function() {
		window.print();
	});
	
	$('.post').hover(function() {
		$('.post .social-news').stop().fadeTo('normal',1);
	},function() {
		$('.post .social-news').stop().fadeTo('normal',0.50);								
	});


	$('.accbutton').click(function() {
//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	$('.acccontent').slideUp('normal');
//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
	if($(this).next().is(':hidden') == true) {
//OPEN THE SLIDE
		$(this).next().slideDown('normal');
		}
		});
});
