$(document).ready(function(){ 
	
  $(".flyout").each(function(e){
		var $this = $(this);
		$this.find(".column:last").addClass("last-column");
		$this.find("object,iframe").attr({width:"300",height:"196"});
		$this.append("<img class='arrow' src='/_img/arrow.png' width='11' height='28'/>");
  });
  
  var timer = setTimeout(hideActiveFlyout,500);

  $("#nav").find("li").bind('mouseenter touchstart',function(e){
	   clearTimeout(timer);
	   var $this = $(this),
		   id = $this.attr("id"),
		   pos = $this.position(),
		   eurl = $this.find("a").attr("href"),
		   flyout = $(".flyout[id=fl_"+id+"]"); 
   	   if(e.type === 'touchstart'){
			$this.unbind('mouseenter');
		}
	   $(".flyout").each(function(e){
			$(this).hide();
			$(this).unbind('mouseleave touchend');
	   });
	   
	   flyout.find(".arrow").css({top:pos.top - 70});
	   flyout.find(".seeall").attr("href",eurl);
	   flyout.css({display:'block'}).show();  
	   flyout.bind({
		   mouseover:function(){ 
			  clearTimeout(timer);
		   },
		   touchstart:function(){
			  clearTimeout(timer);
		   }, 
		   mouseleave: function(){
			  timer = setTimeout(hideActiveFlyout,500);
		   }
	   }); 
  }).bind('mouseleave touchend',function(e){
	  if(e.type !== 'touchend'){ 
	  	timer = setTimeout(hideActiveFlyout,500);
	  }
  });


	function hideActiveFlyout(){
		$(".flyout:visible").hide();
		clearTimeout(timer);
	} 
	if($("html").hasClass("ie8")){
		$("#fl_nav_connect").find(">ul>li:last").addClass("last");
	}
	
	$("#fl_nav_events").find(".imgwrap").each(function(){
      var imgurl = $(this).find("img").attr("src");
      if( imgurl === "" || imgurl === "http://lifecenter.monkpreview.com/mediafiles/default-event-image.jpg"){
          $(this).find("img").attr("src","/mediafiles/default-event-image.jpg");
          $(this).find("img").css({"left":"0px"});
          $(this).find("img").css({"margin-left":"0px"});
          $(this).find("img").css({"width":"180px"});
          $(this).find("img").css({"height":"110px"});
      }
  });

});

