//by gftian
 
function c_module_adpic(ele){
	var links=window.adpic_href;
	var images=window.adpic_src;
	if(!links||!images)
		return;
	
	var today=new Date();
	for(var i=0;i<links.length;i++)
		links[i]=links[i].replace(/=\+(\d+)/gi,function(s0,s1){
			return '='+dateAdd(today,parseInt(s1));
		});

	var button={
		width:16,
		height:16,
		image:'',
		distance:8,
		right:8,
		bottom:8,
		fontSize:11,
		fontFamily:'arial',
		alpha:100
	};
	var b=window.adpic_button||{};
	for(var s in b)
		button[s]=b[s];
	var div=ele.parentNode;

	var offWidth=ele.offsetWidth;
	var offHeight=ele.offsetHeight;
	var target=ele.target||'_top';
	
	div.style.position='relative';
	div.style.textAlign='left';
	div.innerHTML='';
	ele=null;

	var pos=-1,atimer=0,gtimer=0,alpha=0,fore=0,back=0;
	var lnk=document.createElement('a');
	var cnt=links.length,lod=0;
	var img=new Array(cnt),btn=new Array(cnt);

	var bsty={
		top:(offHeight-button.height-button.bottom)+'px',
		width:button.width+'px',
		height:button.height+'px',
		font:'bold '+button.fontSize+'px/'+button.height+'px '+button.fontFamily,
		color:'#fff',
		textAlign:'center',
		position:'absolute',
		cursor:'pointer',
		display:'none',
		overflow:'hidden',
		zIndex:3
	};
	var msty='width:'+offWidth+'px;height:'+offHeight+'px;left:0;top:0;border:none;display:none;position:absolute;filter:alpha(opacity=100)';
	for(var i=0;i<links.length;i++){
		btn[i]=document.createElement('div');
		bsty.left=offWidth-button.right-cnt*button.width-(cnt-1)*button.distance+i*(button.width+button.distance)+'px';
		if(button.image)
			bsty.backgroundImage='url("'+button.image+'")';
		else
			btn[i].innerHTML=i+1;
		for(var s in bsty)
			btn[i].style[s]=bsty[s];
		hilit(i,false);
		btn[i]._index=i;
		btn[i].onclick=click;
		lnk.appendChild(btn[i]);
		img[i]=document.createElement('img');
		img[i].style.cssText=msty;
		img[i].onload=load;
		img[i].src=images[i];
		lnk.appendChild(img[i]);
	}

	lnk.style.cssText='display:block;position:absolute;left:0px;top:0px;text-decoration:none';
	lnk.target=target;
	div.appendChild(lnk);
	lnk.href=links[0];
	img[0].style.display='block';

	function load(){
		this.onload=null;
		if(cnt<2||++lod!=cnt)
			return;
		for(var i=0;i<cnt;i++)
			btn[i].style.display='block';
		setCurrent(0);
	}
	function click(evt){
		if(back!=this._index){
			clearInterval(atimer);
			clearTimeout(gtimer);
			animate(this._index);
		}
		lnk.blur();
		return false;
	}
	function animate(newpos){
		if(newpos<0||arguments.length==0)
			newpos=(pos+1)%cnt;
		setForeBack(pos,newpos);
		atimer=setInterval(function(){
			setAlpha(alpha-3);
			if(alpha>=70&&alpha<73)
				setCurrent(newpos);
			else if(alpha==0)
				clearInterval(atimer);
		},15);
	}
	function setForeBack(newfore,newback){
		img[fore].style.display='none';
		img[back].style.display='none';
		fore=newfore;
		back=newback;
		setAlpha(100);
		setAlpha(100,img[back]);
		with(img[fore].style){
			display='block';
			zIndex=2;
		}
		with(img[back].style){
			display='block';
			zIndex=1;
		}
	}
	function setAlpha(n,im){
		alpha=n<0?0:n;
		im=im||img[fore];
		if(im.filters)
			im.filters[0].opacity=alpha;
		else
			im.style.opacity=alpha/100;
	}
	function setCurrent(newpos){
		if(pos==newpos)
			return;
		if(pos>=0)
			hilit(pos,false);
		pos=newpos;
		hilit(pos,true);
		lnk.href=links[pos];
		gtimer=setTimeout(animate,4000,-1);
	}
	function hilit(p,b){
		var st=btn[p].style;
		if(button.image)
			st.backgroundPosition=-p*button.width+'px '+(b?-button.height:0)+'px';
		else
			st.backgroundColor=b?'orange':'#999999';
		if(button.alpha==100)
			return;
		if("filters" in btn[p])
			st.filter='alpha(opacity='+(b?100:button.alpha)+')';
		else
			st.opacity=b?'0.9999':(button.alpha)/100;
	}
	function dateAdd(dt,n){
		var d=new Date(dt.getTime());
		d.setDate(d.getDate()+n);
		return [d.getFullYear(),d.getMonth()+1,d.getDate()].join('-');
	}
}

function c_module_spcoffer(el){
	var dat = el.getAttribute('para');
	if(!dat || !(dat = window[dat])) return;
	var arr = [];
	for(var i = 0; i < dat.length; i++)
		arr.push(c_module_spcoffer.replace(dat[i]));
	for(var a = el.lastChild; a;){
		if(a.tagName && a.tagName != 'A') break;
		var b = a.previousSibling;
		el.removeChild(a);
		a = b;
	}
	el.innerHTML += arr.join('');
}
c_module_spcoffer.template =
	'<a target="_self" href="{$href}"><p title="{$tip}">{$left}</p><span>{$right}</span></a>';
c_module_spcoffer.replace=function(str){
	var t=str.split('|');
	return this.template.replace('{$left}',t[0]).replace('{$right}',t[1]).replace('{$tip}',t[2]).replace('{$href}',t[3]);
};

function c_module_htlspcoffer(el){
	var dat = el.getAttribute('para');
	if(!dat || !(dat = window[dat])) return;
	var arr = [];
	for(var i = 0; i < dat.length; i++)
		arr.push(c_module_htlspcoffer.replace(dat[i]));
	for(var a = el.lastChild; a;){
		if(a.tagName && a.tagName != 'A') break;
		var b = a.previousSibling;
		el.removeChild(a);
		a = b;
	}
	el.innerHTML += arr.join('');
	$parserByRegExp(el);
}

var linkID=0;

c_module_htlspcoffer.template =
	'<a id="myLink{$ID}_jmpinfo_m" target="_self" href="{$href}" page="enghotel_note.asp" para="align-left,{$tip}"><p>{$left}</p><span>{$right}<dfn class="pubGlobal_remarkcolor01">{$price}</dfn></span></a>';
c_module_htlspcoffer.replace=function(str){
	var t=str.split('|');
	return this.template.replace('{$ID}',linkID++).replace('{$left}',t[0]).replace('{$right}',t[1]).replace('{$price}',t[2]).replace('{$tip}',t[3]).replace('{$href}',t[4]);
};

function c_module_imglink(el){
	var dat = el.getAttribute('para');
	if(!dat || !(dat = window[dat])) return;
	el.href = dat.href||'###';
	el.innerHTML = c_module_imglink.template.replace('{$src}', dat.image).replace(/\{\$title\}/g, dat.title);
}
c_module_imglink.template =
	'<img src="{$src}" title="{$title}" alt="{$title}" />';