$(document).ready(function(){
  // Tabs
  if ($('.tabs').length > 0) {
    $('.tabs').tabs({ fx: { opacity: 'toggle' } });
  }
  
  $(".tabs li a").click(function () { $(this).blur(); });
  // Tables extra styling
  if ($('.tableData').length > 0) {
    $(".tableData tr:even td").css("background-color","#e5e5e5");
    $(".tableData th:last").css("border-right","none");
  }
  
  if ($('#PersonalPortfolio').length > 0) {
    $("#PersonalPortfolio tr:odd td , #PersonalPortfolio tr:odd th").css("background-color","#e5e5e5");
    $("#PersonalPortfolio tr:even td").css("background-color","transparent");
  }
  
  $(".msgError a , .msgAnnounce a , .msgConfirm a").click(function(){$(this).parent("div").hide();})
  
  // Adds target _blank to links with class "targetBlank"
  if ($('.targetBlank').length > 0) {
    $("a.targetBlank").attr('target','_blank');
  }
  // Navigation expand-collapse
  $("#LeftNav ul li.on a.header , #LeftNav ul li.off a.header").click(function(){
         var $this = $(this).parents("li");
       
       if( $this.is('.on') ) {
               $this.removeClass('on');
               $this.addClass('off');
       }
       if( $this.is('.off') ) {
               $("#LeftNav ul li").removeClass('on');
               $("#LeftNav ul li").addClass('off');
               $this.removeClass('off');
               $this.addClass('on');
               $this.blur();
       }
     });
  
  // Portfolio tables
  if ($('#PortfolioSummary').length > 0) {
      $("td:nth-child(even)").css("background-color","#e5e5e5");
  }
  if ($('.portfolioTable').length > 0) {
      $(".portfolioTable tr:nth-child(even) td").css("background-color","#f4f4f4");
  }
   
  /*
  if ($('.portfolioTable').length > 0) {
	var $this = $(".portfolioTable tr:last");
    $($this).prev().find("td").css("border-bottom","solid 1px #D8D8D8");
	$($this).prev().find("td:eq(6),td:eq(7)").css("border-bottom","none");
	$($this).find("td").css("border-bottom","solid 1px #D8D8D8");
  }
  */
  
  // Join page Free service confirmation
  $("#optin_3rd_email").click(function(){
    if ($("#optin_3rd_email:checked").val() == null) {
	  $(this).attr('checked', true);  
	  var answer = confirm('Do you really want to miss out on this special information including share tips, free research, newsletters and other special offers and information? If you do wish to receive it please click OK, if not please click CANCEL.');
	  if(answer){
	  $(this).attr('checked', true);
      } else {$(this).attr('checked', false);}
    }
  });
  
});