// 随机数发生器
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
}
function rand(number) {
	return Math.ceil(rnd()*number);
}

// 滚动widget
function simplescroll(c, config) {
	this.config = config ? config : {start_delay:3000, speed: 23, delay:1500, scrollItemCount:1};
	this.container = $i(c);
	this.pause = false;
	var _this = this;
	
	this.init = function() {
		_this.scrollTimeId = null;
		setTimeout(_this.start,_this.config.start_delay);
	}
	
	this.start = function() {
		var d = _this.container;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		if(d.scrollHeight-d.offsetHeight>=line_height) _this.scrollTimeId = setInterval(_this.scroll,_this.config.speed)
	};
	
	this.scroll = function() {
		if(_this.pause)return;
		var d = _this.container;d.scrollTop+=4;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		//alert(d.scrollTop + "%" + line_height + " : " + d.scrollTop%line_height);
		if(d.scrollTop%(line_height*_this.config.scrollItemCount)<=1){
			d.scrollTop=0;
			for(var i=0;i<_this.config.scrollItemCount;i++){d.appendChild(d.getElementsByTagName('li')[0]);}
			clearInterval(_this.scrollTimeId);
			setTimeout(_this.start,_this.config.delay);
		}
	}
	
	this.container.onmouseover=function(){_this.pause = true;}
	this.container.onmouseout=function(){_this.pause = false;}
}

// tab切换
function tabswitch(c, config){
	this.config = config ? config : {start_delay:3000, delay:1500};
	this.container = $i(c);
	this.pause = false;
	this.nexttb = 1;
	this.tabs = this.container.getElementsByTagName('dt');
	var _this = this;
	if(this.tabs.length<1)this.tabs = this.container.getElementsByTagName('li');
	for(var i = 0; i < this.tabs.length; i++){
		var _ec = this.tabs[i].getElementsByTagName('span');
		if(_ec.length<1)_ec = this.tabs[i].getElementsByTagName('a');
		if(_ec.length<1){
			_ec = this.tabs[i]
		}else{
			_ec = _ec[0];
		}
		_ec.onmouseover = function(e) {
			_this.pause = true;
			var ev = !e ? window.event : e;
			_this.start(ev, false, null);
		};
		
		_ec.onmouseout = function() {
			_this.pause = false;
		};
		
		try{
			$i(this.tabs[i].id + '_body_1').onmouseover = function(){
				_this.pause = true;
			};
			
			$i(this.tabs[i].id + '_body_1').onmouseout = function(){
				_this.pause = false;
			};
		}catch(e){}
	}
	
	if ($i('sts')) {
		var _sts = $i('sts');
		var _step = _sts.getElementsByTagName('li');
		_step[0].onclick = function() {
			if (_this.tabs[_this.tabs.length-1].className.indexOf('current') > -1) {
				_this.nexttb = _this.tabs.length + 1;
			};
			_this.nexttb = _this.nexttb - 2 < 1 ? _this.tabs.length : _this.nexttb - 2;
			//alert(_this.nexttb);
			_this.start(null, null, _this.nexttb);
		};
		
		_step[1].onclick = function() {
			_this.nexttb = _this.nexttb < 1 ? 1 : _this.nexttb;
			_this.start(null, null, _this.nexttb);
		};
	};
	
	this.start = function(e, r, n){
		if(_this.pause && !e)return;
		if(r){
			curr_tab = $i(_this.container.id + '_' + rand(4));
		}else{
			if(n){
				curr_tab = $i(_this.container.id + '_' + _this.nexttb);
			}else{
				curr_tab = _jsc.evt.gTar(e);
				if(curr_tab.id=="")curr_tab = curr_tab.parentNode;
			}
		}
		
		var tb = curr_tab.id.split("_");
		for(var i = 0; i < _this.tabs.length; i++){
			if(_this.tabs[i]==curr_tab){
				_this.tabs[i].className="hot Selected current";
				try{
					//alert(_this.tabs[i].id);
					$i(_this.tabs[i].id + '_body_1').style.display = "block";
				}catch(e){}
			}else{
				_this.tabs[i].className="";
				try{
					$i(_this.tabs[i].id + '_body_1').style.display = "none";
				}catch(e){}
			}
		}
		_this.nexttb = parseInt(tb[1]) >= _this.tabs.length ? 1 : parseInt(tb[1]) + 1;
	};
}

function multibanners(){
	this.i = 0;
	this.ul = $i('multi_banners');
	this.nav = $i('mb-nav');
	this.pause = false;
	this.lis = this.ul.getElementsByTagName('li');
	this.navs = this.nav.getElementsByTagName('li');
	var _this = this;
	
	this.sw = function(o){
		for(var i = 0; i < _this.lis.length; i++){
			_this.lis[i].className = '';
			_this.navs[i].className = '';
		}
		o.className = 'current';
		var _cp = parseInt(o.innerHTML);
		_this.lis[_cp-1].className='current';
		//_this.i = ++_cp % 2;
		//var navs = _this.navs;
		//setTimeout(function() {
		//	if(_this.pause)return;
		//	_this.sw(navs[++_this.i % 2]);
		//}, 7800);
		//if(_this.i>=8)_this.i=0;
	};
	
	this.init = function(instance_name){
		var lis = _this.lis;
		var navs = _this.navs;
		for(var i = 0; i < lis.length; i++){
			var _img;
			_img = lis[i].getElementsByTagName('img')[0];
			if(!_img)_img = lis[i].getElementsByTagName('object')[0];
			_img.onmouseover = function(){_this.pause=true};
			_img.onmouseout = function(){_this.pause=false};
			navs[i].onmouseover = function(e){
				_this.pause=true;
				var ev = !e ? window.event : e;
				_this.sw(_jsc.evt.gTar(ev));
			};
			navs[i].onmouseout = function(){
				_this.pause=false;
			};
		}
		_this.sw(navs[0]);
		setInterval(function() {
			if(_this.pause)return;
			_this.sw(navs[++_this.i % 3]);
		}, 4800);
	};
}

// accordion by nowa
function hslide(c){
	this.c = $i(c);
	this.b = $i('slide_body');
	this.h3s = this.c.getElementsByTagName('ul')[0].getElementsByTagName('h3');
	this.sliding = false;
	var _this = this;
	
	for(var i=0;i<this.h3s.length;i++){
		this.h3s[i].onclick = function(e){
			var ev = !e ? window.event : e;
			_this.slide(_jsc.evt.gTar(ev));
		};
	}
	
	this.slide = function(o){
		if(_this.sliding)return;
	
		var bleft = 0;
		var tleft = 0;
		var passed = false;
		var _tab;
		
		for(var i=0;i<_this.h3s.length;i++){
			if(_this.h3s[i]!=o && _this.h3s[i].parentNode.className=='current'){
				_tab = _this.h3s[i];
			}
		}
		
		try{
			var _tabb = $i(_tab.id + '_body');
			var anim = function(){
				_this.sliding = true;
            	n += 69;
            	if(n >= 367){
					_tabb.style.width = "0px";
            		_tabb.style.display = 'none';
            		_tab.parentNode.className = "";
            		window.clearInterval(tt);
					
					o.parentNode.className = 'current';
					var _tabb2 = $i(o.id + '_body');
					_tabb2.style.width = "0px";
					_tabb2.style.display = 'block';
					var anim2 = function(){
						z += 69;
						if(z >= 367){
							_tabb2.style.width = "376px";
							_this.sliding = false;
							window.clearInterval(tt2);
						}else{
							_tabb2.style.width = z + "px";
						}
					},z=0;
					var tt2 = setInterval(anim2, 30);
            	}else{
            		_tabb.style.width = (377 - n) + "px";
            	}
            },n=0;
            var tt = setInterval(anim, 30);
		}catch(e){}
	}
}

var querygg, ann_tab, banners, hero;

_jsc.util.addEvent(window, 'load', function() {
	
	hero = new tabswitch('hero', {});
	
	hero.start(null, null, 1);
});
