
//创建各种DOM元素
function create(data){
  var element=arguments[1]||document.body;
  var object=document.createElement(data.tags);
  if(/^(script|img|link)$/i.test(data.tags)){
    var func=data.callback||function(){};
    object.onload=object.onreadystatechange=function(){if(!this.readyState||/loaded|complete/.test(this.readyState)){func();this.onload=this.onreadystatechange=null;this.removeAttribute('onload');if(this.tagName=="SCRIPT"){this.parentNode.removeChild(this)};}}
  };
  for(var key in data){
    if(/^(callback|tags|style)$/i.test(key)){
        if(key=='style'){object.style.cssText=data[key]};//delete data[key];
    }else if(object.attributes[key]){
        object.setAttribute(key,data[key])
    }else{
      object[key]=data[key]
    }
  };
  element.appendChild(object);
  return object;
};


//删除DOM对象
var kill=function(x){
  if(x==null||x==undefined){return};
  if(typeof(x)=='string'){                 //删除ID字符串
    var id=document.getElementById(x);
    if(id){id.parentNode.removeChild(id)};
  }else if(x.nodeType&&x.nodeType==1){     //删除DOM对象
    x.parentNode.removeChild(x)
  }else if(x.length!=undefined){           //删除对象集合
    for(var i=x.length;i>0;i--){arguments.callee(x[i-1])}
  }
};


//创建视频播放器栏目sidebar
function setplaybar($){
  var Item = create({tags:"div",name:"ItemBox",style:"padding;0px;margin:0px;border-Radius:3px;"},document.getElementById("zdyBox"));
  var z_bt = create({tags:"div",class:"ItemTxt",innerHTML:$.title,style:"height:20px;padding:4px 0px 0px 10px;background:transparent url('/static/uhome/css/style02/dh.jpg') repeat-x scroll 0px center;color:white;"},Item)
  var z_bo = create({tags:"div",class:"ItemBox",innerHTML:"",style:"width:auto;min-height:20px;border:0px;background:silver url(/static/uhome/images/loading3.gif) no-repeat scroll center center;"},Item)
  embedSWF({src:$.player+'?skin='+$.skins+'&image='+$.images+'&file='+$.video+'&backcolor=0xffffff&frontcolor=0x000000&lightcolor=0x000000&stretching=fill&autostart='+$.autostart+'&repeat=none&volume=100',allowfullscreen:"true",allowscriptaccess:"always",wmode:"opaque",width:$.width+'px',height:$.height+'px',style:'background-color:transparent;border:1px solid #333;border-Width:1px 0px;'},z_bo);
};
//创建播放器标签
function embedSWF(object){
  var element=arguments[1]||document.body;
  var flash=document.createElement("embed");
  if(object.style){flash.style.cssText=object.style;delete object['style']};
  for(var key in object){flash.setAttribute(key,object[key])};
  element.appendChild(flash);
};

//创建SWF播放器栏目
function SwfPlayer($){
  var Item = create({tags:"div",name:"ItemBox",style:"padding;0px;margin:0px;border-Radius:3px;"},document.getElementById("zdyBox"));
  var z_bt = create({tags:"div",class:"ItemTxt",innerHTML:$.title,style:"height:20px;padding:4px 0px 0px 10px;background:transparent url('/static/uhome/css/style02/dh.jpg') repeat-x scroll 0px center;color:white;"},Item)
  var z_bo = create({tags:"div",class:"ItemBox",innerHTML:"",style:"width:auto;min-height:20px;border:0px;background:silver url(/static/uhome/images/loading3.gif) no-repeat scroll center center;"},Item)
  embedSWF({src:$.player,allowfullscreen:"true",allowscriptaccess:"always",wmode:"opaque",width:$.width+'px',height:$.height+'px',style:'background-color:transparent;border:1px solid #333;border-Width:1px 0px;'},z_bo);
};


//创建超链接或文本标签栏目
function seturlbar(){
  var Item = create({tags:"div",name:"ItemBox",style:"padding;0px;margin:0px;border-Radius:3px;"},document.getElementById("zdyBox"));
  var z_bt = create({tags:"div",class:"ItemTxt",innerHTML:arguments[0],style:"height:20px;padding:4px 0px 0px 10px;background:transparent url('static/uhome/css/style02/dh.jpg') repeat-x scroll 0px center;color:white;"},Item)
  var z_bo = create({tags:"div",class:"ItemBox",innerHTML:"",style:"width:auto;min-height:20px;border:0px;background-Color:whitesmoke;"},Item)
  if(arguments[1].length == 0) return;
  var List = create({tags:"ul",style:"padding:0px 0px 0px 5px;;margin:0px;line-height:160%;list-style-type:none;font-Family:Tahoma,微软雅黑,宋体;"},z_bo);
  for(var i=0;i<arguments[1].length;i++){
    var link=arguments[1][i];//.split('|');
    var LI = create({tags:"li",style:"list-style-type:none;word-wrap:break-word;word-break:break-all;"},List);
    if(new RegExp('https?://([\\w\\-]+\\.)+[\\w\\-:]+(/[\\w\\-.:/#?%&=]*)?','ig').test(link[1])){
      var IMG = create({tags:"img",src:"/static/uhome/images/url.gif",style:"width:16px;height:16x;border:0px;vertical-align:middle;"},LI);
      var A = create({tags:"A",innerHTML:link[0],href:link[1],target:"_blank",style:"margin-Left:3px;vertical-align:middle;"},LI);
    }else{
      var IMG = create({tags:"img",src:"/static/uhome/images/wj.gif",style:"width:16px;height:16x;border:0px;vertical-align:middle;"},LI);
      var B = create({tags:"Label",innerHTML:link[0],style:"margin-Left:3px;font-Weight:bold;vertical-align:middle;"},LI);
      var I = create({tags:"Label",innerHTML:link[1],style:"margin-Left:6px;vertical-align:middle;"},LI);
    }
  }
};



//图片播放器-点击事件(停止/播放)
function PicEvent(obj){
  if(obj==null||obj.title=='\u70B9\u51FB\u64AD\u653E') return;
  var img=obj.getElementsByTagName("img");
  if(img.length <= 1) return;
  var x=0, y=0;
  for(var i=0;i<img.length;i++){
    if(img[i].style.display!='none'){x=i;y=(i+1)%img.length;break}
  };
  img[x].style.opacity=1;img[y].style.opacity=0;
  Alpha(img[x],img[y]); //图片切换效果
  setTimeout(function(){PicEvent(obj)}, 8000);
};

//透明渐变(hide/show)
function Alpha(x,y){
  if(!x||!y){return};
  var rgba=function(x){return x.style.opacity*1};
  var A=rgba(x);var B=rgba(y);
  if(A > 0 && B == 0){
    x.style.opacity=A-0.1;
  }else if(A == 0 && B == 0){
    x.style.display='none';
    y.style.display='inline';
    y.style.opacity=B+0.1;
  }else if(A == 0 && B < 1){
    y.style.opacity=B+0.1;
  };
  if(rgba(y)<1){setTimeout(function(){Alpha(x,y)},50)};
};
//创建图片播放栏目
function setpicbar(){
  if(arguments[1].length == 0) return;
  var Item = create({tags:"div",name:"ItemBox",style:"padding;0px;margin:0px;border-Radius:3px;"},document.getElementById("zdyBox"));
  var z_bt = create({tags:"div",class:"ItemTxt",innerHTML:arguments[0],style:"height:20px;padding:4px 0px 0px 10px;background:transparent url('static/uhome/css/style02/dh.jpg') repeat-x scroll 0px center;color:white;"},Item)
  var z_bo = create({tags:"div",class:"ItemBox",innerHTML:"",style:"width:auto;min-height:20px;border:0px;background-Color:whitesmoke;"},Item)

  var play="\u70B9\u51FB\u64AD\u653E"; //点击播放
  var stop="\u70B9\u51FB\u505C\u6B62"; //点击停止
  var PicBox = create({tags:"div",class:"PicBox",innerHTML:"",title:stop,style:arguments[2]},z_bo)
  for(var i=0;i<arguments[1].length;i++){
    var IMG=create({tags:"img",src:arguments[1][i],style:'width:100%;height:100%;float:left;cursor:pointer;display:'+(i==0?'inline':'none')+';'},PicBox);
  }
  PicBox.onclick=function(){this.title=this.title!=play?play:stop;setTimeout(function(){PicEvent(PicBox)}, 8000);};
  setTimeout(function(){PicEvent(PicBox)}, 8000);
};



/*
userconfig.wpzs_textlink_sort = 1; //文本或超链接
userconfig.wpzs_video_sort    = 2; //视频播放
userconfig.wpzs_huandeng_sort = 3; //幻灯图片
*/


//****************************************以下是演示代码****************************************

document.body.scroll="yes"; //显示滚动条


//显示和重新定义边栏CSS
var RightBox = document.getElementById("zdyBox");
RightBox.style.cssText="float:right;display:inline-block;margin:3px;padding;0px;width:300px;min-height:20px;border:2px solid Gray;border-Radius:3px;";


kill(document.getElementById("zdyBox").children);//清空自定义栏目


kill("cssbar"); //如果style标签ID存在则删除



// black,white,gray,silver,maroon,red,olive,yellow,green,lime,teal,cyan,navy,blue,purple,magenta

//边栏样式补充
var cssText = "#zdyBox A{color:black;text-decoration:none;}#zdyBox A:hover{color:red;text-decoration:underline;}#zdyBox LI *{vertical-align:middle;}";

//鼠标悬停-目录效果
if (userconfig.wpzs_faguangzi && userconfig.wpzs_faguangzi!='0') {
	cssText+= ".ztree li A:hover{text-shadow:0px 0px 5px "+userconfig.wpzs_faguangzi+", 0px 0px 10px "+userconfig.wpzs_faguangzi+", 0px 0px 15px "+userconfig.wpzs_faguangzi+", 0px 0px 30px "+userconfig.wpzs_faguangzi+", 0px 0px 40px "+userconfig.wpzs_faguangzi+";}.ztree li A:hover{color:white!important;text-decoration:underline;}";
}


//演示：创建一个style标签，添加CSS
var cssbar=create({tags:"style",type:"text/css",id:"cssbar",innerHTML:cssText},document.getElementsByTagName("head")[0]);




var Eval=new Object(); //存放要执行的脚本，然后遍历对象数组，按字母顺序执行脚本！

/*
//演示一：创建一个文本标签栏目
seturlbar("文本标签测试",[["联系方式","QQ:244656508"],["我的邮箱","244656508@qq.com"]])
*/


//演示二：创建一个视频播放器栏目 http://chunge188.com/video/SomeoneLikeYou.flv
if(userconfig.wpzs_video_url){
  Eval[userconfig.wpzs_video_sort]=function(){
    if(/\.swf(\?.*)?$/.test(userconfig.wpzs_video_url)==true){
      SwfPlayer({title:userconfig.wpzs_video_title,width:300, height:190,player:userconfig.wpzs_video_url});
    }else{
		  setplaybar({
	      title:userconfig.wpzs_video_title, width:300, height:190,
	      player:"http://www.a8tg.com/flash/JwPlayer.swf",
	      skins:"http://www.a8tg.com/flash/skin/beelden.zip",
	      video:userconfig.wpzs_video_url,
	      images:userconfig.wpzs_video_img+'?'+userconfig['indexbg_time']+'&imageMogr2/thumbnail/!230x180r/gravity/center/crop/230x180/interlace/1/quality/80',
	      autostart:"false"
	    });
    }
	}
};


//演示三：创建一个超链接栏目

var urls=new Array();
if(userconfig.wpzs_textlink!=null){
  for(var key in userconfig.wpzs_textlink){
    if(/^(length|toString)$/.test(key))continue; //排除这两个可能会导致错误的属性名
		urls.push([userconfig.wpzs_textlink[key].title,userconfig.wpzs_textlink[key].link]);
  }
};
if(urls.length > 0){
  Eval[userconfig.wpzs_textlink_sort]=function(){seturlbar(userconfig.wpzs_textlink_title,urls)};	 //创建超链接栏目
};


//演示四：创建一个图片轮播栏目
var images=new Array();
for(var i in userconfig.wpzs_huandeng){
	images.push(userconfig.wpzs_huandeng[i].src+'?imageView2/2/w/230/h/180/q/80');
}

if(images.length > 0){
  Eval[userconfig.wpzs_huandeng_sort]=function(){setpicbar(userconfig.wpzs_huandeng_title,images,'width:100%;height:230px;')}
};


//Eval存放要执行的脚本，然后遍历对象数组，按字母顺序执行脚本！
for(var key in Eval){ if(typeof Eval[key]=="function"){ Eval[key]() } };




//创建Flash节点 - 【创建开场动画】
function swfembed(object){
  //var msie=/msie/i.test(navigator.userAgent);
  var flash=document.createElement("embed");
  if(object.style){flash.style.cssText=object.style;delete object['style']};
  for(var key in object){flash.setAttribute(key,object[key])};
  //if(!msie)flash.onmouseup=function(){this.parentNode.removeChild(this)};
  flash.onmouseup=function(){this.parentNode.removeChild(this)};
  document.body.appendChild(flash);
};

if (userconfig['wpzs_kaichangdonghua']) {
	//产生一个随机的ID名字
	var TempID="S_"+Math.floor(Math.random()*0x7fffffff);
	
	//用这个ID创建一个不透明的flash动画元素
	swfembed({src:userconfig['wpzs_kaichangdonghua'],id:TempID,name:TempID,wmode:"opaque",style:"position:absolute;z-index:21474836470;left:0px;top:0px;width:100%;height:100%;background-color:#000;"});
	
	//如果5秒后这个ID还存在，就删除这个元素
	setTimeout(function(){var S=$("#"+TempID)[0];if(S){S.parentNode.removeChild(S)}}, userconfig['wpzs_kaichangdonghua_time']*1000);
};




var div=$('.ta_wjq')[0].getElementsByTagName("div");

if(!$('#timer')[0]){
  div[0].innerHTML="<label id='timer' style='color:yellow;'></label>&nbsp;<label id='folder' style='margin-right:20px;'>" + div[0].innerHTML.replace(/\s+/g,' ').replace(/^\s+|\s+$/g,'')+"</label>";
};

if(!$('#myip')[0]){
  div[1].innerHTML="\u76EE\u5F55\u5217\u8868&nbsp;<label id='myip' style='margin-left:20px;color:yellow;'></label>"
};

//系统时间
Date.prototype.Format = function(formatStr){return formatStr.replace(/yyyy|YYYY/,this.getFullYear()).replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100)).replace(/MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString():'0' + (this.getMonth()+1)).replace(/M/g,(this.getMonth()+1)).replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate()).replace(/d|D/g,this.getDate()).replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours()).replace(/h|H/g,this.getHours()).replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes()).replace(/m/g,this.getMinutes()).replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds()).replace(/s|S/g,this.getSeconds()).replace(/w|W/g,['日','一','二','三','四','五','六'][this.getDay()]);};

//显示时间 YYYY年MM月DD日 HH时mm分SS秒 星期W
(function(){
  if(!$('#timer')[0]  || userconfig['wpzs_time']=='隐藏'){return};
  $('#timer').html(new Date().Format("YYYY\u5E74MM\u6708DD\u65E5 HH\u65F6mm\u5206SS\u79D2 \u661F\u671FW"));
  setTimeout(arguments.callee, 1000);
})();


//显示IP地址 var returnCitySN={"cip":"","cid":"","cname":""};
if($('#myip')[0] && userconfig['wpzs_ip']=='显示'){
  create({tags:"script",type:"text/javascript",src:"http://pv.sohu.com/cityjson",callback:function(){$('#myip').html("\u60A8\u7684IP\uFF1A"+returnCitySN.cip+"\u3000\u6765\u81EA\uFF1A"+returnCitySN.cname);}});
};

//添加顶部动画  http://www.a8tg.com/flash/01.swf
for(var i in userconfig.wpzs_topflash){
	var flash=document.createElement("embed");
	flash.style.cssText="position:absolute;left:0;top:0px;width:100%;height:200px;";
	flash.setAttribute("src",userconfig.wpzs_topflash[i].url);
	flash.setAttribute("wmode","transparent");
	document.body.appendChild(flash);
};

//添加音乐播放器 http://www.yc88.net/dj1/
if (userconfig.wpzs_music_url) {
	jQuery('#music').html('<div id="Theme1_FlowStatistics" style="text-align: center;"><iframe src="'+userconfig.wpzs_music_url+'" width="100%" height="50" frameborder="0" scrolling="no"></iframe>');
};

//没有栏目则删除右侧边框
if (!userconfig.wpzs_textlink && !userconfig.wpzs_huandeng && !userconfig.wpzs_video_url) {
	jQuery('#zdyBox').remove();
}
