/* 
 * N.B Secondary link logging is taken care of by "Landing-page-secondary-links.js"
 * These work by
 * 1. Setting a Timeout to follow the link
 * 2. Working out what string is appropriate for ns_onclick
 * 3. Running ns_onclick
 */ 
$(function() {
 // 1 - slideshow links
 //$('#slideshow a.button').click(function() {
 $('#slideshow li:not(.takeover) a.primary-promo-orange-button').click(function() {

   
   
   if($(this).attr('onclick') == 'undefined' || $(this).attr('onclick') == null) {
   //  setTimeout('window.location = "' + $(this).attr('href') + '"',100); //Do first incase the tracking fails
   }
      
   var sTrackTitle = jQuery.trim($(this).parent().parent().find('h2 span.main').text());
   
   if(sTrackTitle == '') {
     var sTrackTitle = jQuery.trim($(this).parent().parent().find('h2').text());
   }
   
   
   sTrackTitle = LinkTrackClean(sTrackTitle);
   sTrackTitle = sLandingPage + '.main_banner.' + sTrackTitle + '.link';
      //console.log(sTrackTitle);

   if(typeof ns_onclick == 'function') {

     ns_onclick(this,'',sTrackTitle,'clickin');
   }         
   return false; 
 }); //End of Slideshow Links
 
 
 //2 - Linkbox Links
 $('#linkboxes ul li a').click(function() {
    if($(this).attr('onclick') != 'undefined' && $(this).attr('onclick') != null) {
    //  setTimeout('window.location = "' + $(this).attr('href') + '"',100); //Do first incase the tracking fails
    }
    //return false;


    var sTrackLinkTitle = $(this).text();
    sTrackLinkTitle = LinkTrackClean(sTrackLinkTitle);

    
    var sLinkBoxTitle = $(this).parent().parent().parent().parent().find('h2').text();    
    sLinkBoxTitle = LinkTrackClean(sLinkBoxTitle);
    
    var sTrackTitle = sLandingPage + '.linkbox_' + sLinkBoxTitle + '.' + sTrackLinkTitle + '.link';
        
     //alert('ns onclick exists');       
    if(typeof ns_onclick == 'function') {
      ns_onclick(this,'',sTrackTitle,'clickin');
    }
    return false;
 }); //end of Linkbox Links
 
 //3. Right Hand Side Links
 $('#right-column .panel-wide a').click(function() {
   //Only do this set timeout IF these links do not open in a new window.
  
  var sTrackLinkTitle = $(this).text();
  sTrackLinkTitle = LinkTrackClean(sTrackLinkTitle);
  
  var sPanelTitle = $(this).parent().parent().parent().parent().find('h2').text();    
  sPanelTitle = LinkTrackClean(sPanelTitle);
 
  var sTrackTitle = sLandingPage + '.' + sPanelTitle + '.' + sTrackLinkTitle + '.link';
  //console.log(sTrackTitle);

  if(typeof ns_onclick == 'function') {
    ns_onclick(this,'',sTrackTitle,'clickin');
  }    
  
  return false;
 });//End of Right Hand Side Links

    

   
});
