window.$ = function(objid){
	return document.getElementById(objid);
}
String.prototype.inc=function(s){
	return this.indexOf(s)>-1?true:false;
}

function picshow(name,boxid,unitstr,items,steptime,divisor,width,height,display){
	var container = $(boxid);
	var itemObjs = new Array();
	var toDisplay = display;
	var isInit = false;
	var Handle = null;//handle = setTimeout...
	var handlet = null;
	this.Init = function()
	{
		IsInit = false;
		if (items.length == 0) return
		if (!container) return 
		
		//clear childNodes
		while (container.childNodes.length > 0) container.removeChild(container.childNodes[0]);
		container.style.width = (items.length * width)+'px';
		container.style.left = -(width*display)+'px'
		for(var i = 0,re; i < items.length; i++)//create all nodes
		{
			itemObjs[i] = document.createElement("div");
			//恶心的兼容
			itemObjs[i].style.styleFloat = 'left';
			itemObjs[i].style.cssFloat = 'left';
			
			itemObjs[i].style.overflow = 'hidden';
			itemObjs[i].style.width = width + 'px';
			itemObjs[i].style.height = height + 'px';
			var tempstr = unitstr;
			for (var j=0; j < items[i].length; j++)
			{
				re = new RegExp('\\{' + j + '\\}', 'g');
				tempstr = tempstr.replace(re, items[i][j]);
			}
			itemObjs[i].innerHTML = tempstr;
			container.appendChild(itemObjs[i]);
		}
		//alert(container.innerHTML)
		IsInit = true;
	}
	this.Move = function()
	{
		var curleft = Math.abs(parseInt(container.style.left));
		var step = (toDisplay*width - curleft) / divisor;
		
		if (IsInit)
		{
			var done = false;
			var movement = Math.round(step);
			if (Math.abs(movement)<1)
			{
				movement = toDisplay*width - curleft;
				done = true;
			}			
			container.style.left = -(curleft + movement) + 'px';
			if (!done){
				try{
					clearInterval(handlet);
				}catch(e){
					//do...
				}
				clearTimeout(handlet);
				handlet = setTimeout(name + '.Move();',steptime);//继续移动
			}
			else{
				clearTimeout(handlet);
				handlet = setTimeout(name + '.Next();',7000);//滚动到下一个
			}
		}
	}

	this.Next = function(){
		toDisplay++;
		clearTimeout(handlet);
		if (toDisplay>items.length-1) toDisplay = 0
		this.Move()
	}
	this.Previous = function(){
		toDisplay--;
		clearTimeout(handlet);
		if (toDisplay<0) toDisplay = items.length-1
		this.Move()
	}
	this.Init();
	handlet = setTimeout(name + '.Next();',7000);//开始滚动
}

window.onload = function(){//初始化事件处理||表单悬停||导航悬停
	try{
		$("login").onmouseover  =function(){
			this.src = "/boao/login_hover.png";
		}
		$("register").onmouseover  =function(){
			this.src = "/boao/register_hover.png";
		}
		$("login").onmouseout  =function(){
			this.src = "/boao/login_default.png";
		}
		$("register").onmouseout  =function(){
			this.src = "/boao/register_default.png";
		}
	}catch(e){
		//do nothing 已经登录
	}
		
	$("searchbox").onclick = function(){
		if ($('inputkeyword').value!=''){ 
			$('searchform').submit();
		}
	}
	$("searchbox").onmouseover = function(){
		for (var iiii=0;iiii<this.childNodes.length;iiii++){
			if (this.childNodes[iiii].tagName == "IMG") this.childNodes[iiii].src = "/boao/search_over.png"
		}
	}
	$("searchbox").onmouseout = function(){
		for (var iiiii=0;iiiii<this.childNodes.length;iiiii++){
			if (this.childNodes[iiiii].tagName == "IMG") this.childNodes[iiiii].src = "/boao/search_default.png"
		}
	}
		
	$("broadcastimg").onclick = function(){
		//do nothing
	}
	$("broadcastimg").onmouseover = function(){
		this.src="/boao/broadcast_over.png";
	}
	$("broadcastimg").onmouseout = function(){
		this.src="/boao/broadcast_default.png";
	}
	/*try
	{
		$("navgame").onclick = function(){
			//do nothing
		}
		$("navgame").onmouseover = function(){
			this.src="/boao/gameover.png";
		}
		$("navgame").onmouseout = function(){
			this.src="/boao/game.png";
		}
		$("navtech").onclick = function(){
			//do nothing
		}

		$("navtech").onmouseover = function(){
			this.src="/boao/techover.png";
		}
		$("navtech").onmouseout = function(){
			this.src="/boao/tech.png";
		}

		$("navmovie").onclick = function(){
			//do nothing
		}
		$("navmovie").onmouseover = function(){
			this.src="/boao/movieover.png";
		}
		$("navmovie").onmouseout = function(){
			this.src="/boao/movie.png";
		}

		$("navmusic").onclick = function(){
			//do nothing
		}
		$("navmusic").onmouseover = function(){
			this.src="/boao/musicover.png";
		}
		$("navmusic").onmouseout = function(){
			this.src="/boao/music.png";
		}

		$("navarts").onclick = function(){
			//do nothing
		}
		$("navarts").onmouseover = function(){
			this.src="/boao/artsover.png";
		}
		$("navarts").onmouseout = function(){
			this.src="/boao/arts.png";
		}
		$("navwater").onclick = function(){
			//do nothing
		}
		$("navwater").onmouseover = function(){
			this.src="/boao/waterover.png";
		}
		$("navwater").onmouseout = function(){
			this.src="/boao/water.png";
		}
	}catch (e){
			//do nothing
	}*/
}
