$import('../js/ui.js');
Object.extend('Tabber.prototype',{
	initialize:function(id,options){
		var t = this;
		t.options = options;
		t.__id = '#'+id;
		t.active = options.active;
		$(t.__id+' a').css({cursor:'pointer'})[options.eventType](function(){t.setActive(this)});
	},
	setActive:function(column){
		var tabber = $(column);
		var item = $('for_'+column.id);
		$.addClass(this.active.column,'');
		$.hide(this.active.item);
		$.addClass(column,'active');
		$.show(item);
		this.active = {column:column,item:item};
	}
});

/**
 * 导航条
 */
Object.extend('tomatolei.searchTabber',{
	active:null,
	initialize:function(){
		var t = this;
		t.active={tabber:$('tabber_page'),search:$('search_page')};
		this.setActive(t.active.tabber);
		$('#t_tabber a').click(function(){t.setActive(this)});
		this.addLinksHref();
		$('#top .t_keyword').mouseover(function(){this.select();this.focus();});
		$('.button input').mouseover(function(){this.className='t_active'}).mouseout(function(){this.className='t_enter'});
		$('#top form').attr('onsubmit',this.doSearch);
	},
	setActive:function(tabber){
		var tabber = $(tabber);
		var name = tabber.id.split('_')[1];
		var search = $('search_'+name);
		$.addClass(this.active.tabber,'');
		$.hide(this.active.search);
		$.addClass(tabber,'active');
		$.show(search);
		var links = $.find(search,'.links').last();
		var list = $.find(links,'a').elements;
		$('#search_' +name+' .t_keyword').attr('value',list[Math.floor(Math.random()*list.length)].innerHTML);
		if(!tabber.marquee)tabber.marquee=new Marquee(links,0,1,520,22,50,4000,500);
		this.active = {tabber:tabber,search:search};
	},
	addLinksHref:function(){
		$('.t_search .links a').each(function(o){
			var node = o;
			for(var i=0;i<4;i++){node=$.parent(node).last()}
			var textbox = $.find(node,'.t_link').last();
			o.href.indexOf(document.domain)>-1?o.href=textbox.value+encodeURIComponent($.html(o)):'';
		});
	},
	doSearch:function(){
		var searchCode = "",self=this;
		['link','keyword'].each(function(i){searchCode+= $.find(self,'.t_'+i).attr('value')});
		var last=searchCode.split('&'),item = last[last.length-1]
		window.open(searchCode.substring(0,searchCode.lastIndexOf('=')+1)+encodeURIComponent(item.split('=')[1]));
		return false;
	}
});

/**
 * 轮换广告.
 */
Object.extend('tomatolei.rollAd',{
	options:{width:'100%',height:'100%',pauseTime:1,isShowText:1,textColor:'000',bgColor:'ddd',src:'images/focus.swf'},
	items:[
		{img:'images/img/adimg_1.jpg',link:'http://www.ccydt.com',text:''},
		{img:'images/img/adimg_2.jpg',link:'/jkzj.php',text:''},
		{img:'images/img/adimg_3.jpg',link:'/wsgh/',text:''},
		{img:'images/img/adimg_4.jpg',link:'/jkzj.php',text:''},
		{img:'images/img/adimg_5.jpg',link:'/jkzj.php',text:''}
	],
	initialize:function(id,options){
		var elem = $('#upside .ad li').last();
		Object.extend(this.options,options||{});
		if(elem)this.addEmbed(elem);
	},
	addEmbed:function(parent){
		var itemsStr={imgs:'',texts:'',links:''},flashVars = "";
		this.items.each(function(o){Object.each(o,function(t,o){itemsStr[t+'s']+='|'+o})});
		['img','link','text'].each(function(i){flashVars+=i+'s='+itemsStr[i+'s'].slice(1)+'&';});
		Object.each(this.options,function(key,value){flashVars+=key+'='+value+'&'});
		parent.innerHTML='<embed flashvars="'+flashVars+'" width="'+this.options.width+'" height="'+this.options.height+'" ' +
						 'src="'+this.options.src+'" type="application/x-shockwave-flash"></embed>';
	}
});

/**
 * 天气
 */
Object.extend('tomatolei.weather',{
	initialize:function(){
		this.setCityID(clientIp);		
	},
	setCityID:function(clientCity){
		var id=0;
			Object.each(city,function(name,value){
				Object.each(value,function(name,value){if(clientCity.indexOf(name)>0&&!id)id=value;});
				if(clientCity.indexOf(name)>0&&!id)id=value['_'];
			});
			if(id)this.loadScript("/minisite_"+id+".js",this.setImage.bind(this));
	},
	loadScript:function(url,caller){
		
		var script = $.append(document.body,'script').attr('src',url).last();
		$.ie?script.onreadystatechange=function(){if(this.readyState=='loaded'||this.readyState=='complete')caller()}:script.onload=function(){caller()};
	},
	setImage:function(){	
		try{
			var list = __minisite__weather__.split(' '),url=0;
			weather_value.each(function(item){if(item[0]==list[2]&&!url)item[1]});
			if(!url)list[2].split(goto_value).each(function(value){weather_value.each(function(item){if(item[0]==value)url=item[1]})});
			var url = url || weather_value[weather_value.length-1][1];
			$.imageAlpha($('#t_w_img a').last(),'/img/weather/'+url+'.png');
			$.html($('t_w_city'),list[0]);
			$.html($('t_w_text'),list[1]+' '+list[2]);
		}catch(e){};
	}
});

/* 初始化 */
$.ready(function(){	
	tomatolei.searchTabber.initialize();
	if(!$('news_title').tagName)return;/*当为子页面时返回*/
	tomatolei.rollAd.initialize()
	new Tabber('news_title',{active:{column:$('nt_1'),item:$('for_nt_1')},eventType:'mouseover'});
	new Tabber('game_column',{active:{column:$('gc_1'),item:$('for_gc_1')},eventType:'mouseover'});
	new Tabber('bbs_article',{active:{column:$('art1'),item:$('for_art1')},eventType:'mouseover'});
	new Tabber('textAd_title',{active:{column:$('ta_t_1'),item:$('for_ta_t_1')},eventType:'mouseover'});
});

/* 会员登录 */
function loging(titod) {
if (titod.usname.value==""){
alert("请输入用户名！");
return false;
}
if (titod.passwd.value==""){
alert("请输入密码！");
return false;
}
}
/* 打开新窗口 */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}