/**
* 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);
				 
(function($){
	
	$.extend({
			 
		smoothAnchors : function(speed, easing, redirect){
				
			speed = speed || "fast";
			easing = easing || null;
			redirect = (redirect === true || redirect == null) ? true : false;
			
			$("a").each(function(i){
							
				var url = $(this).attr("href");
				
				if(url){
					if(url.indexOf("#") != -1 && url.indexOf("#") == 0){
		
						var aParts = url.split("#",2);
						var anchor = $("a[name='"+aParts[1]+"']");
						
						if(anchor){
																					
							$(this).click(function(){
												   
								if($(document).height()-anchor.offset().top >= $(window).height()
								 || anchor.offset().top > $(window).height()
								 || $(document).width()-anchor.offset().left >= $(window).width()
								 || anchor.offset().left > $(window).width()){
												   
									$('html, body').animate({
										scrollTop: anchor.offset().top,
										scrollLeft: anchor.offset().left
									}, speed, easing, function(){
										if(redirect){ 
											window.location = url 
										}
									});
								
								}
								
								return false;
																
							});
						}
					
					}
					
				}
				
			});
			
		}
	
	});
	
})(jQuery);

// Page Scripts 
function addHoverHide(linkHover) {
	var t;
	var durationTime = 300;
	
	//Start Rollover Function
    $(linkHover).hover(function() {
		$("ul.dropMenu").hide();
		$(linkHover).removeClass("hoverOnState");
		$(this).find("ul.dropMenu").addClass("active").addClass("current").fadeIn(200);
        clearTimeout(t);
        // custom function which creates drop shadows around layerId
		$(this).addClass("hoverOnState");
		
	
}, function() {
	
        t = setTimeout(function() {
					 $(".active").hide();
								$(linkHover).removeClass("hoverOnState");
								$(".active").hide();		

							}, durationTime);
		
		
    });
	
	//If you Roll over subNav Reset Primary Nav Timer and styles
	$("#primaryNavigation ul.dropMenu").hover(function() {
									
        clearTimeout(t);
		$(this).parent().find("#agencyHover").addClass("hoverOnState");
		
	
}, function() {
	     t = setTimeout(function() {
					 $("ul.dropMenu").hide();
								$(linkHover).removeClass("hoverOnState");
							}, durationTime);
		});

	
	
} 

function addiicHover(){ 
	  $(this).find("ul.dropMenu").addClass("active").addClass("hoverOnState").fadeIn(200);
	  $(this).addClass("hoverOnState");
  } 
	 
	function removeiicHover(){ 
	 $(this).find("ul.dropMenu").removeClass("active").fadeOut(50);
	  $(this).removeClass("hoverOnState");
	  }
	  

var iicHover = {     
	     interval: 20, 
	     sensitivity: 2,
		 over: addiicHover, 
		 out: removeiicHover,
		 timeout: 100
}

$(document).ready(function(){

 
$(".concealed").hide();
	$(".hoverElement").hover(
      function () {
			$(this).find("a").addClass("greyLink");
			$(this).find("h1,h2,h3,h4,h5,h6").addClass("hoverHeaderTag");
			$(this).find("h5 a").addClass("footerLink");
			$(this).find("p").addClass("hoverParagraph");
			$(this).find(".linkedInOff").removeClass("linkedInOff").addClass("linkedInOn");
			$(this).find(".facebookOff").removeClass("facebookOff").addClass("facebookOn");
			$(this).find(".twitterOff").removeClass("twitterOff").addClass("twitterOn");
			$(this).find("#iiBrainStorm").addClass("overState");
			$(this).addClass("overState");
      }, 
      function () {
			  $(this).find("a").removeClass("greyLink");
			  $(this).find("h1,h2,h3,h4,h5,h6").removeClass("hoverHeaderTag");
			   $(this).find("h5 a").removeClass("footerLink");
			   $(this).find("p").removeClass("hoverParagraph");
			   $(this).removeClass("overState");
			   $(this).find(".linkedInOn").removeClass("linkedInOn").addClass("linkedInOff");
			$(this).find(".facebookOn").removeClass("facebookOn").addClass("facebookOff");
			$(this).find(".twitterOn").removeClass("twitterOn").addClass("twitterOff");
			$(this).find("#iiBrainStorm").removeClass("overState");
        //$(this).find("a").removeClass("greyLink");
      }
    );
	
	
	$(".moreLink").click(
      function () {
		  $(".moreLink").hide();
		  $(".closeLink").show();
			$(".concealed").animate({ 
      "height": "toggle", "opacity": "toggle"

      }, 400 );
			$('html, body').animate({scrollTop:300}, '1300'); 
			 return false;
      });
	
	$(".closeLink").click(
      function () {
		  
			
		  $(".moreLink").show();
		  $(".closeLink").hide();
			$(".concealed").fadeOut(400);
			$('html, body').animate({scrollTop:0}, '1300'); 
			 return false;
      });
  
	
//Drop Down Menu - Agency

		  
	// addHoverHide("li.agencyHover");
	 $("li.agencyHover").hoverIntent(iicHover)

$.smoothAnchors(700, "swing", false);

});



