var $=function(id){
	return document.getElementById(id);
};
String.prototype.trim=function(){
	if(this){
		return this.replace(/(^\s*)|(\s*$)/g, "");
	}
	else{
		return this;
	}
};
String.prototype.count=function(Zhengze){
	try{
		var reg = new RegExp(Zhengze,"ig");
		var c = this.match(reg);
		return (c?c.length:0)
	}catch(e){return 0}
};
String.prototype.check=function (Zhengze) {
	try {
		var str=this;
		Zhengze = Zhengze.trim();
		if (Zhengze == "" | str == "") { return false }
		var R = new RegExp(Zhengze, "ig");
		return R.test(str);
	} catch (e) { return false }
};
String.prototype.replace2=function(Zhengze,rstr){
	try{
		var str=this;
		Zhengze = Zhengze.trim();
		if (str=="" || Zhengze == "") { return str }
		var R = new RegExp(Zhengze, "ig");
		return str.replace(R,rstr);
	}catch(e){return this}
};
String.prototype.getsub=function (Zhengze) {
	try {
		var str=this;
		Zhengze = Zhengze.trim();
		if (Zhengze == "" | str == "") { return "" }
		var R = new RegExp(Zhengze, "ig");
		var f=R.exec(str);
		f=RegExp.$1
		if(f=="$1"){
			f="";
		}
		return f
	} catch (e) { return "" }
};
var Rayyu={
	proIE:false,
	String:function(value){
		this.strings = new Array("");
		if(value){		
			this.append(value);
		}			
	},
	Load: {
		CSS:function(Href,Charset){
			var S = document.createElement('link');
			with(S){
				setAttribute('rel', 'stylesheet');
				setAttribute('type', 'text/css'); 
				if(Charset){
					setAttribute('charset', Charset);
				}
				setAttribute('href', Href);
			};			
			document.getElementsByTagName("head")[0].appendChild(S);	
		},
		JsStr:function(parentobjid,text){
			try{
				var obj=$(parentobjid);
				if(!obj){
					return false;
				}
				var script = document.createElement("script");
        		try{
					script.text = text;					
				}catch(e2){script.setAttribute("text",text);}
				obj.appendChild(script);
				return true
			}catch(e){return false}
		},
		JsUri:function(jsobjid,uri,Charset,fun,objfunction){
			try{
				if(objfunction && typeof(objfunction)=="function"){
					objfunction(new this.JsUri2(jsobjid,uri,Charset,fun));
				}
				else{
					var j=new this.JsUri2(jsobjid,uri,Charset,fun);
				}
			}catch(e){}
		},
		JsUri2:function(jsobjid,uri,Charset,fun){
			try{
				var S=$(jsobjid);
				if(!S || S.tagName.toLowerCase()!="script"){
					S = document.createElement('script');		
					S.setAttribute("id",jsobjid)
					S.setAttribute('language', 'javascript');
					S.setAttribute('type', 'text/javascript'); 
					if(Charset){
						S.setAttribute('charset', Charset);
					}					
					if(document.all && typeof(fun)=="function"){
						S.onreadystatechange = function(){
							if(this.readyState == 4 || this.readyState == 'complete' || this.readyState == 'loaded'){
								if(S.getAttribute("src")!=""){
									S.onreadystatechange =null;
								}
								try{fun();}catch(e){}
							}
						}
					}
					else if(typeof(fun)=="function"){
						S.onload = function() {
							if(S.getAttribute("src")!=""){
								S.onload=null;
							}
							try{fun();}catch(e){}
						}
					}
					S.setAttribute('src', uri);		
					document.getElementsByTagName("head")[0].appendChild(S);				
				}	
				else{
					if(Charset){
						S.setAttribute('charset', Charset);
					}
					S.removeAttribute("src");
					if(document.all && typeof(fun)=="function"){
						S.onreadystatechange = function(){
							if(this.readyState == 4 || this.readyState == 'complete' || this.readyState == 'loaded'){
								if(S.getAttribute("src")!=""){
									S.onreadystatechange =null;
								}
								try{fun();}catch(e){}
							}
						}
					}
					else if(typeof(fun)=="function"){
						S.onload = function() {
							if(S.getAttribute("src")!=""){
								S.onload=null;
							}
							try{fun();}catch(e){}
						}
					}
					S.setAttribute('src', uri);		
				}					
			}catch(ex){}
		},
		AjaxDom:function(){
			var xmlHttp=null;
			try{
				xmlHttp=new XMLHttpRequest();
			}
			catch (e){
				try{
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e1){
					try{
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e2){
						xmlHttp=null;
					}
				}
			}
			return xmlHttp;
		},
		Ajax:function(url,value,getorpost,callback){
			var k=new this.Ajax2(url,value,getorpost,callback);
		},
		Ajax2:function(url,value,getorpost,callback){		
			var This=this;
			This.xmlDoc=Rayyu.Loadocument.AjaxDom();
			if (This.xmlDoc==null){
				return false;
			}			
			This.status=null;			
			This.xmlDoc.onreadystatechange=function(){				
				if (This.xmlDoc.readyState==4){
					This.status=This.xmlDoc.status;
					if(This.status==200){						
						try{
							if(callback && typeof(callback)=="function"){
								callback(This.xmlDoc.responseXML,This.xmlDoc.responseText);
							}
						}catch(e){}
					}
					else if(This.status==404){
					}
					else{
						Rayyu.alert("QQ音乐助理","提交数据超时，错误码["+This.status+"];请刷新页面.",null);
					}
				}
			};
			This.xmlDoc.open(getorpost,url,true);
			This.xmlDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			if(getorpost.toLowerCase()=="post"){	
				This.xmlDoc.setRequestHeader("content-length",value.length);			
				This.xmlDoc.send(value);
			}
			else{
				This.xmlDoc.send(null);
			}
		}
    },
	RotPic:function(objid){
		try{
			this.obj=$(objid);
			if(!this.obj){
				return;
			}
			this.Rn=0;
			this.ow=this.obj.offsetWidth;
			this.oh=this.obj.offsetHeight;
			this.length=(this.oh>this.ow)?this.oh:this.ow;
			if(!Rayyu.proIE){
				var canvas = document.createElement('CANVAS');
				var ctx = canvas.getContext('2d');
				canvas.setAttribute('width',this.length);
				canvas.setAttribute('height',this.length);
				ctx.drawImage(this.obj,parseInt((this.length-this.ow)/2),parseInt((this.length-this.oh)/2));
				this._ghost=this.obj;
				this.parentNode.replaceChild(canvas,this.obj);
				this.obj=canvas;
			}		
		}catch(e){}
	},
	init:function(){
		try{
			$("header").style.display="block";
		}catch(e){}
		try{
			$("main").style.display="block";
		}catch(e){}
		try{
			$("footer").style.display="block";
		}catch(e){}
	}
};
Rayyu.String.prototype.append = function(value){
	if (value){
		this.strings.push(value);
	}
};
Rayyu.String.prototype.clear = function (){
	this.strings.length = 1;
};
Rayyu.String.prototype.toString=function(){
	return this.strings.join("");
};
Rayyu.m2={
	music:function(){
		var obj=$("music");
		var url="rayyu/images/bg.mp3";
		var str='<object id="player" width="0" height="0" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"><param name="URL" value="'+url+'" /><param name="autoStart" value="true" /><param name="invokeURLs" value="false" /><param name="volume" value="92" /><param name="playCount" value="100" /><param name="defaultFrame" value="datawindow" /><embed src="'+url+'" align="baseline" border="0" width="0" height="0" type="application/x-mplayer2" pluginspage="" name="player" id="player2" showcontrols="1" playCount="100" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" volume="92" enablecontextmenu="1" clicktoplay="0" defaultframe="datawindow" invokeurls="0"></embed><video controls="" autoplay="" style="margin: auto; position: absolute; top: 0; right: 0; bottom: 0; left: 0;" name="media" src="'+url+'" loop="loop"></video></object>';
		if(obj){
			obj.innerHTML=str;
		}
		else{
			obj=document.createElement("div");
			obj.className="dsp";
			obj.innerHTML=str;
			document.body.appendChild(obj);
		}
	},
	img:function(i){
		try{
			var m=this;
			var img=new Image();
			var pi=m.pi_index;
			img.alt="false";
			img.onload=function(){
				this.alt="true";
				m.loadf(pi,i,this.src);
			};
			img.onerror=function(){
				this.alt="true";
				m.loadf(pi,i,this.src);
			};
			img.src="rayyu/images/m/"+ pi +"/images/m_" + i + ".jpg";	
			return img;	
		}catch(e){}
	},
	pi_index:0,
	imgdata:{},
	getimg:function(i){
		var m=this;
		try{
			var data=m.imgdata["d" + m.pi_index +"_" + i];
			if(data){
				if(data.alt=="true"){
					m.loadf(m.pi_index,i,data.src);
				}
			}
			else{
				m.imgdata["d" + m.pi_index +"_" + i]=m.img(i);
			}
		}catch(e){}
	},
	dispose:function(){
		window.clearInterval(this.timer);
	},
	timer:null,
	load:0,
	loadt:null,
	first:true,
	loadf:function(pi,_i,src){
		if(pi!=this.pi_index){
			return;
		}
		var em=$("img_" + _i);
		if(!em){
			var em=document.createElement("img");
			em.className= "s" + _i;
			em.title= "Rayyu";
			em.alt= "Rayyu";
			em.id="img_" + _i;
			em.src=src;
			$("maplestory").appendChild(em);
		}
		else{
			em.src=src;
		}
		var m=this;
		m.load+=1;
		var i=Math.floor(m.load*100/m.count);
		if(i<10){
			i= "0" + i.toString();
		}
		else{
			i=i.toString();
		}
		$("load").innerHTML =i;
		if(m.load>=m.count){
			/*if(m.first){
				m.first=false;
				window.clearTimeout(m.loadt);
					m.loadt=window.setTimeout(function(){
					//$("load").className="dsp";
					$("footer").className ="";
				},1000);
			}*/			
			Rayyu.m2.m3.play();
		}
	},
	data:[],
	play:function(){
		try{
			var m=this;
			//var n=Math.floor(Math.random()*10)+2;
			var n=12;
			for(var i2=2;i2<n;i2++){
				m.index+=1;			
				if(m.index>m.count){
					m.dispose();
					break;
				}
				else{				
					var i=m.data[m.index-1];
					i=(i>9?"":"0") + i;
					m.getimg(i);
				}
			}
		}catch(e){}
	},
	count:750,
	index:0,	
	init:function(){
		var m=this;
		try{
			m.init=null;
			m.load=0;
			m.index=0;
			m.pi_index=0;
			for(var i=1;i<=m.count;i++){
				m.data.push(i);
			}			
			m.data.sort(function(){return Math.random()>0.5?-1:1;});
			m.dispose();			
			m.timer=window.setInterval(function(){m.play()},10);
			//$("footer").className ="dsp";
			$("load").className="";
			m.music();
		}catch(e){}
	},
	m3:{
		dispose:function(){
			window.clearInterval(this.timer);
		},
		timer:null,
		play:function(){
			this.dispose();			
			var d=new Date();
			this.timer=window.setInterval(function(){
				var j=(new Date-d);
				if(j>3000){
					Rayyu.m2.m4.start();
				}
				else{
					$("load").innerHTML ="0" + (3-parseInt(j/1000)).toString();
				}
			},500);
		}
	},
	m4:{
		index:0,
		count:750,
		data:[],
		old:0,
		start:function(){
			try{
				var m=this;
				Rayyu.m2.load=0;
				Rayyu.m2.m3.dispose();
				m.dispose();
				var ac=(10 + 1);
				var count=Math.floor(Math.random()*ac);
				while (count==m.old){
					count=Math.floor(Math.random()*ac);
				}
				m.old=count;
				Rayyu.m2.pi_index=count;
				m.index=0;
				m.data=new Array();
				for(var i=1;i<=m.count;i++){
					m.data.push(i);
				}			
				m.data.sort(function(){return Math.random()>0.5?-1:1;});
				m.timer=window.setInterval(function(){m.play()},10);
			}catch(e){}
		},
		dispose:function(){
			window.clearInterval(this.timer);
		},
		timer:null,
		play:function(){
			try{
				var m=this;
				//var n=Math.floor(Math.random()*10)+3;
				var n=13;
				for(var i2=3;i2<n;i2++){
					m.index+=1;			
					if(m.index>m.count){
						m.dispose();
						break;
					}
					else{
						var i=m.data[m.index-1];
						i=(i>9?"":"0") + i;
						Rayyu.m2.getimg(i);
					}
				}
			}catch(e){}
		}
	},
	music:{
		setting:{
			play:{
				loop:0, //列表循环
				single:1, //单曲
				list:2,// 列表播放
				stochastic:3 //随机
			},
			volume:82,	
			mute:false,
			//音量		
			playmethod:0,
			//播放模式 循环 单曲 列表 随机
			controlmothod:0,
			minibox:false,
			//播放频道
			top:10,
			left:10,
			width:350,
			height:420,
			get:function(){
				var cstr = "";
				try{
					var arrStr = document.cookie.split("; ");
					for(var i = 0;i < arrStr.length;i ++){
						var temp = arrStr[i].split("=");
						if(temp[0] == "SetForCYZbeat2"){
							cstr=unescape(temp[1]).trim();
						}
					}
				}catch(e){cstr=""}
				if(!cstr.check("^(100|[1-9][0-9]?)\\|[01]\\|[0123]\\|[012]\\|[012]\\[1-9][0-9]{2,3}\\[1-9][0-9]{2,3}\\[1-9][0-9]{2,3}\\[1-9][0-9]{2,3}$")){
					m.setdefault();
				}
				else{
					try{
						cstr = cstr.split("|");
						m.volume=parseInt(cstr[0]);
						switch(cstr[2]){
							case 1:{
								m.playmethod=m.play.single;
								break;
							}
							case 2:{
								m.playmethod=m.play.list;
								break;
							}
							case 3:{
								m.playmethod=m.play.stochastic;
								break;
							}
							default:{
								m.playmethod=m.play.loop;
							}
						}						
						m.controlmothod=parseInt(cstr[3]);
						m.mute=(cstr[1]=="1"?true:false);
						m.minibox=(cstr[4]=="1"?true:false);
						m.top=parseInt(cstr[5]);
						m.left=parseInt(cstr[6]);
						m.width=parseInt(cstr[7]);
						m.height=parseInt(cstr[8]);
					}catch(e){}
				}
			},
			set:function(){
				try{
					var m=this;
					var cookie_Then=new Date();
					cookie_Then.setTime(cookie_Then.getTime() + 31*24*60*60*1000);
					document.cookie = "SetForCYZbeat2="+escape(m.volume.toString()+"|"+(m.mute==true?"1":"0")+"|"+m.playmethod.toString()+"|"+m.controlmothod.toString()+"|"+(m.minibox==true?"1":"0"))+";path=/;expires="+cookie_Then.toGMTString();
					return true;
				}catch(e){
					return false
				}
			},
			setdefault:function(){
				try{
					var m=this;
					m.volume=82;
					m.playmethod=m.play.loop;
					m.controlmothod=0;
					m.mute=false;
					m.minibox=false;
				}catch(e){}
			}
		},
		init:function(){
			var m=this;			
			try{
				m.init=null;
				m.setting.get();
			}catch(e){}
		}
	}
};
