function TabPager(tabs, tabtype, clients, opt){
	this.tabs = document.getElementById(tabs);
	this.tabtype = tabtype;
	this.timer = 0;
	this.a = 1;

	if(opt.autoChange){
		this.autoChange = opt.autoChange;
	}else{
		this.autoChange = false;
	}

	if(opt.imgChange){
		this.imgChange = opt.imgChange;
	}else{
		this.imgChange = false;
	}

	if(opt.arr){
		this.arr = opt.arr;
	}else{
		this.arr = null;
	}

	var that = this;
	this.enable = function (start){
		if(that.disabled && start){
			that.disabled = false;
		}
		if(!that.disabled){
			if(that.autoChange){
				that.caller(true);
			}
		}
	}

	this.disable = function (stop){
		if(that.timer){
			clearTimeout(that.timer);
			that.timer = 0;
		}

		if(stop){
			if(that.disabled){
				that.enable(true);
			}else{
				that.disabled = true;
			}
		}
	}

	this.changePage = function (){
		if(arguments.length > 0){
			that.n = arguments[0];
		}

		if(that.n < 0){
			that.n = that.total - 1;
		}else if(that.n >= that.total){
			that.n = 0;
		}

		var reg = new RegExp(that.tabtype, 'i');
		var tablist = that.tabs.getElementsByTagName(tabtype);
		var j = 0;
		for(var i = 0; i < tablist.length; i++){
			var tab = tablist[i];
			if(tab.tagName && reg.test(tab.tagName) && tab.innerHTML){
				if(j == that.n){
					tab.className = tab.className.match('hot') ? tab.className : tab.className + ' hot';
				}else{
					tab.className = tab.className.replace(/ ?hot/, '');
				}
				j++;
			}
		}

		if(that.imgChange){
			if(that.arr[that.n].map){
				that.clients.childNodes[0].useMap = that.arr[that.n].map;
				that.clients.childNodes[0].src = that.arr[that.n].img;
				that.clients.childNodes[0].alt = that.arr[that.n].alt;
			}else{
				that.clients.childNodes[0].href = that.arr[that.n].lnk;
				that.clients.childNodes[0].title = that.arr[that.n].title;
				that.clients.childNodes[0].childNodes[0].src = that.arr[that.n].img;
				that.clients.childNodes[0].childNodes[0].alt = that.arr[that.n].alt;
			}
		}
		else
		{
			j = 0;
			for(var i = 0; i < that.clients.childNodes.length; i++){
				var client = that.clients.childNodes[i];
				if(client.tagName){
					client.style.display = (j == that.n ? '' : 'none');

					var classTemp = client.className.split(' ');
					for (k = 0; k < classTemp.length; k++){
						if(m = classTemp[k].match(/^(.*)_hidden$/)){
							classTemp[k] = m[1];
						}
					}
					client.className = classTemp.join(' ');

					if(j == that.n && that.arr){
						var imgs = client.getElementsByTagName('img');

						for(var k = 0; k < imgs.length; k++){
							if(!imgs[k].src || imgs[k].src.match('space.gif')){
								imgs[k].src = that.arr[j][k];
							}
						}
					}

					j++;
				}
			}
		}
	}

	this.caller = function (){
		if(that.timer){
			clearTimeout(that.timer);
			that.timer = 0;
		}

		if(!arguments[0]){
			that.n += that.a;
			that.changePage();
		}

		that.timer = setTimeout(that.caller, 3000);
	};

	var reg = new RegExp(this.tabtype, 'i');
	var k = 0, tab, oldonmouseover;
	var tablist = this.tabs.getElementsByTagName(tabtype);
	for(var i = 0; i < tablist.length; i++){
		tab = tablist[i];
		if(tab.tagName && reg.test(tab.tagName) && tab.innerHTML){
			if(tab.onmouseover){
				oldonmouseover = tab.onmouseover;
			}
			eval('tab.onmouseover = function (){' + (tab.onmouseover ? 'oldonmouseover();' : '') + 'that.disable();that.changePage(' + k +  '); }');
			tab.onmouseout = this.enable;
			k++;
		}
	}

	if(opt.clientEvent)
	{
		k = 0;
		var clientslist = document.getElementById(clients).childNodes;
		for(var i = 0; i < clientslist.length; i++){
			var client = clientslist[i];
			if(client.tagName){
				if(client.onmouseover){
					oldonmouseover = client.onmouseover;
				}
				eval('client.onmouseover = function (){' + (client.onmouseover ? 'oldonmouseover();' : '') + 'that.disable();that.changePage(' + k +  '); }');
				client.onmouseout = this.enable;
				k++;
			}
		}
	}

	this.total = k;
	this.n = 0;

	this.clients = document.getElementById(clients);
	this.clients.onmouseover = this.disable;
	this.clients.onmouseout = this.enable;

	if(this.autoChange){
		this.caller(true);
	}
}

function Scroller(id)
{
	var debug = true, timer;

	//Build wrapper
	var outer = document.getElementById(id), wrapper;
	if(!outer && debug){
		alert('Wrapper is not defined!');
	}

	//Initialize configuration
	//others: blockWidth, blockHeight
	var cfg;
	if(arguments.length < 2)
	{
		cfg = {};
	}
	else
	{
		cfg = arguments[1];
	}

	if(cfg.wrapper){
		wrapper = document.getElementById(cfg.wrapper);
	}

	//Direction: 0-left, 1-right, 2-up, 3-down
	if(!cfg.direction){
		cfg.direction = 0;
	}

	if(!cfg.period){
		cfg.period = 50;
	}

	if(!cfg.interval){
		cfg.interval = 1000;
	}

	if(!cfg.speed){
		cfg.speed = 1;
	}

	if(cfg.direction < 2 && !cfg.innerWidth){
		if(cfg.blockWidth){
			cfg.innerWidth = outer.clientWidth + cfg.blockWidth * 2;
		}else{
			cfg.innerWidth = 5000;
		}
	}

	this.cfg = cfg;

	//Build inner wrapper
	var inner = document.createElement('div');
	if(cfg.innerWidth){
		inner.style.width = cfg.innerWidth + 'px';
	}
	if(wrapper){
		outer.appendChild(inner);
		inner.appendChild(wrapper);
	}else{
		wrapper = inner;
		inner.innerHTML = outer.innerHTML;
		outer.innerHTML = '';
		outer.appendChild(inner);
	}

	if(inner.offsetWidth < outer.clientWidth){
		return;
	}

	//Assign event
	var scroll = function(){
		switch(cfg.direction){
		case 0:
			if(outer.scrollLeft < cfg.blockWidth){
				outer.scrollLeft += cfg.speed;
			}else{
				var c = wrapper.childNodes;
				for(var i = 0; i < c.length; i++){
					if(c[i].tagName){
						wrapper.appendChild(c[i]);
						break;
					}
				}
				outer.scrollLeft -= cfg.blockWidth;
			}
			break;
		case 1:
			if(outer.scrollLeft > 0){
				outer.scrollLeft -= cfg.speed;
			}else{
				var c = wrapper.childNodes;
				for(var i = c.length - 1; i >= 0; i--){
					if(c[i].tagName){
						for(var j = 0; j < c.length; j++){
							if(c[j].tagName){
								wrapper.insertBefore(c[i], c[j]);
								break;
							}
						}
						break;
					}
				}
				outer.scrollLeft += cfg.blockWidth;
			}
			break;
		case 2:
			if(cfg.blockHeight){
				if(outer.scrollTop < cfg.blockHeight){
					outer.scrollTop += cfg.speed;
				}else{
					var c = wrapper.childNodes;
					for(var i = 0; i < c.length; i++){
						if(c[i].tagName){
							wrapper.appendChild(c[i]);
							break;
						}
					}
					outer.scrollTop -= cfg.blockHeight;
				}
			}else{
				var c = wrapper.childNodes;
				for(var i = 0; i < c.length; i++){
					if(c[i].tagName){
						//alert(c[i].offsetHeight + c[i].tagName);
						if(outer.scrollTop < c[i].offsetHeight){
							outer.scrollTop += cfg.speed;
						}else{
							for(var i = 0; i < c.length; i++){
								if(c[i].tagName){
									wrapper.appendChild(c[i]);
									break;
								}
							}
							outer.scrollTop -= cfg.blockHeight;
						}
						break;
					}
				}
			}
			break;
		case 3:
			if(outer.scrollTop > 0 || !cfg.blockHeight){
				outer.scrollTop -= cfg.speed;
			}else{
				var c = wrapper.childNodes;
				for(var i = c.length - 1; i >= 0; i--){
					if(c[i].tagName){
						for(var j = 0; j < c.length; j++){
							if(c[j].tagName){
								wrapper.insertBefore(c[i], c[j]);
								break;
							}
						}
						break;
					}
				}
				outer.scrollTop += cfg.blockHeight;
			}
			break;
		}
		if(!cfg.disabled){
			if(cfg.direction == 0 && cfg.blockWidth && outer.scrollLeft == 0){
				timer = setTimeout(scroll, cfg.interval);
			}else if(cfg.direction == 1 && cfg.blockWidth && outer.scrollLeft == 0){
				timer = setTimeout(scroll, cfg.interval);
			}else if(cfg.direction == 2 && cfg.blockHeight && outer.scrollTop == 0){
				timer = setTimeout(scroll, cfg.interval);
			}else if(cfg.direction == 3 && cfg.blockHeight && outer.scrollTop == 0){
				timer = setTimeout(scroll, cfg.interval);
			}else{
				timer = setTimeout(scroll, cfg.period);
			}
		}else{
			timer = false;
		}
	}

	outer.onmouseover = function (){
		cfg.disabled = true;
	};
	outer.onmouseout = function (){
		cfg.disabled = false;
		if(!timer){
			timer = setTimeout(scroll, cfg.period);
		}
	};

	//Start scrolling
	if(!cfg.disabled){
		timer = setTimeout(scroll, cfg.period);
	}
}

function changeMenu(){
	var menu1 = document.getElementById('menu1');
	var menu2 = document.getElementById('menu2'), menu2Children = new Array;
	var menu, submenu, i, j = 0, t, l;

	for(i = 0; i < menu2.childNodes.length; i++){
		if(menu2.childNodes[i].tagName){
			menu2Children.push(menu2.childNodes[i]);
		}
	}

	var menuleft = 0;
	for(i = 0; i < menu1.childNodes.length; i++){
		if(menu1.childNodes[i].tagName){
			menu = menu1.childNodes[i];
			submenu = menu2Children[j];
			t = submenu.style.display;
			submenu.style.display = '';
			l = parseInt(menuleft + menu.offsetWidth * 0.5 - submenu.offsetWidth / 2);
			submenu.style.display = t;
			if(l > 0){
				submenu.style.left = (l + 17) + 'px';
			}
			if(menu.getElementsByTagName('a')[0].href == '' && submenu.getElementsByTagName('a').length > 0){
				menu.getElementsByTagName('a')[0].href = submenu.getElementsByTagName('a')[0].href;
			}
			j++;
			menuleft += menu.offsetWidth;
		}
	}
}
