﻿var stopEvent = function(e){
	e = e||window.event;
	if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble = true;}
	if(e.preventDefault){e.preventDefault();}else{e.returnValue = false;}
};
var getElementsBy = function(att,svalue,stag,dmodule,collection){
		var rd = [],l = dmodule?dmodule.length:0;
		if(!stag){return rd;}
		if(l){
			for(var n=0;n<l;n++){if(!dmodule[n]){continue;}rd = rd.concat(arguments.callee(att,svalue,stag,dmodule[n],collection));}
			return rd;
		}
		var atts = att,ctag = true,hasatt = false,satt = null,rxp = new RegExp("("+svalue+")","i");
		if(atts=='class'&&(/msie[67]/i).test(navigator.appVersion.replace(/\s/g,''))){atts='classname'}
		if(collection){
			if(!att){
				if(stag=='*'||stag.toLowerCase()==dmodule.tagName.toLowerCase()){rd.push(dmodule);return rd;}
			}else{
				hasatt = dmodule.getAttributeNode(att),satt = dmodule.getAttribute(atts);
				ctag = (stag=='*')?true:(dmodule.tagName.toLowerCase()==stag.toLowerCase());
				if(ctag&&hasatt&&(!svalue||rxp.test(satt))){rd.push(dmodule);return rd;}
			}
		}else{
			var tmpd = dmodule.getElementsByTagName(stag),tmpdl = tmpd.length,i = 0;
			if(!tmpdl){return rd;}
			if(!att){
				for(i=0;i<tmpdl;i++){
					if(stag=='*'||stag.toLowerCase()==tmpd[i].tagName.toLowerCase()){rd.push(tmpd[i]);continue;}
				}
			}else{
				for(i=0;i<tmpdl;i++){
					hasatt = tmpd[i].getAttributeNode(att),satt = tmpd[i].getAttribute(atts);
					if(hasatt&&(!svalue||rxp.test(satt))){
						rd.push(tmpd[i]),rxp.lastIndex = -1;
					}
				}
			}
		}
		return rd;
};
var dySwitch = function(sEventHandle,bStopEvent){//参数1:切换方式;参数2:是否阻止Event
	this.btn = [];
	this.content = [];
	this.nowIndex = 0;
	this.sEventHandle = (sEventHandle==null)?'click':sEventHandle;
	this.bStopEvent = (bStopEvent==null)?true:bStopEvent;
	this.timer = null;
}
dySwitch.prototype = function(){
	if(!Function.prototype.bind){
		Function.prototype.bind = function(obj){
			var owner = this,args = Array.prototype.slice.call(arguments),callobj = Array.prototype.shift.call(args);
			return function(e){e=e||top.window.event||window.event;owner.apply(callobj,args.concat([e]));};
		};
	}
	return {
		addSw:function(dBtn,dContent){
			if(dBtn && dContent){
				var iLength = this.btn.length;
				(iLength>0) && (dContent.style.display='none',1) || (dBtn.className='on')
				with({i:iLength}){
					dBtn['on'+this.sEventHandle] = this.show.bind(this,i);
					if(this.bStopEvent&&this.sEventHandle!='click'){dBtn.onclick = function(e){e = e||window.event;stopEvent(e);}}
				}
				this.btn.push(dBtn);
				this.content.push(dContent);
			}
		},
		playFilter:function(dobj){
			if(!dobj||!dobj.filters||!dobj.filters.length){return false;}
			//dobj.filters[0].Transition=23; 随机切换滤镜开启
			dobj.filters[0].apply();
			dobj.filters[0].Play();
		},
		show:function(iIndex,e){
			e = e||window.event;
			if(e&&e.type=='click'){stopEvent(e);}
			var nowIndex = this.nowIndex;
			if(nowIndex!=iIndex) this.btn[nowIndex].className='';this.content[nowIndex].style.display='none';
			if(iIndex>-1 && iIndex<this.btn.length) this.btn[iIndex].className='on';this.playFilter(this.content[iIndex]);this.content[iIndex].style.display='';
			this.nowIndex = iIndex;
		},
		autoShow:function(iSpeed){
			var os = this,tsl = this.btn.length;
			var ias = function(){
				var ni = (os.nowIndex >= tsl-1)?0:os.nowIndex+1;
				os.show(ni);
				os.timer = window.setTimeout(arguments.callee,iSpeed);
			};
			var wct = function(){window.clearTimeout(os.timer);};
			var wst = function(){os.timer = window.setTimeout(ias,iSpeed);};
			var wcst = function(){window.clearTimeout(os.timer);os.timer = window.setTimeout(ias,iSpeed);};
			for(var i=0;i<tsl;i++){
				if(document.attachEvent){
					if(this.sEventHandle!='mouseover'){
						this.btn[i].attachEvent('on'+this.sEventHandle,wcst);
					}else{
						this.btn[i].attachEvent('on'+this.sEventHandle,wct);
						this.btn[i].attachEvent('onmouseout',wst);
					}
				}else{
					if(this.sEventHandle!='mouseover'){
						this.btn[i].addEventListener(this.sEventHandle,wcst,true);
					}else{
						this.btn[i].addEventListener(this.sEventHandle,wct,true);
						this.btn[i].addEventListener('mouseout',wst,true);
					}
				}
			}
			this.timer = window.setTimeout(ias,iSpeed);
		}
	}
}();
var doWhileExists = function(id,foo){
	var dTmp = document.getElementById(id);
	if(dTmp){foo(dTmp);}
};
//sidebar oplist hover
var dhover = function(dModule){
	var dMenu = dModule.getElementsByTagName('LI');
	var ln = dMenu.length;
	for(var i=0;i<ln;i++){
		with({i:i}){
			dMenu[i].onmouseover = function(){
				if(dMenu[i].className != 'on'){
					dMenu[i].className = 'over';
				}
			}
			dMenu[i].onmouseout = function(){
				if(dMenu[i].className != 'on'){
					dMenu[i].className = '';
				}
			}
		}
	}
}
doWhileExists('sidecont',dhover);
doWhileExists('appmenulist',dhover);