/* w_tab
自动初始化选项卡的操作及调用目标页面的动作(此处设置针对全局属性)
属性:{
	param:调用目标页面时传送的内容,
	acdiv:是否自动创建内容div,
	divcss:自动创建的内容div的样式类,
	divsty:自动创建的内容div的样式,
	cssH:指向选项卡时的样式类,
	cssS:选中后选项卡的样式类,
	divaim:存放内容div的容器ID
	load:正在加载时显示的内容,
	cache:是否使用缓存数据,
	event:激活选项卡的方式(click:单击 hover:鼠标指向)
}
每个选项卡可设置属性说明:(此处设置针对每一个选项卡)
aim:内容框的ID号 格式为:[元素类型#]内容ID号
lnk:目标页面地址
cssH:指向选项卡时的样式类
cssS:选中后选项卡的样式类
styH:指向选项卡时的样式代码
styS:选中选项卡时的样式代码

*/
(function($){
	$.fn.w_tab=function(op){
		if(typeof(op)=="number"){
			this.eq(op).triggerHandler("click");
		}else{
			var op=$.extend({},$.fn.w_tab.defaults,op);
			if(op.acdiv){ if(!op.divaim){ return;}}
			var old="";
			var sib=Array();
			this.each(function(){sib.push('#'+$(this).attr('aim'));});
			sib=sib.join(',');
			return this.each(function(){
				var el=$(this);
				var param={
					aM:el.attr('aim'),
					lK:el.attr('lnk'),
					cC:el.attr('class'),
					cH:el.attr('cssH') || op.cssH,
					cS:el.attr('cssS') || op.cssS,
					sC:el.attr('style'),
					sH:el.attr('styH'),
					sS:el.attr('styS')
				};
				el.mouseover(function(){
					if(old[0]!=this){
						if(param.cH){ this.className=param.cH;}
						if(param.sH){ $(this).attr('style',param.sH);}
						if(op.event=='mouseover'){$(this).triggerHandler('click');}
						if (this.aim=="zw2tabcont1"){
							$("#swfcont1").attr("style","display:block");
						}else if (this.aim=="zw2tabcont2"){
							$("#swfcont2").attr("style","display:block");
						}else if (this.aim=="zw2tabcont3"){
							$("#swfcont3").attr("style","display:block");
						}else if (this.aim=="zw2tabcont4"){
							$("#swfcont4").attr("style","display:block");
						}
					}
				}).mouseout(function(){
					if(old[0]!=this){
						if(param.cC){ this.className=param.cC;} else { this.className="";}
						if(param.sC){ $(this).attr('style',param.sC);}
						if (this.aim=="zw2tabcont1"){
							$("#swfcont1").attr("style","display:none");
						}else if (this.aim=="zw2tabcont2"){
							$("#swfcont2").attr("style","display:none");
						}else if (this.aim=="zw2tabcont3"){
							$("#swfcont3").attr("style","display:none");
						}else if (this.aim=="zw2tabcont4"){
							$("#swfcont4").attr("style","display:none");
						}
					}
					
					
					
				}).click(function(){
					var tmp=old;old=$(this);
					if(tmp!=""){tmp.triggerHandler("mouseout");}
					if(param.cS){ this.className=param.cS;}
					if(param.sS){ $(this).attr('style',param.sS);}
					//根据参数调用目标页面并显示在内容容器(内容容器根据需要自动创建与否)
					//得出目标ID值和目标元素类型
					var arram=param.aM.split('#');
					if(arram.length>1){
						param.aM=arram[1];
						param.dT=arram[0];
					}else{
						param.dT='div';
					}
					var ediv=$('#'+param.aM);
					if(ediv.length<1){
						if(op.acdiv){
							ediv=$('<'+param.dT+' id="'+param.aM+'" class="'+op.divcss+'" style="'+op.divsty+'">').appendTo($('#'+op.divaim));
						}else{return;}
					}
					ediv.css('display','block').siblings(sib).hide();
					if(param.lK){
						if(ediv.attr('isContent')!="1" || !op.cache){
							ediv.html(op.load);
							$.ajax({
								url:param.lK,
								type:"GET",
								data:op.param,
								success:function(data){
									ediv.html(data);
									ediv.attr('isContent',"1")
								}
							});
						}
					}
				})
			});
		}
	};
	$.fn.w_tab.defaults={
		param:{},
		acdiv:0,
		divcss:"",
		divsty:"",
		cssH:"",
		cssS:"",
		divaim:0,
		cache:1,
		event:'click',
		load:'<br /><br /><br /><img align="absmiddle" src="images/loading.gif" />&nbsp;正在加载数据'
	};
})(jQuery);


/* w_roll
滚动对象，该插件会复制出同样的对象以实现无缝滚动效果，新复制出的对象ID为目标对象ID连接_roll
属性:{
	speed:移动速度,
	way:滚动方向,1234对应上右下左,
	cbtn:控制方向的按钮组 例:cbtn:{1:'',2:''} 其中的数字对应着way
	cbtncss:是否自动调整方向按钮的位置
}
*/
(function($){
	$.fn.w_roll=function(p){
		var op=$.extend({},$.fn.w_roll.defaults,p);
		return this.each(function(){
			var mytime=0;
			var el=$(this).css({'overflow':'hidden'});
			var _t=op.way==2 || op.way==4?0:1;
			var wsize=0;
			if(el.data('plug_init')!=1){
				var elc=$('<div></div>');
				var _el=el[0];
				elc.css(_t?'height':'width',3000);
				el.children().each(function(){
					wsize+=$(this)[_t?'outerHeight':'outerWidth'](true);
				});
				if(wsize<(_t?el.height():el.width())){return;}
				el.append(elc.append(el.children(),el.children().clone()).css(_t?'height':'width',wsize*2));
				el.data('plug_init',1)
					.hover(function(){
						clearInterval(mytime);
					},function(){
						clearInterval(mytime);
						mytime=setInterval(rollpic,op.speed)
					});
					
				if(op.cbtn){
					$.each(op.cbtn, function(i,val){
						var $val=$('#'+val);
						$val.bind('mousedown',function(){op.way = i;op.oldstep=op.step;op.step=op.step+4;})
								.bind('mouseup',function(){op.step=op.oldstep;});
						
						if(op.btncss){
							$val.css({'position':'absolute'});
							var off=el.position();
							var si={t:(el.outerHeight()-$val.outerHeight())/2,l:(el.outerWidth()-$val.outerWidth())/2};
							switch(i){
								case '1':$val.css({left:si.l,top:off.top+10});break;
								case '2':$val.css({top:si.t,left:off.left+el.outerWidth()-$val.outerWidth()-10});break;
								case '3':$val.css({left:si.l,top:off.top+el.outerHeight()-$val.outerHeight()-10});break;
								case '4':$val.css({top:si.t,left:off.left+10});break;
							}
						}
					});
				}
				
				function rollpic(){
					var ws = (op.way==1 || op.way==3)?'scrollTop':'scrollLeft';
					if(op.way== 1 || op.way==4){
						_el[ws] +=op.step;
						if(_el[ws]>=wsize){_el[ws] = 0;}
					}else{
						_el[ws] -=op.step;
						if(_el[ws]<=0){_el[ws] = wsize;}
					}
				};
				
				mytime=setInterval(rollpic,op.speed)
			}
		});
	};
	$.fn.w_roll.defaults={
		speed:30,
		way:4,
		step:1,
		cbtn:0,
		btncss:0
	};
})(jQuery);

/*对齐页面元素 a:高度参照元素ID b:目标元素ID mar:偏移量 调用者为需要改变的元素*/
(function($){
	$.fn.w_aheight=function(p){
		var op=$.extend({},$.fn.w_aheight.defaults,p);
		var $el=this;
		var $a=$('#'+op.a);
		var $b=$('#'+op.b);
		var tmpH=$a.outerHeight()-$b.outerHeight()-op.mar;
		$el.height($el.height()+tmpH);
	}
	$.fn.w_aheight.defaults={
		a:'',
		b:'',
		mar:0
	};
})(jQuery);

/*
播放指定的FLV文件,
参数：
a:放置flv影片的元素ID号
b:flv影片的位置
p:其它的一些参数
*/
function playFlv(a,b,p){
	var defaults={
		width:500,
		height:400,
		player:"/script/flv.swf",
		vesi:"9.0.0",
		vars:{flvurl:b,vcastr_file:b,vcastr_title:''},
		para:{menu:false},
		attr:{}
	};
	if(p!=null){
		p.vars=$.extend({},defaults.vars,p.vars);
		p.para=$.extend({},defaults.para,p.para);
		p.attr=$.extend({},defaults.attr,p.attr);
	}
	var op=$.extend({},defaults,p);
	swfobject.embedSWF(op.player, a, op.width, op.height, op.vesi, "", op.vars, op.para, op.attr);
}

/*显示栏目用户投票*/
function showCatevalue(aim,cid){
	if($('#catevote_form').length<1){
		var edit=$('<div id="catevote_form"></div>').hide().appendTo(document.body);
		$.get('/vote/catevote_form.php',{cid:cid,isajax:1},
		function(data){
			$(document).mousedown(function(e){if($(e.target).parents().index(edit)<0){edit.hide();}});
			edit.html(data);
			edit.showE($(aim),1,1);
			edit.find('#catevote_button_ok').click(function(){edit.hide();});
		}); 
	}else{
		$('#catevote_form').showE($(aim),1,1);
	}
}

/*取得上级网站内容
	cid:栏目编号,
	p:页码,
	ps:每页显示的行数,
	sw:过滤的标题内容,
	fun:当取得数据时执行的函数,将传递内容结构值给fun
*/
(function($){
	$.fn.getcdinfo=function(p){
		var op=$.extend({},$.fn.getcdinfo.defaults,p);
		var $el=this;
		var $tf=op.fun?true:false;
		$.ajax({
			type:"GET",
			url:'http://www.chengdu.gov.cn/Interface/GovInfoOpens/infoList.jsp?ClassID='+op.cid+'&sw='+op.sw+'&p='+op.p+'&ps='+op.ps,
			success:function(xmldoc){
				var resu=[]; var i=0;
				$(xmldoc).find('record').each(function(){
					if($tf){
						resu[i]=xmlTovar($(this));
					}else{
						var val=xmlTovar($(this));
						resu[i]='<a href="'+val.classid+'">'+val.title+'</a>';
					}
				});
				if($tf){
					op.fun.call(this,resu);
				}else{
					resu=resu.join('');
					$el.html(resu);
				}
			}
		});
	};
	$.fn.getcdinfo.defaults={
		cid:0,
		p:0,
		ps:20,
		sw:'',
		fun:0
	};
})(jQuery);

/*将XML转换成数组变量*/
function xmlTovar(exml,r0){
	var va=[];
	var tmpchild=exml.children();
	for(var i=0;i<tmpchild.length;i++){
		var tc=tmpchild[i];
		if(!tc.firstChild){va[tc.tagName]="";}
		else if(tc.firstChild.nodeValue=="0" && r0){va[tc.tagName]="";}
		else{va[tc.tagName]=tc.firstChild.nodeValue;}	
	}
	return va;
};
function openwin(op){
	if(op.chk){
		height = screen.height;
		width = screen.width;
		if(width != op.w || height != op.h){
			if(!confirm("该系统是针对"+op.w+" x "+op.h+"的分辨率设计,你的系统分辨率为"+width+" x "+height+"。\n如果您确定要使用现在的屏幕分辨率，请点“确定”按钮。")){
				return false;
			}
		}
	}
	//window.open(op.url,'','status=no,width='+op.w+',height='+op.h+',left=0,top=0');
	if(op.w>0 || op.h>0){
		window.open(op.url,'','status=no,width='+op.w+',height='+op.h+',left=0,top=0');
	}else{
		window.open(op.url,'');
	}
}
