function mwa(){
	Mwa_translation();
   	Mwa_JTsetup('.Mwa .entry_v2 > .hw_d > .fl');
}
function Mwa_JTsetup(str){
	var eles=document.querySelectorAll(str);
	if(eles.length<2){
		if(!!eles[0]){
			eles[0].removeAttribute('onclick');
		}
		return;
	}
	for(var i=0; i<eles.length; ++i){
		eles[i].setAttribute('onclick', Mwa_scrollPosition(eles[i==eles.length-1?0:i+1]));
	}
}

function Mwa_scrollPosition(target){
	var _id=target.getAttribute('id');
	if(!_id){
		_id='random'+Math.round(Math.random()*100000);
		target.setAttribute('id', _id);
	}
	if(!isBluedict())
		return "window.location.href='#"+_id+"'";
	return "window.location.href='entry://#"+_id+"'";
}

function isBluedict(){
	return !!document.querySelector('.bd_body, .lm5ppbody.bluedict');
}


function Mwa_translation(){
	if (!document.querySelector('.Mwa .mw_zh')) return;
	Mwa_translation_individual();
	var Mwa_h1=document.querySelectorAll('.Mwa #ld_entries_v2_mainh');
	for (var i=0; i<Mwa_h1.length; ++i){
		var trans_button=document.createElement('Mwa_trans');
		trans_button.onclick=Mwa_translation_button;
		Mwa_h1[i].appendChild(trans_button);
	}
}

function Mwa_translation_individual(){
	var Mwa_cn=document.querySelectorAll('.Mwa .mw_zh');
	for (var i=0; i<Mwa_cn.length; ++i){
		var trans_blank=document.createElement('Mwa_trans_blank');
		trans_blank.onclick=Mwa_translation_blank;
		Mwa_cn[i].parentNode.insertBefore(trans_blank, Mwa_cn[i]);
	}
}

function Mwa_translation_blank(trans_blank){
	this.setAttribute('trans', '');
	this.nextSibling.setAttribute('trans', '');
}

function Mwa_translation_button(){
	var Mwa_cn=document.querySelectorAll('.Mwa .mw_zh, Mwa_trans_blank');
	var Mwa_btns=document.getElementsByTagName('Mwa_trans');
	if(Mwa_btns[0].hasAttribute('trans')){
		for(var i=0; i<Mwa_btns.length; ++i){
			Mwa_btns[i].removeAttribute('trans');
		}
		for(var i=0; i<Mwa_cn.length; ++i){
			Mwa_cn[i].removeAttribute('trans');
		}
	}
	else{
		for(var i=0; i<Mwa_btns.length; ++i){
			Mwa_btns[i].setAttribute('trans', '');
		}
		for(var i=0; i<Mwa_cn.length; ++i){
			Mwa_cn[i].setAttribute('trans', '');
		}
	}
}
