// config
var homeScrollerStatus = {
	pause: 0,
	play:  1
}
var homeScroller = {};
// next
function homeScroller_next(){
	// hide the current index; hax to actually hide all :]
	homeScroller['elements'].hide();
	// show the next one
	homeScroller['index']++;
	if(homeScroller['index'] == homeScroller['elements'].length) homeScroller['index'] = 0;
	$(homeScroller['elements'][homeScroller['index']]).show();
	homeScroller_update();
}
// previous
function homeScroller_previous(){
	// hide the current index; hax to actually hide all :]
	homeScroller['elements'].hide();
	// show the next one
	homeScroller['index']--;
	if(homeScroller['index'] < 0) homeScroller['index'] = homeScroller['elements'].length - 1;
	$(homeScroller['elements'][homeScroller['index']]).show();
	homeScroller_update();
}
// update
function homeScroller_update(){
	// set selected class for current index
	$('#home .buttons a.selected').removeClass('selected');
	$($('#home .buttons a')[homeScroller['index']]).addClass('selected');
}
// function autoScroll
function homeScroller_autoScroll(){
	if(homeScroller['status'] == homeScrollerStatus.pause){
		// doNothing();
	}else{
		homeScroller_next();
	}
}
// init
$(function(){
	homeScroller['elements'] = $('.testimonial div.ftwffs');
	homeScroller['count']    = homeScroller['elements'].length;
	homeScroller['index']    = 0;
	homeScroller['status']   = homeScrollerStatus.play;
	// create links
	$('#home div.buttons').html('');
	for(var i = 0; i < homeScroller['elements'].length; ++i){
		var a = document.createElement('a');
		a.href = '#';
		a.innerHTML = i + 1;
		$('#home div.buttons').append(a);
		a = null;
	}
	$('#home .buttons a').live('click', function(){
		var idxNow = homeScroller['index'];
		var idxNew = parseInt(this.innerHTML) - 1;
		if(idxNow != idxNew){
			if(idxNew == 0){ homeScroller['index'] = homeScroller['elements'].length - 1; }
			else{ homeScroller['index'] = idxNew - 1; }
			homeScroller_next();
		}
		return false;
	});
	homeScroller_update();
	$('#home .buttons a').live('mouseover', function(){
		homeScroller['status'] = homeScrollerStatus.pause;
	});
	$('#home .buttons a').live('mouseout', function(){
		homeScroller['status'] = homeScrollerStatus.play;
	});
	setInterval('homeScroller_autoScroll()', 8000);
});
