var xx = {
	//定时器
	slideTimer : -1,
	//变换时间间隔
	timerOut : 3000,
	//下一次开始位置
	currElem : 1,
	E : function( id )
	{
		return document.getElementById( id );
	},
	autoLoad : function()
	{
		xx.slide( xx.E( 'slideList' ), xx.E( 'leftBut' ), xx.E( 'rightBut' ), 'ddr2', [42,42,94,94], 'dd' );
	},
	/**
	 * var acElem		object	被操作dom元素
	 * var leftBut		object	左按钮dom元素
	 * var rightBut		object	右操作dom元素
	 * var currClass	string	被选中项的class
	 * var picAtt		array	图片的高度和宽度
	 */
	slide : function( acElem, leftBut, rightBut, currClass, picAtt, dd )
	{
		var picList = acElem.getElementsByTagName ( dd );
		if( picList.length <= 3 ) return;
		//播放
		var imgPlay = function()
		{
			for( var k = 0; k <= ( picList.length - 1 ); k++ )
			{
				if( k == xx.currElem )
				{
					picList[ k ].className = currClass;
					picList[ k ].getElementsByTagName( 'img' )[ 0 ].width = picAtt[ 2 ];
					picList[ k ].getElementsByTagName( 'img' )[ 0 ].height = picAtt[ 3 ];
				}
				else
				{
					picList[ k ].className = 'none';
					picList[ k ].getElementsByTagName( 'img' )[ 0 ].width = picAtt[ 0 ];
					picList[ k ].getElementsByTagName( 'img' )[ 0 ].height = picAtt[ 1 ];
				}
				picList[k].style.display = k < xx.currElem && k != (xx.currElem - 1) ? 'none' : '';
			}
			//清除定时器
			if( xx.slideTimer != -1 )	{	clearTimeout( xx.slideTimer );	xx.slideTimer = -1;	}
			//修正当前选中项
			xx.currElem++;
			xx.currElem = ( xx.currElem < 1 ) || ( xx.currElem >= ( picList.length - 1 ) ) ? 1 : xx.currElem;
			//定时器
			xx.slideTimer = setTimeout( imgPlay, xx.timerOut );
		}
		leftBut.onclick = function()
		{
			if( xx.currElem <= 2 )
			{
				xx.p( '已经到底了' );
				return;
			}
			if( xx.slideTimer != -1 )	{	clearTimeout( xx.slideTimer );	xx.slideTimer = -1;	}
			xx.currElem = xx.currElem - 2;
			xx.p( xx.currElem);
			imgPlay();
		}
		rightBut.onclick = function()
		{
			if( xx.currElem >= picList.length - 1 )
			{
				xx.p( '已经到头了' );
				return;
			}
			if( xx.slideTimer != -1 )	{	clearTimeout( xx.slideTimer );	xx.slideTimer = -1;	}
			xx.currElem = xx.currElem;
			xx.p( xx.currElem );
			imgPlay();
		}

		//定时器
		xx.slideTimer = setTimeout( imgPlay, xx.timerOut );
	},
	p : function( i )
	{
		try{
			//console.debug( i );
		}
		catch( e )
		{
			alert( e.message );
		}
	}
};


//自动载入
window.onload = xx.autoLoad;
