/**
* Gate-B Website
*
* The www.gateb.ch website is heavily using JavaScript
* for visual enjoyment, but the whole site degrades beautifully
* using the unobtrusive JavaScript philosophy.
*
* @author Roman Simecek
*
*/

OFFSET_Y = -30;
OFFSET_X = 10;
SELECTED_TEAM_MEMBER = false;

$(document).ready(function(){
  addTeamBehavior();
});

/**
 * Load and add behaviour for the team page
 */
function addTeamBehavior() {
  if($('div.people').length>0){
    // console.log('*** load team behavior ***');
    $('div.people a').each(function(){
      /*
      * gets the text for the popup form the alt-tag
      */
      var temp = $(this).children('img').attr('alt').split(',');
      var name = temp[0].split(' ');
      $('body').append('<div id="team-mouseover-'+name[0]+'" style="z-index:10000;background-color:#FFFFFF;display:none;position:absolute;padding:5px;width:150px;"><b>'+temp[0]+'</b><br />' + temp[1]+'</div>');

      $(this).mouseover(function(){
        $('#team-mouseover-'+name[0]).fadeIn(0);
        $().mousemove(function(e){
          $('#team-mouseover-'+name[0]).css('top', e.pageY+OFFSET_Y);
          $('#team-mouseover-'+name[0]).css('left', e.pageX+OFFSET_X);
        });
      });

      $(this).mouseout(function(){
        $('#team-mouseover-'+name[0]).fadeOut(0);
      });

      $(this).click(function(e){
        e.preventDefault();
        if(!$(this).children('img').hasClass('select')){
          $('div.people a img').each(function(){
            $(this).removeClass('select');
          });
          $('#description').html($(this).next('.description').html());
          $(this).children('img').addClass('select');
          $('div.people a img').each(function(){
            if($(this).hasClass('select')) {
              $(this).animate({opacity: 1.0}, 125);
            }else{
              $(this).animate({opacity: 0.1}, 125);
            }
          });
        }else{
          $(this).children('img').removeClass('select')
          $('div.people a img').each(function(){
            $(this).animate({opacity: 1.0}, 125);
          });
          $('#description').html('');
        }
      });
    });
  }
}