
// Site level additions.
$(document).ready(function() {
   newWindowClass();
   voidHrefAnchors();
   manageCustomNavItem();
   trackAddThis();
});

/**
 * Opens link in new window.
**/
function newWindowClass() {
   $('a.new-window').click(function() {
      window.open(this.href);
      return false;
   });
}

/**
 * Prevents anchor tags with href="#" from displaying the #.
**/
function voidHrefAnchors() {
   $('a').each(function(el) {
      if ($(this).attr('href') == '#') {
         $(this).click(function() {
            void(0);
            return false;
         });
      }
   });
}
function manageCustomNavItem() {
   //This section is for setting the on setting for the page you are on in the Joe Montana navigation	
   var urlCurrent = window.location.href;		
   
   if(urlCurrent.indexOf("joe-montana") > -1 && urlCurrent.indexOf("press-room") < 1) {				
      $("#joemontana").attr('src', '/assets/images/nav/joe_montana_on.jpg');
   } else {						
      $("#joemontana").hover(
         function(){ $(this).attr('src', '/assets/images/nav/joe_montana_on.jpg'); }
         , 
         function(){ $(this).attr('src', '/assets/images/nav/joe_montana_page.jpg'); } 
      );		
   }
}

// Event attached to the parent of the add this button, whcih has its own events. 
function trackAddThis(){
   $('.addThisBtn').click(function(){
      pageTracker._trackEvent('add this', 'clicks');  // google tracking event.
      callDartTracking();  // Additional tracking, inline iframe w/image source. Poor choice.
   });
}

// Injects iframe into dom ondemand so the image px tracking can be sent. 
function callDartTracking() {
   var tag_url="http://fls.doublclick.net/activity;src=2414590;type=signu528;cat=bigga537;ord="+Math.floor(Math.random()*999999) + ";num="+Math.floor(Math.random()*999999);
   if(document.getElementById("DCLK_FLDiv")){
      var flDiv=document.getElementById("DCLK_FLDiv");
   } else{
      var flDiv=document.body.appendChild(document.createElement("div"));
      flDiv.id = "DCLK_FLDiv";
      flDiv.style.display = "none";
   }
   
   var DCLK_FLIframe = document.createElement("iframe");
   DCLK_FLIframe.id = "DCLK_FLIframe_" + Math.floor(Math.random()*999999);
   DCLK_FLIframe.src = tag_url;
   flDiv.appendChild(DCLK_FLIframe);
   setTimeout(function(){return true;}, 1000);
}