window.onerror=function(){return true};
$.ajaxSetup({crossDomain: false});
$("a").live("focus",function(){$(this).blur();})
function alertFun(str,HTML){
	str=str||"*";
	if(typeof(str) =="object"){str='<b>【object】</b>'+jsonToString(str);}
	printHtml=HTML||false;
	if($("#alert").length==0){$("body").prepend('<div id="alert"></div>')}
	if(printHtml){str='<textarea style="width:99%;height:80px;border:1px #FF9595 solid;">'+str+'</textarea>';}
	$("#alert").html($("#alert").html()+str).unbind().dblclick(function(){$(this).hide()});
};
/*********************************************************/
/*侧边栏导航事件*/
function add_client_navClk(){
	$(".client_nav a").click(function(){
		openUrlInMainWnd($(this).attr("href"));
		return false;
	});
}
function openUrlInMainWnd(url){
	try{
		window.top.bfcwin.openUrlInMainWnd(url);
	}catch(e){}
}
/*********************************************************/
/*下载按钮状态事件*/
function webLoadButtonStyle(appID,state){
	var allAddAppObj=$("a[addApp='true'][resid='"+appID+"']");
	for(var i=0,l=allAddAppObj.length;i<l;i++){
		var tmpclass=loadButtonStyle(state);
		allAddAppObj.eq(i).attr("class","addRes_"+allAddAppObj.eq(i).attr("btnClass")).addClass(tmpclass+"_"+allAddAppObj.eq(i).attr("btnClass"));
	}
}
function initLoadButtonStyle(){
	var allAddAppObj=$("a[addApp='true']");
	for(var i=0,l=allAddAppObj.length;i<l;i++){
		var appID=allAddAppObj.eq(i).attr("resid");
		try{
			var appState = parseInt(window.top.bfcweb.getAppState(appID),10);
		}catch(e){
			var appState = 0;
		}
		var tmpclass=loadButtonStyle(appState);
		var btnClass=allAddAppObj.eq(i).attr("class").split("_")[1];
		allAddAppObj.eq(i).attr("btnClass",btnClass);
		allAddAppObj.eq(i).attr("class","addRes_"+btnClass).addClass(tmpclass+"_"+btnClass);
	}

}
function loadButtonStyle(appState){
	var tmpclass="addBtn";
	switch(appState){
		case 0:
			//未下载
			tmpclass="addBtn";
			break;
		case 1:
			//正在下载
			tmpclass="loadingBtn";
			break;
		case 2:
			//已停止下载
			tmpclass="restartBtn";
			break;
		case 3:
			//下载失败
			tmpclass="addBtn";
			break;
		case 4:
			//下载完成
			tmpclass="loadingBtn";
			break;
		case 5:
			//正在安装中
			tmpclass="loadingBtn";
			break;
		case 6:
			//安装失败
			tmpclass="addBtn";
			break;
		case 7:
			//安装完成
			tmpclass="openBtn";
			break;
		case 8:
			//正在删除
			tmpclass="openBtn";
			break;
		case 9:
			//正在修复
			tmpclass="loadingBtn";
			break;
		case 10:
			//修复失败
			tmpclass="openBtn";
			break;
		case 11:
			//正在升级
			tmpclass="loadingBtn";
			break;
		case 12:
			//升级失败
			tmpclass="openBtn";
			break;
		default:
			tmpclass="addBtn";
			break;
	}
	return tmpclass;
}
/*********************************************************/
/*添加资源函数*/
function addApp(apps,autoplay){
	if(!$.isArray(apps)){
		apps=new Array(apps);
	}
	for(var i=0,l=apps.length;i<l;i++){
		var _app=apps[i];
		if(!$.isPlainObject(_app)){
			try{
				eval("_app="+_app);
			}catch(e){
				_app={};
			}
		}
		if(!_app.id){return;}
		try{
			_app.fly=(i==0)?true:false;//是否需要图标飞动
			_app.autoplay=(i==0)?autoplay||_app.autoplay : 0;//0强制不打开 1自动 2强制代开
			window.top.bfcweb.addApp(jsonToString(_app,"Unicode"));
		}catch(e){
			alert(jsonToString(_app,"Unicode"));	
		}
	}
}
/*********************************************************/
/*对象转字符串函数*/
function jsonToString(obj,chrType){
	var _tmpArray=[];
	for(var key in obj){
		var tmpobjs;
		var values=obj[key];
		if(values instanceof Array){//值为数组
			var tmpArr=[];
			for(var i=0,l=values.length;i<l;i++){
				if(values[i] === null){//数组元素值为null
					tmpArr.push("null");
				}else if(values[i] instanceof Object){//数组元素有对象
					tmpArr.push(arguments.callee(values[i]));
				}else{
					switch(typeof(values[i])){
						case "string":
							if(chrType=="Unicode"){
								tmpArr.push(chrToUnicode(values[i]));
							}else{
								tmpArr.push('"'+values[i]+'"');
							}
							break;
						default:
							tmpArr.push(values[i]);
							break;
					}
				}
			}
			tmpobjs='['+tmpArr.join(',')+']';
		}else if(values instanceof Object){//值为对象
			tmpobjs=arguments.callee(values);
		}else{
			switch(typeof(values)){
				case "string":
					if(chrType=="Unicode"){
						tmpobjs=chrToUnicode(values);
					}else{
						tmpobjs='"'+values+'"';
					}
					break;
				default:
					tmpobjs=values;
					break;
			}
		}
		_tmpArray.push('"'+key+'":'+tmpobjs);
	}
	var returnStr='{'+_tmpArray.join(',')+'}';
	return  returnStr;
}
function chrToUnicode(str){
	if (str!="") {
		var escapable = /[^\u0000-\u00FF]/g;
		str=str.replace(/\\/g,"\\\\").replace(/\//g,"\\/");
		escapable.lastIndex = 0;
		return escapable.test(str) ? '"' + str.replace(escapable, function(a){
			return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
		}) + '"' : '"' + str + '"';
	}else {
		return '""';
	}
}
/*获取url地址参数*/
function getUrlParam(url){
	var sUrl = url || window.location.href;
	start = sUrl.indexOf("?");
	end = sUrl.length;
	sUrl=sUrl.substring(start+1,end);
	var strArr = sUrl.split("&");
	var paramJson={};
	for(var i=0;i<strArr.length;i++){
		var tmpSplit=strArr[i].split("=");
		paramJson[tmpSplit[0]]=tmpSplit[1];
	}
	return paramJson;
}
/*********************************************************/
/*随机数组函数*/
function getArrayRandomItems(){
	var arr=arguments[0];
	var putLen=arguments[1];//去除数组元素的个数
	var temp_array=arr.concat();
	var return_array = new Array();
	for (var i = 0; i<putLen; i++) {
		if (temp_array.length>0) {
			var arrIndex = Math.floor(Math.random()*temp_array.length);
			return_array[i] = temp_array[arrIndex];
			temp_array.splice(arrIndex, 1);
		} else {
			break;
		}
	}
	return return_array;
}

/**************************************************************************************/
/*滚动类*/
function autoSlideClass(options){
	options=options||{};
	this.Timer = [null,null];
	this.id_class=options.id_class||null;
	this.leftBar=($(options.leftBar).length>0)?$(options.leftBar):null;
	this.rightBar=($(options.rightBar).length>0)?$(options.rightBar):null;
	this.numBar=($(options.numBar).length>0)?$(options.numBar):null;
	this.numBarEventName=options.numBarEventName||"mouseover";
	this.conText=($(options.conText).length>0)?$(options.conText):null;
	this.conTextArr=options.conTextArr||[];
	this.position=options.position||"left-right";
	this.easing=options.easing||"easeOutQuad";//缓动方法 使用easing插件
	this.animateTime=options.time||0;//动画持续时间
	this.autoPlay=options.autoPlay||false;
	this.domAppendWhere="append";
	this.pauseTime=options.pauseTime||6000;
	this.indexImg=options.indexImg||0;
	this.moveDomNumber=options.moveDomNumber||1;
	this.fn=options.callback||function(){};
	this.barClickPlay=this.autoPlay||false;//未设置自动播放，控制bar事件启动自动播放
	this.conCase=$(this.id_class);
	this.conCaseWidth=this.conCase.innerWidth()||620;
	this.conCaseHeight=this.conCase.innerHeight()||200;
	this.ulObj=this.conCase.children();
	this.conLiWidth=this.ulObj.children().innerWidth()||120;
	this.conLiHeight=this.ulObj.children().innerHeight()||180;
	this.listArr=options.listArr||[];
	this.isMoving=false;
	this.Start=function(){
		if(this.position=="left-right"){
			this.ulObj.width(this.conCaseWidth*this.moveDomNumber*2.5);//初始化UL宽度
		}else{
			this.ulObj.width("105%");
			this.ulObj.height(this.conCaseHeight*this.moveDomNumber*2.5);//初始化UL高度
		}
		var that=this;
		
		if(this.leftBar){
			this.leftBar.focus(function(){$(this).blur()}).click(function(){
				if(that.isMoving){return false;}
				that.reWriteList(that.addDomList("prepend"));
			}).hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		
		if(this.rightBar){
			this.rightBar.focus(function(){$(this).blur()}).click(function(){
				if(that.isMoving){return false;}
				that.reWriteList(that.addDomList("append"));
			}).hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		
		if(this.numBar){
			var clickTimer=100;
			if(this.numBarEventName=="click"){
				this.numBar.find("a").bind("mousemove",function(){
					clickTimer=0;
					that.autoPlay=false;
					that.Stop();								   
				});
			}
			this.numBar.find("a").unbind().focus(function(){$(this).blur()}).bind(this.numBarEventName,function(){
				that.autoPlay=false;
				that.Stop();
				if(that.isMoving){return;}
				var index=parseInt($(this).attr("index"));
				clearTimeout(that.Timer[1]);
				that.Timer[1]=setTimeout(function(){
					if(that.indexImg==index){
						return;
					}else if(that.indexImg>index){
						that.indexImg=index+1;
						that.reWriteList(that.addDomList("prepend"));
					}else{
						that.indexImg=index-1;
						that.reWriteList(that.addDomList("append"));
					}
					that.numBar.find("a").removeClass("active").eq(index).addClass("active");
				 },clickTimer);
				return false;
			}).bind("mouseout",function(){
				clearTimeout(that.Timer[1]);
				that.reStart();
			});
		}
		
		if(this.conText){
			this.conText.hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		this.conCase.hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		if(this.autoPlay){
			this.reStart();
		}
	};
	this.addDomList=function(where){
		this.domAppendWhere=where;
		var listLen=this.listArr.length;
		switch(where){
			case "prepend":
				var indexArr=[this.indexImg];
				for(var i=0;i<this.moveDomNumber;i++){
					indexArr.push((indexArr[i]-1<0)?listLen-1:indexArr[i]-1);
				}
				indexArr.shift();
				if(this.indexImg==indexArr[indexArr.length-1]){return [];}
				this.indexImg=indexArr[indexArr.length-1];
				break;
			default:
				var index=this.indexImg;
				for(var i=0;i<this.moveDomNumber-1;i++){
					index=(index+1>=listLen)?0:index+1;
				}
				var indexArr=[index];
				for(var i=0;i<this.moveDomNumber;i++){
					indexArr.push((indexArr[i]+1>=listLen)?0:indexArr[i]+1);
				}
				indexArr.shift();
				if(this.indexImg==indexArr[0]){return [];}
				this.indexImg=indexArr[0];
				break;
		}
		return indexArr;
	},
	this.reWriteList=function(indexArr){
		this.backcallIndexImg=indexArr;//此属性回调函数中使用
		if(indexArr.length<1){return;}
		for(var i=0,l=indexArr.length;i<l;i++){
			if(this.domAppendWhere=="prepend"){
				this.ulObj.prepend(this.listArr[indexArr[i]]);
				if(this.position=="left-right"){
					this.conCase.scrollLeft(this.conLiWidth*(i+1));
				}else{
					this.conCase.scrollTop(this.conLiHeight);
				}
				if(i>=l-1){
					this.Move(-1);
				}
			}else{
				this.ulObj.append(this.listArr[indexArr[i]]);
				if(i>=l-1){
					this.Move(1);
				}
			}
		}
		if(this.numBar){
			this.numBar.find("a").removeClass("active").eq(indexArr[0]).addClass("active");
		}
		this.fn(this);
	};
	this.Move=function(n){
		this.Stop();
		this.isMoving=true;
		var that=this;
		switch(this.position){
			case "left-right":
				var _w=(n<0)?0:this.conLiWidth*this.moveDomNumber;
				this.conCase.animate({scrollLeft: _w},this.animateTime,this.easing,function(){
					that.isMoving=false;
					if(n<0){
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().last().remove();
						}
					}else{
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().first().remove();
						}
						that.conCase.scrollLeft(0);
					}
					if(that.autoPlay){that.reStart();}
					return;								   
				});
				break;
			default:
				var _h=(n<0)?0:this.conLiHeight*this.moveDomNumber;
				this.conCase.animate({scrollTop: _h},this.animateTime,this.easing,function(){
					that.isMoving=false;
					if(n<0){
						for(var i=0;i<that.moveDomNumber;i++){
							this.ulObj.children().last().remove();
						}
					}else{
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().first().remove();
						}
						that.conCase.scrollTop(0);
					}
					if(that.autoPlay){that.reStart();}
					return;															   
				});
				break;
		}
	};
	this.Stop=function(){
		clearTimeout(this.Timer[0]);
	};
	this.reStart=function(){
		this.Stop();
		this.autoPlay=true;
		var that=this;
		if(this.autoPlay && this.barClickPlay){
			this.Timer[0]=setTimeout(function(){that.reWriteList(that.addDomList(that.domAppendWhere));},this.pauseTime);
		}
	}
}

/**************************************************************************************/
/*easing插件*/
jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});
