var els = new Array();
var max = null;
var timer = null;
var offset = 5000;
var index = -1;

$(function(){
	$('#pic div.ele').each(function(){
		els.push(this.id);
	});
	max = els.length;
	hook_scroll();
	auto();	
});

function auto(){
	index++;
	if(index > (max - 1)){
		index = 0;
	}
	slide(index);
	timer = window.setTimeout(auto,offset);
}

function slide(i){
	var id = els[i];
	judge(i, '/images/cms/design/10_peoples/icon_scrollnav_hover.gif');
	$('#'+id)
		.animate({opacity:1},800).show()
		.siblings('div:visible')
		.animate({opacity:0},800).hide();
}

function hook_scroll(){
	$('a.dobtn').bind('click',function(){
		var name = this.name;
		if(timer){
			clearTimeout(timer);
		}
		if(name == 'p'){
			index--;
			if(index < 0) index = max - 1;
		}else{
			index++;
			if(index > (max - 1)) index = 0;
		}
		slide(index);
		timer = window.setTimeout(auto,offset);
		return false;
	});
}

function judge(num, address) {
	defaultBtnBg();
	num += 1;
	switch(num) {
		case 1:
			$('.firstSlide').attr('src', address);
			break;
		case 2:
			$('.secondSlide').attr('src', address);
			break;
		case 3:
			$('.thirdSlide').attr('src', address);
			break;	
		case 4:
			$('.fourthSlide').attr('src', address);
			break;
		case 5:
			$('.fifthSlide').attr('src', address);
			break;
	}
}
function defaultBtnBg() {
	$('.scrollnav img').attr('src', '/images/cms/design/10_peoples/icon_scrollnav.gif');
}


