
var _hex_menu_hover_map = new Object();

$(function(){

  $('#hexmap area').hover(function(){
    if(_hex_menu_hover_map['00'] === true) hide_all_hex_menu_animation ();
    var key = $(this).attr('accesskey');
    clearTimeout(_hex_menu_hover_map[key]);
    $('#hex-menu-'+key).fadeIn();
		//.css('visibility','visible');
  },function(){
    var key = $(this).attr('accesskey');
    //_hex_menu_hover_map[key] = setTimeout("$('#hex-menu-"+key+"').css('visibility','hidden');",100);
		_hex_menu_hover_map[key] = setTimeout("$('#hex-menu-"+key+"').hide();",100);
  });

  $('.hex-menu').hover(function(){
    var key = $(this).attr('id').split('-')[2];
    clearTimeout(_hex_menu_hover_map[key]);
  },function(){
    var key = $(this).attr('id').split('-')[2];
    //_hex_menu_hover_map[key] = setTimeout("$('#hex-menu-"+key+"').css('visibility','hidden');",100);
		_hex_menu_hover_map[key] = setTimeout("$('#hex-menu-"+key+"').hide();",100);
  });
	
	//return;
	
  if( $('body.home').length && window.location.hash != '#home' ) {
    $('#home-intro').show();
    $('#page').hide();
    setTimeout('intro_animation_01()',1000);
  }

});

function intro_animation_01() {
  $('#hi-cs').fadeIn(1500,function(){
    $('#hi-isnow').fadeIn(1500,function(){
      setTimeout('intro_animation_02()',500);
    });
  });
}

function intro_animation_02() {
	$('#home-intro-is-now').fadeOut(1000,function(){
	  $('#home-intro-logo').fadeIn(2000,function(){
        setTimeout('intro_animation_03()',500);
      });
	});
}

function intro_animation_03() {
  $('#home-intro').fadeOut(1500,function(){
	$('#main-hexs').hide().fadeIn(1500);
    $('#page').fadeIn(1500, function(){
			window.location.hash = '#home';
      hex_menu_animation();
	});
  })
}

function hex_menu_animation() {
	
	var delay = 1000;
	
  _hex_menu_hover_map['00'] = true;
  var displayOrder = [1,6,2,5,3,4];
  for( var j in displayOrder ) {
	if(_hex_menu_hover_map['00']) {
    setTimeout('show_hex_menu_animation("0'+displayOrder[j]+'");',   j * delay         );
		setTimeout('hide_hex_menu_animation("0'+displayOrder[j]+'");', ( j * delay ) + delay );
	}else {
	  break;
	}
  }
  setTimeout('hide_all_hex_menu_animation();', (7 * delay) )
}

function show_hex_menu_animation(accesskey) {
  if(_hex_menu_hover_map['00']) {
	$('#hex-menu-'+accesskey).fadeIn();
	//.css('visibility','visible');
  }
}

function hide_hex_menu_animation(accesskey) {
  if(_hex_menu_hover_map['00']) {
	$('#hex-menu-'+accesskey).fadeOut();
	//.css('visibility','hidden');
  }
}

function hide_all_hex_menu_animation() {
  if(_hex_menu_hover_map['00']) {
    _hex_menu_hover_map['00'] = false;
    for( var j = 1; j<=6; j++ ) {
      $('#hex-menu-0'+j).hide();
			//.css('visibility','hidden');
    }
  }
}
