$(document).ready(function() {
      // header navigation
      $("#navigation li").hover(function() {
            $(this).find("li").show();
            $(this).css('color','#FFF');
            $(this).children("a").css('color','#FFF');
            
            if($(this).parent().attr("class") != "sub-menu" && $(this).("a").html() == "Blog"){
                //if sub-nav page is active, hide while hovering others
                if($(this).html() != $(".current_page_parent").html()) $(".current_page_parent").find("li").hide();
                if($(this).children("a").html() != $(".current-post-parent").parent().parent().children("a").html()) $(".current-post-parent").parent().hide();
            }
        } , function() {
            if($(this).children("a").html() != $(".current-post-parent").parent().parent().children("a").html()){
                $(this).find("li").hide();
                $(this).css('color','#C1C1C1');
                $(this).children("a").css('color','#C1C1C1');
            }
            
            //if sub-nav page is active, show the correct nav
            $(".current_page_parent").find("li").show();
            $(".current-post-parent").parent().show();
        });
        
        //if sub-nav page is active, show the correct nav
        $(".current_page_parent").find("ul").show();
        
        $(".current-post-parent").parent().parent().children("a").css('color','#FFF');
        $(".current-post-parent").parent().show();
        
      $("div.home_news_item").hover(function() {
            $(this).css('background-image','_img/home_news_item_bg_hover.png');
        } , function() {
            $(this).css('background-image','_img/home_news_item_bg.png');
        });

      // Image Preloader
      preload([
        'wp-content/themes/CLM/_img/home_news_item_bg_hover.png',
        'wp-content/themes/CLM/_img/blue_arrow.png'
      ]);
      
      // Tooltips
      $(".tooltip").qtip({ 
          style: { 
              name: 'dark',
              tip: 'bottomMiddle'
          },
          position: {
              corner: {
                 target: 'topMiddle',
                 tooltip: 'bottomMiddle'
              }
          }
      })
        
      //### Functions ###
      function preload(arrayOfImages) {
          $(arrayOfImages).each(function(){
              (new Image()).src = this;
          });
      }
});
