/**
 * @classDescription 导航类
 * @author molezz (msn:mole_zz@hotmail.com QQ:13148960)
 * @version 3.0.2.0 alpha
 * @description 优化了图像预载函数 L111
 * @since 3.0.1.0 alpha
 * @license GPL
 */
function Nav(className){
	this.name=className;
	this.conTagID;//容器ID
	this.textTagID;//欲改变文本的区域ID
	this.imgTagID;//欲改变图像的区域ID
	this.imgLinkTagID;//欲改变的图象链接ID
	this.actTagName="a";//产生动作的标签name
	this.actType="mouseover";//自选动作，默认为mouseover
	this.flag=999;
	this.ifAutoDo=true; //初始化时是否自动执行第一次
	this.ifRepeat=false; //是否重复更新相同项目（与其他程序整合时使用）	
	this.classMark;//变化的样式
	this.classTagName=this.actTagName;//改变样式的目标标签name,默认为产生动作的标签
	this.arrCon;//传入内容的数组(imgSrc,imgUrl,textContent)
	this.imgCache;//图片缓存数组
	this.useCache=true;//是否使用图片缓存,默认为true。
	this.msFilter=false;//是否使用IE的转换效果，该效果对FF无效 false为不使用;auto为使用滤镜，且由程序决定使用何种滤镜;数字0-18为对应的19种滤镜.默认为auto
	this.filterCustom;//自定义滤镜，类型为字符串
	this.filterTagID;//滤镜应用区域ID，仅当msFilter不为false时有效
	this.navAuto=false;//自动导航展示	true为开启，在此状态下间隔为5000ms；false为关闭； 数字为变化的毫秒数。 默认为false
	this.useXmlHttp=false; //是否使用XmlHttpResponse方式获得文本区域的内容，默认为false，可选项（"xml"，"text"）；开启此功能需包含framework.js
	this.ajaxCache=[]; //ajax方式缓存数组
	this.ajaxLocked=false; //ajax方式定位锁
	this.ajaxOnload='<div style="margin:0 auto;position:relative;top:30px;"><img src="http://www.bdall.com/skin/bdall/styles/default/common/img_loading.gif" alt="loading"/>页面载入中，请稍候...</div>'; //载入效果
	this.initiMe=function(){
		if(typeof this.conTagID=="string"){ this.conTag=document.getElementById(this.conTagID); }		
		if(typeof this.textTagID=="string"){ this.textTag=document.getElementById(this.textTagID);}
		if(typeof this.imgTagID=="string"){ this.imgTag=document.getElementById(this.imgTagID);}
		if(typeof this.imgLinkTagID=="string"){ this.imgLinkTag=document.getElementById(this.imgLinkTagID);}
		if(typeof this.actTagName=="string"&&typeof this.conTag!="undefined"){ this.actTag=this.conTag.getElementsByTagName(this.actTagName);}	
		if(typeof this.classTagName=="string"&&typeof this.conTag!="undefined"){ this.classTag=this.conTag.getElementsByTagName(this.classTagName);}		
		if(this.useCache==true){
			this.imgCache=this.arrImgPre(this.arrCon);			
		}
		if(!this.addEvent(className)){
			alert("添加动作失败");
		}
		if(typeof this.msFilter=="undefined"||this.msFilte==""){//安全检查，防止空值
			this.msFilter="auto";
		}		
		if((this.msFilter!==false||this.msFilter=="auto")&&document.all){//判断是否使用IE的转换滤镜
		    this.filterLib=new Array()//滤镜效果库
		    this.filterLib.push("progid:DXImageTransform.Microsoft.Barn(duration=1,motion=in,orientation=vertical);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Blinds(duration=1,bands=50,Direction=right);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.CheckerBoard(duration=1,Direction=right);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Fade(duration=1.5,overlap=0.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.gradientWipe(duration=2,gradientsize=0.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Inset(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Iris(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Pixelate(duration=1.5,maxSquare=20);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.RadialWipe(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.RandomBars(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.RandomDissolve(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Slide(duration=2.5,bands=8);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Spiral(duration=1.2,GridSizeX=25,GridSizeY=25);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Stretch(duration=1.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Strips(duration=2);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Wheel(duration=1.5,spokes=8);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.Zigzag(duration=2.5,GridSizeX=25,GridSizeY=25);");
			this.filterLib.push("blendTrans(duration=0.5);");
			this.filterLib.push("progid:DXImageTransform.Microsoft.RevealTrans(duration=2,transition=23);");
	   }
	   if(this.ifAutoDo==true){
	   		this.changeState(0);
			this.flag=0;   		
	   };	     
	   if(this.navAuto!=false&&typeof this.navAuto=="number"){
	   	    eval("this.setIntervalID=window.setInterval(\""+className+".autoShow()\","+this.navAuto+");");			
	   }else if(this.navAuto==true){
	   	    eval("this.setIntervalID=window.setInterval(\""+className+".autoShow()\",5000);");
	   }	 		
	}		
}
Nav.prototype.arrImgPre=function(arr){//图片预先载入返回图片数组
	   if(typeof(arr)!="undefined"){
			 var t=new Array();			
			 for(var i in arr){
				   t[i]=this.getImg(arr,i);					  								
				 }
			return t;
		 }else{
		 	return ;
		 }
		}
Nav.prototype.formatArr=function(arr){//格式化数组索引.返回数组
		if(typeof(arr)=="undefined"){
			return false;
			}else{				
				var imgCon=new Array();
				var num=0;
				for(var i in arr){
				  	imgCon[num]=i;
						num++;
				}
				return imgCon;
			}
		}
Nav.prototype.getImg=function(arr,index){
		  if(typeof(arr)=="undefined"){
			  return false;
			}else if(typeof arr[index][0]!="undefined"&&arr[index][0]!=""){				
				var img=new Image();
				img.src=arr[index][0];
				return img;
			}else {return false;}
		}
Nav.prototype.getTxt=function(arr,index){
		  if(typeof(arr)=="undefined"){
			  return false;
			}else{			
				return arr[index][2];
			}
		}
Nav.prototype.getUrl=function(arr,index){
		  if(typeof(arr)=="undefined"){
			  return false;
			}else{			
				return arr[index][1];
			}
		}
Nav.prototype.addEvent=function(cName){//添加动作	
	     if(typeof cName!="string"){
		 	alert("未提供类实例变量名称，添加动作失败！");
			return false;
		 }		 
		 if(typeof this.actTag!="undefined"){
			 var t=this.actTag;			 
			 if(typeof this.actType!="string")	 return false;		
			 var tasktype=(window.addEventListener)? this.actType : "on"+this.actType;
			 var focusAct=(window.addEventListener)? "focus" : "onfocus";
			 var functionref;
			 var functionBlur=function(){ this.blur();};
			 for(var i=0;i<t.length;i++){
			 	t[i].tabIndex=i;
				eval("functionref=function(){"+cName+".changeState("+i+");if("+cName+".setIntervalID)clearInterval("+cName+".setIntervalID);}");//用户选择后取消自动展示			    				
				if (t[i].addEventListener){
					t[i].addEventListener(focusAct, functionBlur, false);
		            t[i].addEventListener(tasktype, functionref, false);						
				}else if (t[i].attachEvent){					
					t[i].attachEvent(tasktype, functionref);				
				}
			}				
			return true;
		 }else{
		 	return false;
		 } 
		}
Nav.prototype.changeImg=function(imgTag,content){
		if(typeof imgTag!="undefined"&&content!=false){			
			imgTag.src=content.src;			
			}
		}
Nav.prototype.changeTxt=function(textTag,choice){
		if(typeof textTag!="undefined"&&this.useXmlHttp===false){
				textTag.innerHTML=this.getTxt(this.arrCon,this.flag);
			}else{
				if(typeof this.ajaxCache[choice]!=="undefined"){
					textTag.innerHTML=this.ajaxCache[choice];
				}else{
					var pageContent=textTag.innerHTML; //存储当前页面内容
					textTag.innerHTML=this.ajaxOnload;
					var url=this.getTxt(this.arrCon,this.flag); //获取数据页面地址					
					if(this.useXmlHttp=="text"&&url!="_self"){
						try{
							eval('xmlHttpPool.sendReq("GET","'+url+'","",function(obj){'+this.name+'.remoteDataHandle(obj,"'+this.name+'");});');
							this.ajaxLocked=textTag; //锁定对象
						}catch(e){
							alert("函数调用错误，请包含framework.js，或检查链接"+e);
						}
					}else if(this.useXmlHttp=="xml"&&url!="_self"){ //功能尚未开放
						return false;
					}else if(url=="_self"){ //读取当前页面
						textTag.innerHTML=pageContent;
						this.ajaxCache[choice]=pageContent; //将页面内容写入缓存
						return;
					}else{
						textTag.innerHTML="非法参数"+this.useXmlHttp;
					}
				}				
			}
		}
Nav.prototype.changeUrl=function(imgLinkTag){//为图片添加链接
		if(typeof imgLinkTag!="undefined"){
			imgLinkTag.href=this.getUrl(this.arrCon,this.flag);
			}
		}
Nav.prototype.changeClass=function(obj){//改变className返回改变前的className值
		if(typeof obj!="undefined"){
		    var t=obj.className;
		    obj.className=this.classMark;		
		    return t;
		}
	}
Nav.prototype.changeState=function(choice){
	    var tag=this;//对this进行封包，便于在子函数内引用
		var t=tag.classTag;
		var classObj=t[choice];//获取目标对象
		var classPre=t[tag.flag];//获取当前对象，保存状态
		var classOrg;//记录当前对象的className				
		if(tag.flag==choice&&tag.ifRepeat==false){return false;}//安全检查				
		if(typeof(tag.arrCon[choice])=="undefined"){return false;}//安全检查
		if(tag.useXmlHttp!==false){ tag.ajaxLocked=false; } //解锁，防止在使用ajax方式时页面被错误改写
		function changeNavClass(){//改变导航栏样式
			if(typeof(classObj)!="undefined"){
			    classOrg=tag.changeClass(classObj);
				if(typeof(classPre)!="undefined"){classPre.className=classOrg;}
						    			    						
		    }		
		}
		function changeImgLink(){
			if(typeof tag.imgLinkTag!="undefined"){			
				tag.changeUrl(tag.imgLinkTag);
			}
		}
		function changeImgSrc(){
			if(typeof tag.imgCache!="undefined" && tag.imgCache!=null){//检测是否使用了图片缓存，并改变图片
			    tag.changeImg(tag.imgTag,tag.imgCache[choice]);							
		    }else{
			    tag.changeImg(tag.imgTag,tag.getImg(tag.arrCon,choice));					
		    }
		}
		function changeTextArea(){		
		    if(typeof tag.textTag!="undefined"){
		        tag.changeTxt(tag.textTag,choice);
		    }
		}
		if((tag.msFilter!==false||tag.msFilter=="auto")&&document.all&&window.navigator.appName.toLowerCase()!="opera"){//判断是否使用IE的转换滤镜		  			
			var filterTag;			
			function filterPlay(filterKey){
			    if(typeof tag.filterTagID=="undefined"){filterTag=tag.imgTag;}else{filterTag=document.getElementById(tag.filterTagID);}
			    if(typeof filterTag!="undefined"){
					if(typeof filterKey!="string") return false;
				    filterTag.style.filter=filterKey;				    
				    filterTag.filters[0].Apply();
				    changeImgSrc();
				    filterTag.filters[0].Play();
			    }
			}
			if(typeof tag.filterCustom=="string"){			
			    filterPlay(tag.filterCustom);
			}else if(typeof tag.msFilter=="number"){
				filterPlay(tag.filterLib[tag.msFilter]);
			}else if(tag.msFilter.toLowerCase()=="auto"){
				var c=Math.random();				
				c=Math.floor((c*1000)%19);								
				filterPlay(tag.filterLib[c]);
			}
			tag.flag=parseInt(choice);
			if (typeof this.classMark!="undefined")
			{
				changeNavClass();
			}			
			changeTextArea();
			changeImgLink();
		}else{			
			tag.flag=parseInt(choice);
			if (typeof this.classMark!="undefined")
			{
				changeNavClass();
			}
			changeImgSrc();	
			changeTextArea();
			changeImgLink();
		}		
	}
Nav.prototype.autoShow=function(){	
	if(typeof this.autoTotal=="undefined"){
		this.autoTotal=this.actTag.length;
	}
	if(typeof this.autoCount=="undefined"||(typeof this.autoCount=="number"&&this.autoCount>=this.autoTotal)){//初始化计数器
		this.autoCount=0;
	}else if(typeof this.autoCount=="number"&&this.autoCount<this.autoTotal){
		this.autoCount+=1;
	}
	this.changeState(this.autoCount);
}
Nav.prototype.remoteDataHandle=function(obj,name){
	var tag=eval(name);	
	if(tag.ajaxLocked!==false){		
		tag.ajaxCache[tag.flag]=obj.responseText;		
		tag.ajaxLocked.innerHTML=tag.ajaxCache[tag.flag];
	}else{
		return;
	}
}
