var timer=null;

var t_idx=0;

function Testimonial(text,person)
{
	this.Text=text;
	this.Person=person;
}


var testmonials=[new Testimonial('Good speakers generally and good networking.','Ross Matthews, Starr Underwriting Agents'),new Testimonial('We have learned a lot from regulators and business managers in China market.','Cunqiang Li, Massmutual'),new Testimonial('Interesting and a generally informative event.','Ross Bondey, Whittington Group'),new Testimonial('Enough breaks for networking.','Dirvi Viamutzum, Siemens'),new Testimonial('Good show by the organizers who seem to be young & committed.','Ravi Naidu, Sun RE'),new Testimonial('It was very interesting.','Thibaus Hervy, HCC Global Finance Products')];

$(function(){
	$('#nav .header').hover(
		function (){
			$('*',$('#s_ChildMenu')).remove();
			$('ul',this).clone().appendTo($('#s_ChildMenu'));
		},
		function (){}
	);
	$('#s_ChildMenu').bind('mouseleave',function(){
		//timer=setTimeout('HideChildMenu',1000);
		HideChildMenu()
	}).bind('mousein',function(){
		clearTimeout(timer);
	});
	//var c = readCookie('style');
	//if (c) switchStyle(c);
	
	//SwitchPhoto(photos,6);
	SwitchTml(testmonials);


});
function SwitchPhoto(ptos,num)
{
	$('*','#speakersBox').remove();
	var brk=p_idx;
	for(var i=0;i<num;i++)
	{
		$('#speakersBox').append('<img src="'+ptos[p_idx].Path+'" title="'+ptos[p_idx].Title+'" />')
		if((p_idx-brk)<num)
		{
			p_idx++;
		}
		if(p_idx>=ptos.length){p_idx=0;}
	}
	setTimeout('SwitchPhoto(photos,6)',5000);
}

function SwitchTml(tmls)
{
	$('*','#s_Tml').remove();
	$('#s_Tml').append('<span class="tml_text"><img src="Style/default/images/left_mark.png" />'+tmls[t_idx].Text+'<img src="Style/default/images/right_mark.png" /></span>'+'<span class="tml_psn">-- '+tmls[t_idx].Person+'</span>')
	t_idx++;
	if(t_idx>=tmls.length){t_idx=0;}
	setTimeout('SwitchTml(testmonials)',5000);
}
function HideChildMenu()
{
	$('ul',$('#s_ChildMenu')).hide(1000,function(){$(this).remove()});
}
function switchStyle(styleName)
{
	$('link').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style',styleName,365);
}
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


//定义一维数组 
function MArray(len){ 
this.length = len; 
for(i=1;i<=len;i++) this[i] = 0; 
return this; 
} 
//创建数组 
var strarray = new MArray(5) ;
var AllTabs="";
var current=1;
var next=2;
var Switching=null;

$( function(){ 
	var n=1;
	$('li','#myTabs').each(function(){
		strarray[n]=$(this).attr('id');
		AllTabs+="#"+$(this).attr('id')+",";
		n++;
	})
	ShowTabBodyByIndex(1);
	//StartSwitching();
	$('li','#myTabs').click(function(){
//		var ct=$(this).attr('id');
//		$('div','#myTabs').hide();
//		$("#"+ct+'_body').show();
		ShowTabBody($(this).attr('id'));
		//Stop();
	}).mouseout(function(){
		//StartSwitching();
	})
	$('div','#myTabs').mouseover(function(){
		//Stop();
	}).mouseout(function(){
		//StartSwitching();
	})
	
})
function ShowTabBody(tabname)
{
	$('div','#myTabs').hide();
	$('#'+tabname+'_body').show();	
	SetTabStyle(tabname);
}
function ShowTabBodyByIndex(index)
{
	$('div','#myTabs').hide();
	$('#'+strarray[index]+'_body').show();
	SetTabStyleByID(index);
	current=index;
}
function StartSwitching()
{
	Switching=setInterval('Next()',2000);
}
function Next()
{
	if(current<strarray.length)
	{
		next=current+1;
		ShowTabBodyByIndex(next);
	}
	else
	{
		next=1;
		ShowTabBodyByIndex(next);
	}
	
}
function Stop()
{
	if(Switching!=null)
	{
		clearInterval(Switching);
		Switching=null;
	}
}
function SetTabStyleByID(index)
{
	//alert($('#'+strarray[index]).html());
	$('a',AllTabs).css({backgroundPosition: '0% 0px'});
	$('span',AllTabs).css({backgroundPosition: '100% 0px'});
	$('a','#'+strarray[index]).css({backgroundPosition: '0% -42px'});
	$('span','#'+strarray[index]).css({backgroundPosition: '100% -42px'});
	$('a',AllTabs).css({color: '#666'});
	$('a','#'+strarray[index]).css({color: '#FFF'});
}
function SetTabStyle(tabname)
{
	$('a',AllTabs).css({backgroundPosition: '0% 0px'});
	$('span',AllTabs).css({backgroundPosition: '100% 0px'});
	$('a','#'+tabname).css({backgroundPosition: '0% -42px'});
	$('span','#'+tabname).css({backgroundPosition: '100% -42px'});
	$('a',AllTabs).css({color: '#666'});
	$('a','#'+tabname).css({color: '#FFF'});
}
