// JavaScript Document
////////////////////////////////////////////////////////////
// 
var g_ip_btnidhead		= "id_ip_btn";	
var g_ip_tabidhead		= "id_ip_table";
 
var g_ip_tabnumber		= 4;
var g_ip_btncls_seled		= "nav_button_1";
var g_ip_btncls_normal	= "nav_button_0";
var g_ip_DuringTime		= 5*400;	// 自动翻页时的停留时间，单位：毫秒
var g_ip_CurrTable		= 0;
var g_ip_PlayStep		= 1;
var g_ip_TimerId		= 0;
var g_ip_IsUserClick		= false;
var g_ip_PlayStop		= false;
var g_ip_FreezingTime		= 10*1000;	// 用户点了一个后的停留时间，单位：毫秒
 
 
// 定位 BUTTON
function ip_SetBtnPos()
{
	var oip_btn = document.getElementById( "id_indexplayer_button" );
	var oip_div = document.getElementById( "id_indexplayer_div" );
	if ( oip_btn && oip_div )
	{
		oip_btn.style.top = oip_div.style.top - -8;
	}
}
function ip_ge(strid)
{
	return document.getElementById(strid);
}
function ip_onipmover(o)
{
	if ( g_ip_btncls_seled != o.className )
	{
		o.className = g_ip_btncls_seled;
	}
}
function ip_onipmout(o)
{
	var oBtn = ip_ge( g_ip_btnidhead + g_ip_CurrTable );
 
	if ( oBtn )
	{
		if ( o.id != oBtn.id )
			o.className = g_ip_btncls_normal;
	}
}
function ip_setstop(bstop)
{
	var oimg = ip_ge( "id_ip_btn_img_p" );
	if ( oimg )
	{
		if ( bstop )
		{
			g_ip_PlayStop = true;
		}
		else
		{
			g_ip_PlayStop = false;
		}
 
	}
 
}
function ip_OnBtnClick( nid )
{
	g_ip_CurrTable = nid;
	ip_setstop( false );
	g_ip_PlayStep = 0;
	window.clearTimeout( g_ip_TimerId );
	ip_CallbackTimer();
}
function ip_OnUserPlayClick( nAct )
{
	g_ip_IsUserClick	= true;
 
	if ( nAct < 0 )
	{
		ip_setstop( false );
		g_ip_PlayStep = -1;
		ip_CallbackTimer();
	}
	else if ( 0 == nAct )
	{
		ip_setstop( ! g_ip_PlayStop );
		window.clearTimeout( g_ip_TimerId );
		g_ip_TimerId = window.setTimeout( "ip_CallbackTimer();", g_ip_DuringTime );
	}
	else if ( nAct > 0 )
	{
		ip_setstop( false );
		g_ip_PlayStep = 1;
		ip_CallbackTimer();
	}
}
function ip_CallbackTimer()
{
	if ( g_ip_PlayStop )
	{
		window.clearTimeout( g_ip_TimerId );
		return;
	}
 
	var i			= 0;
	var oTab		= null;
	var oBtn		= null;
 
	g_ip_CurrTable += g_ip_PlayStep;
	g_ip_PlayStep = 1;
 
	if ( g_ip_CurrTable > g_ip_tabnumber )
		g_ip_CurrTable = 1;
	if ( g_ip_CurrTable < 1 )
		g_ip_CurrTable = g_ip_tabnumber;
 
	for ( i = 1; i <= g_ip_tabnumber; i ++ )
	{
 
 
		oTab = ip_ge( g_ip_tabidhead + i );
		if ( oTab )
			oTab.style.display = "none";
		oBtn = ip_ge( g_ip_btnidhead + i );
 
		if ( oBtn )
			oBtn.className = g_ip_btncls_normal;
	}
	oTab = ip_ge( g_ip_tabidhead + g_ip_CurrTable );
	if ( oTab )
		oTab.style.display = "";
	oBtn = ip_ge( g_ip_btnidhead + g_ip_CurrTable );
	if ( oBtn )
		oBtn.className = g_ip_btncls_seled;
 
	if ( g_ip_IsUserClick )
	{
		g_ip_IsUserClick = false;
		window.clearTimeout( g_ip_TimerId );
		g_ip_TimerId = window.setTimeout( "ip_CallbackTimer();", g_ip_FreezingTime );
 
 
	}
	else
	{
		g_ip_TimerId = window.setTimeout( "ip_CallbackTimer();", g_ip_DuringTime );
	}
}
 
function ip_PlayStart()
{
	ip_SetBtnPos();
	ip_CallbackTimer();
}
 
document.onload = ip_PlayStart();
