Twotwenty = {
  bubbleTimer: null,
  bubbleIndex: null,

  rotate: function() {
    if(Twotwenty.bubbleIndex == null) {
      Twotwenty.bubbles.eq(0).fadeIn(1000);
      Twotwenty.bubbleIndex = 0;
    } else {
      Twotwenty.bubbles.eq(Twotwenty.bubbleIndex).fadeOut(1000);
      Twotwenty.bubbleIndex += 1;
      if(Twotwenty.bubbleIndex >= Twotwenty.bubbles.length) {
        Twotwenty.bubbleIndex = 0;
      }
      Twotwenty.bubbles.eq(Twotwenty.bubbleIndex).fadeIn(1000);
    }
  },

  start: function() {
    Twotwenty.bubbles = $('.aux-info li')

    Twotwenty.bubbles.mouseover(function() {
      Twotwenty.bubbles.stop(true, true).fadeOut();
      $(this).stop(true, true).show();
      clearInterval(Twotwenty.bubbleTimer)
    });
    
    Twotwenty.bubbles.mouseout(function() {
      Twotwenty.bubbleIndex = $(this).index(); 
      Twotwenty.bubbleTimer = setInterval(Twotwenty.rotate, 5000);
    });
    
    Twotwenty.bubbleTimer = setInterval(Twotwenty.rotate, 5000);
  }
}
  
$(document).ready(function() {
  $('.aux-info li').hide();
  Twotwenty.start();

  $('#profile-cards ul.buttons>li a').click(function(e) {
    e.preventDefault();
    $('#profile-cards ul.buttons>li').removeClass('current');
    $(this).parents('li').addClass('current');

    var guy = this.href.split('#').pop();
    $('#profile-cards ul.members>li').hide();
    $('#profile-cards ul.members>li.' + guy).show();
    $('#local-portrait-wrapper')[0].className =  'web-guy-' + guy.substring('member-'.length);
    return false;
  });

  cookies = document.cookie.split(';');
  hideoverlay = false;
  for(i = 0; i < cookies.length; i++) {
    if(cookies[i].substring(0, " hideoverlay".length) == ' hideoverlay') {// && cookies[i].substring("hideoverlay=".length + 1) == 'true') {
      hideoverlay = true;
    }
  }
  
  if($.browser.msie && $.browser.version.match(/6/) && !hideoverlay) {
    $('div#wrapper').append('<div class="overlay">&nbsp;</div><div class="message"><h1>You are using an old browser</h1><p>It looks like you are using Internet Explorer 6, which is a very old browser that is no longer supported (even by Microsoft, Google or YouTube). You can upgrade your browser <a href="http://www.microsoft.com/ie">here</a> or send us an email <a href="mailto:fixmybrowser@twotwenty.com.au">fixmybrowser@twotwenty.com.au</a> and we can come and do it for you!</p><p><a href="#" style="font-size: 14px" id="close">I understand that this website ' + "won't" + ' look right, but let me in</a></p></div>');
    $('div.overlay').css('opacity', .8);
    $('a#close').click(function() {
      $('div.overlay').hide();
      $('div.message').hide();
      document.cookie = "hideoverlay=true; expires=Fir, 1 Jan 2010 00:00:00 UTC; path=/";
      return false;
    });
  }

  var latlng = new google.maps.LatLng(-31.9371, 115.8427);
  var center = new google.maps.LatLng(-31.9360, 115.8427);
  var myOptions = {
    zoom: 16,
    center: center,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("google-map"), myOptions);
  var twotwentyMarker = new google.maps.Marker({
    position: latlng,
    map: map
  });
  var infowindow = new google.maps.InfoWindow({
    content: "<h2 style=\"text-align: center; font-size: 16px; font-weight: bold; color:#53C4C4; margin-bottom: 0;\">Twotwenty HQ</h2><p style=\"text-align: center;\">220 Carr Place, Leederville WA</p>",
  });
  infowindow.open(map, twotwentyMarker);
});

$(window).load(function() {
  // Pre load headshots
  var alex_headshot = new Image();
  alex_headshot.src = '/images/local_alex.jpg';
  var gary_headshot = new Image();
  gary_headshot.src = '/images/local_gary.jpg';
  var myles_headshot = new Image();
  myles_headshot.src = '/images/local_myles.jpg';
  var pascal_headshot = new Image();
  pascal_headshot.src = '/images/local_pascal.jpg';
});

