var mapdata = { target: null, func: null };
var handler_out = function(target){
	var stip = $(target+"-tip");
	//stip.data('OutInProgress',true);
	stip.css('z-index','999');
	stip.animate({opacity: "hide"}, 200,
		function(){
			//mapdata.target = null;
			stip.css('top','0');
			//_this.data('OutInProgress',false);
		}
	);
};

jQuery(document).ready(function(){
	$('#map-world>area').each(function(){
		var _container = $('#map');
		var _map = $(this);
		var _map_id = _map.attr('id');
		var _ids = '#'+_map_id+', #'+_map_id+'-tip';
		if( $.browser.msie && $.browser.version<8 ){
			_ids = _ids+', #'+_map_id+'-tip *';
		}
		_map.click(function(){
			var _tmpID = $(this).attr('id').replace('-tip','');
			var _this = $('#'+_tmpID);
			var stip = $('#'+_tmpID+'-tip');
			//console.log("mouseclick > mapdata.target="+mapdata.target);
			if(mapdata.target!=null && mapdata.target!=_this){
				handler_out('#'+mapdata.target.attr('id'));
			}
			mapdata.target=_this;
			var _coords;
			try{
			_coords = _this.attr("coords").split(',');
			}catch(ex){ _coords = ''; }
			var _minX = 10000, _minY = 10000, _maxX = 0, _maxY = 0;
			for(i=0; i<_coords.length; i++){
				if( i%2==0){
					_maxX = parseInt(_coords[i])>parseInt(_maxX)?parseInt(_coords[i]):parseInt(_maxX);
					_minX = parseInt(_coords[i])>parseInt(_minX)?parseInt(_minX):parseInt(_coords[i]);
				}else{
					_maxY = parseInt(_coords[i])>parseInt(_maxY)?parseInt(_coords[i]):parseInt(_maxY);
					_minY = _coords[i]>_minY?_minY:_coords[i];
				}
			}
			var _w = parseInt(_maxX) - parseInt(_minX);
			_minX =  parseInt( parseInt(_minX) + (_w / 2) ) - 50;
			var _h = parseInt(_maxY) - parseInt(_minY);
			_minY = parseInt(_minY) + parseInt(_h/2) - parseInt(stip.outerHeight()) - 10;
			stip.css({'left': _minX+'px','z-index':'1000'});
			stip.animate({opacity: 'show',top:_minY}, 500,
						 function(){

						});
			return false;
		});
		$(_ids,_container).hover(function(){
			//console.log("mouseIn > mapdata.target="+mapdata.target);
			var _tmpID = $(this).attr('id').replace('-tip','')
			var _this = $("#"+_tmpID);
			if(mapdata.target!=null)
			{
				if( _this.attr('id')==mapdata.target.attr('id') )
				{
					clearTimeout( mapdata.func );
				}
			}
		},function(){
			//console.log("mouseOut > mapdata.target="+mapdata.target);
			var _tmpID = $(this).attr('id').replace('-tip','')
			var _this = $("#"+_tmpID);
			mapdata.target = _this;
			_this.css('z-index','999');
			mapdata.func = setTimeout('handler_out(\'#'+_tmpID+'\')', 200);
		});
	});
	/*
	$("#south, #south-tip").mouseover(function(){
			var _this = $("#south");
			clearTimeout( _this.data( 'event_out') );
			var stip = $("#south-tip");
			var _coords = _this.attr("coords").split(',');
			var _minX = 10000, _minY = 10000;
			for(i=0; i<_coords.length; i++){
				if( i%2==0){
					_minX=_coords[i]>_minX?_minX:_coords[i];
				}else{
					_minY=_coords[i]>_minY?_minY:_coords[i];
				}
			}
			//var _w = stip.width();
			//_minX = _minX - (_w/2);
			_minY = _minY - (stip.height()/2);
			//stip.css({left:_minX+'px',opacity:'hide',top:0});
			stip.css('left', _minX+'px');
			stip.animate({opacity: "show",top:_minY}, 500,
						 function(){
							$(this).css('opacity','show');
						});
		}).mouseout(function(){
			var _this = $("#south");
			_this.data( 'event_out', setTimeout('handler_out()', 100) );
		});
	*/
});

/*

jQuery(document).ready(function(){
								
	
	$("#south").hover(function() {
	
	if ($("#south-tip", this).css("display") == "block") { return false; }
	os = $("#south-tip").offset();
	$("#south-tip", this).css({top: 120+"px", right: 140+"px"}).animate({top: 140+"px", opacity: "show"}, 750);
	},
	function() {
	os = $(this).offset();
	$("#south-tip", this).animate({top: os.top+"px", opacity: "hide"}, 10);
	});
	

}};

*/

