$(function() {

// Band hover effect
$(".hoverlight").css("opacity","0.0");

// ON MOUSE OVER
$(".hoverlight").hover(
  function () {
    // SET OPACITY TO 100%
    $(this).stop().animate({
      opacity: 1.0
    }, "slow");

    /*$(".band_main").stop().animate({
      opacity: 0.6
    }, "normal");*/

  },
  // ON MOUSE OUT
  function () {
    // SET OPACITY BACK
    $(this).stop().animate({
    opacity: 0.0
    }, "slow");

    /*$(".band_main").stop().animate({
    opacity:1.0 
    }, "normal");*/
  }
);

var band_map = [
  'tobias', 
  'dominik',
  'bjoern',
  'christopher',
  'michael',
  'ilona',
  'phil'
];

function show_profile(member) {
  // Band member click effect
  $("#" + member).click(function() {
    
    // Hide other band members
    $.each(band_map, function(id, member) {
      $("#" + member).hide();
    });

    // Show profile picture of selected band member
    $("#" + member + "_highlight").show().stop().animate({
      left: '200',
      opacity: 1.0
    }, 1400, "swing");

    $(".band_main").stop().animate({
      opacity:0.0 
    }, "slow");

    // Band history button
    $("#bandgeschichte").stop().animate({
      opacity:0.0 
    }, "slow");

     // Band history button
     $("#bandgeschichte_highlight").hide();

    $(".room1").show().stop().animate({
      opacity:1.0
    }, "slow");

   $(".button_next").show().stop().animate({
      opacity:1.0
    }, "slow");

    $(".button_back").show().stop().animate({
      opacity:1.0
    }, "slow");


    $("#member_info").scrollTop(0);

    $("#member_info").show().stop().animate({
        opacity: 0.8
    }, 1400, "swing");

    show_description(member);
  });
}


function hide_profile() {

    // Hide band members
    $.each(band_map, function(id, member) {
      $("#" + member).show();
      $("#" + member + "_highlight").animate({
      opacity:0.0
      }, "slow", function() { $(this).hide(); });
    });

    $(".band_main").stop().animate({
      opacity:1.0 
    }, "slow");

    // Band history button
    $("#bandgeschichte").stop().animate({
      opacity:1.0 
    }, "slow");

   // Band history button
   $("#bandgeschichte_highlight").show();

    $(".room1").stop().animate({
      opacity:0.0
    }, "slow", function() { $(this).hide(); });

   $(".button_next").stop().animate({
      opacity:0.0
    }, "slow");

    $(".button_back").stop().animate({
      opacity:0.0
    }, "slow");

    $("#member_info").stop().animate({
        opacity: 0.0
    }, "fast", "swing", function() { $(this).hide(); });

}

function show_description(member) {
  $("#member_info").animate({
      scrollTop: 0
  },150, "swing");
  var infotext = "content/band/infos/info_" + member + ".mkdn";
  $.ajax({
      url: infotext,
      cache: false,
      success: function(text){
        var converter = new Attacklab.showdown.converter();
        var html = converter.makeHtml(text);
        $("#member_info").html(html);
      }
  });
}

function scroll_out(member) {
    $("#" + member + "_highlight").animate({
      left: '0',
      opacity: 0.0
    }, 500, "swing", function() { $(this).hide(); });
}

function scroll_in(member) {
  $("#" + member + "_highlight").css("left","400px").show().stop().animate({
      left: '200',
      opacity: 1.0
    }, 500, "swing");
    show_description(member);
}

function swap_member(id, next_id) {
  var current_member = band_map[id];
  var next_member = band_map[next_id];
  scroll_out(current_member);
  scroll_in(next_member);
}

function next_profile() {
   $.each(band_map, function(id, member) {
     if ( $("#" + member + "_highlight").is(":visible") ) {
       var next_id = (id + 1) % band_map.length;
       swap_member(id, next_id);
       return false;
     }
  });
}

$.each(band_map, function(id, member) { 
  show_profile(member);
});

$(".button_next").click(function() {
  next_profile();
});

$(".button_back").click(function() {
  hide_profile();
});


/*
 * Replaced with tinybox
 * $(".history").click(function() {
  $(".bandbox").show().stop().animate({
    opacity: 1.0
  }, 1400, "swing");
});*/


});

