$.fn.doPopo=function(type){
	$(this).append(jQuery('<table id="dpop" class="popup"><tbody><tr><td id="topleft" class="corner"></td><td class="top"></td><td id="topright" class="corner"></td></tr><tr><td class="left">&nbsp;</td><td class="bg">'+$(this).attr('description')+'</td><td class="right"></td></tr><tr><td class="corner" id="bottomleft"></td><td class="bottom"><img width="30" height="29" alt="弹出信息" src="css/images/bubble-tail2.gif"/></td><td id="bottomright" class="corner"></td></tr></tbody></table>'));
	$(this).each(function(){
		var distance = 6;
		var time = 250;
		var hideDelay = 100;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var info = $('.popup', this).css('opacity', 0);
		var thisw=$(this).width();
		var popow=$('.popup',this).width();
		if(type==1){
			info.css({
				top: -($('.popup',this).height()-36)+'px',
				left: (thisw<popow?-(popow-thisw)/2:(thisw-popow)/2)+'px',
				display: 'block',
				opacity: 1
			});
		}
		$(this).mouseover(function(){
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown){
				return;
			}
			else{
				//重置信息框位置
				beingShown = true;
				info.css({
					top: -($('.popup',this).height()-36)+'px',
					left: (thisw<popow?-(popow-thisw)/2:(thisw-popow)/2)+'px',
					display: 'block'
				}).animate({
					top: '-='+distance+'px',
					opacity: 1
				}, time, 'swing', function(){
					beingShown = false;
					shown = true;
				});
			}
			return false;
		}).mouseout(function(){
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function (){
				hideDelayTimer = null;
				info.animate({
					top: '+=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});
			}, hideDelay);
			return false;
		});
	});
};

$.fn.getContent=function(gid){
	dts=new Date().getTime();
	var obj=$(this);
	$('#mainMmap').html('<div><span id="loading">读取中...</span></div>'+$('#mainMmap').html());
	$('#loading').css({
		position:'absolute',
		width:'50px',
		backgroundColor:'#FFF',
		color:'#333',
		border:'1px solid #666',
		padding:'3px 6px 3px 6px',
		margin:'5px'
	});
	$.ajax({
		url: "ajax/getMagicMap.php?gid="+gid+"&dt="+dts,
		type: "GET",
		dataType: "text",
		timeout: 10000,
		error: spotIndex.Exception(),
		success: function(text){
			obj.html(text);
			$('.cm1').doPopo();
			$('.cm2').doPopo();
			$('.cm3').doPopo();
			$('.cm4').doPopo();
			$('.cm5').doPopo();
			$('.cmx').movePlay();
			obj.moveTip();
			obj.append($('<div id="overInfo"></div>'));
			$('#overInfo').html(obj.attr('description'));
			$('#glist'+gid).attr("style","font-weight:bold;font-size:14px;");
		}
	});
};

$.fn.movePlay=function(){
	var obj=$(this).css('opacity','1');
	var pi=3.14159265358979323846264338727950288419;
	var x=0;
	var y=0;
	Timer = setInterval(function(){
		x = x<760?Number(obj.css("marginLeft").replace('px',''))+3:0;
		y = Math.sin((pi*2*x)/180+0.618)*20+((x*pi*2)/90+0.618)+50; 
		obj.css({
			marginLeft: x+'px',
			marginTop: y+'px'
		});				 
	},30);
};

$.fn.moveTip=function(){
	var Timer=null;
	var thisw=0;
	var popow=0;
	var j=1;
	var t=0;
	Timer = setInterval(function(){
		thisw=$('.cm'+j).width();
		popow=$('.popup',$('.cm'+j)).width();
		$('.popup','.cm'+j).css({
			top: -($('.popup',$('.cm'+j)).height()-36)+'px',
			left: (thisw<popow?-(popow-thisw)/2:(thisw-popow)/2)+'px',
			display: 'block'
		}).animate({
			top: '-=' + 6 + 'px',
			opacity: 1
		}, 250, 'swing', function(){
			beingShown = false;
			shown = true;
		});
		t=(j==1)?5:j-1;
		$('.popup','.cm'+t).animate({
			top: '+=' + 6 + 'px',
			opacity: 0
		}, 250, 'swing', function(){
			shown = false;
			$(this).css('display', 'none');
		});
		j=(j<5)?j+1:1;
	}, 4000);
};