$(document).ready(function(){
		   
  // Open external links in new tab/window
  $("a[href*='http://']:not([href*='"+location.hostname+"'])").click(function(){
    this.target = "_blank";
  });
    
  // Return inputs to default value on blur.
  $('input[alt]').focus(function(){
    if ($(this).attr("value") === $(this).attr("defaultValue")) {
      $(this).attr("value", "");
    }
  }).blur(function(){
    if ($(this).attr("value") === "") {
     $(this).attr("value", $(this).attr("defaultValue"));
    }
  });

  // Navigation rollovers
  $('#sub_nav li .popup_nav').css({opacity:0, paddingTop:20});
  $('#sub_nav li').hover(function(){
    $(this).children('.popup_nav').show().stop().animate({opacity:1, paddingTop:30}, 'fast');
  }, function(){
    $(this).children('.popup_nav').stop().animate({opacity:0, paddingTop:20}, 'fast', function(){$(this).hide();});
  });

  // Home BG rotator
  if($('#home-bg li:last').length > 0){setInterval('rotate_home_bg()', 5000);}

  // Team profiles navigation
  $('body.team #sections').prepend('<div class="team-links">Investement Team: <ul></ul></div>');
  var links = [];
  $('body.team div.section.first h1').each(function(i,e){
    var name = $(e).text();
    var id = name.toLowerCase().replace(/[^a-z]/, '-');
    console.log(id);
    $(e).attr('id', id);
    if(id !== 'learn-more'){links.push('<li><a href="#'+id+'">'+name+'</a></li>');}
  });
  $('.team-links ul').append(links.join(' | '));

  // Discretionary Managed Service Slides
  $('.international div.block').slice(1, -1).each(function(){$(this).addClass('slide')})
  $('.international div.block.slide').first().before('<div id="slide-container"><div id="slider">');
  $('.international div#slider').append($('.international .block.slide'));
  $('.international div.block.slide').each(function(i, e){
    $(e).append('<div class="prevnext">')
    if(i>0){$('.prevnext', e).append('<a class="prev">Go to the Previous Step</a>');}
    if(i<2){$('.prevnext', e).append('<a class="next">Go to the Next Step</a>');}
  });
  $('.international .slide a.next').click(function(){
    var slider = $('.international #slider');
    var currentMargin = parseInt(slider.css('marginLeft'));
    slider.animate({marginLeft:currentMargin-960});
  })
  $('.international .slide a.prev').click(function(){
    var slider = $('.international #slider');
    var currentMargin = parseInt(slider.css('marginLeft'));
    slider.animate({marginLeft:currentMargin+960});
  })
});

var dmsSlide = function(num){
  var margin = -1 * ( (num-1)*960 );
  $('.international #slider').animate({marginLeft:margin});
  return false;
};

var rotate_home_bg = function(){
 $('#home-bg li:last').fadeOut('slow', function(){
    $(this).parent().prepend($(this))
    $(this).show();
  });
};

