/*V. 0.1*/
$(document).ready(function(){

  var currentElem = 0;
  var animation = 0;
  var arrayElem = $(".boxes ul.listCountry > li");
  var arrayElemTrans = $(".boxes ul.listCountry > li .trans");
  $(".trans").show();

  var status = [
      {"id" : "africa",
       "status" : 0,
       "opacity" : 0},
      {"id" : "america",
       "status" : 0,
       "opacity" : 0 },
      {"id" : "asia",
       "status" : 0,
       "opacity" : 0 },
      {"id" : "europe",
       "status" : 0,
       "opacity" : 0 },
      {"id" : "middle-east",
       "status" : 0,
       "opacity" : 0 },
  ];

  var _tracker;
  var _trackEvent = function(event) {
	  	try {
			if(!_tracker) {
				_tracker = _gat._getTrackerByName();
			}
			_tracker._trackEvent('CountrySelector', event, 'click');
		} catch (e) {
		}
	};

  var setStatus = function(clickado) {

    var idActual = clickado.attr("id");

    //console.log("estoy en setstatus");

    for(s in status) {

      if( status[s].id == idActual ){
        oldOpacity = status[s].opacity;

        status[s].opacity = 0;

        $("#" + status[s].id + " .trans").stop(true, true).animate({
            opacity: 0
          }, 500, function(){
        	  $(this).css("display", "none");
          });

      }else{
          oldOpacity = status[s].opacity;
          status[s].opacity = 0.8;

          $("#" + status[s].id + " .trans").css("display", "block");

          $("#" + status[s].id + " .trans").stop(true, true).animate({
              opacity: 0.8
          }, 500);
      }

    }

  };

  var _mouseover = function() {
	  animation = 1;
	  var clickado = $(this);

    setStatus(clickado);

  };


  var _mouseout = function() {
    animation = 0;

	setTimeout(function() {

		if(animation == 0) {

			animation = -1;

		    var countries = [];
		    $(".trans", ".boxes ul.listCountry > li").stop(true,true).animate({
		    	"opacity" : 0
		    }, 500);

		    for(s in status) {
		    	status[s].opacity = 0;
		    }

		}
		 $(".trans", ".boxes ul.listCountry > li").css("display","block");

	}, 200);

  };

  $(".boxes ul.listCountry > li").bind('mouseenter', _mouseover).bind("mouseleave", _mouseout);

  $(".boxes ul.listCountry a").click( function(e){
	  	_trackEvent( $(this).html() );
	  });

  $(".boxes ul.listCountry > li").each(function() {
	 $(".trans", this).css({
		 "display" : "block",
		 "opacity" : 0
 	 });
  });

});

