/* _js/structure.js */


// - run these functions when ready
$(document).ready(function() {
	
	// -- initialize header features
	hfInit();
});




// - header features functionality


// -- object to store vars
var v_hf = new Object();

// -- vars (config)
v_hf.speed = 1000; // (miliseconds) speed of transitions
v_hf.delay = 7500; // (miliseconds) to delay between cycles

// -- vars (private)
v_hf.total = 0; // how many testimonials do we have
v_hf.current = 0; // which item are we currently viewing?
v_hf.target = 0; // which item are we viewing next?
v_hf.interval = 0; // reference to the interval handler



// -- initialize header images
function hfInit() {
	
	
	$('div#header_feature > ul')
		.addClass('cycling'); // apply "cycling" class to ul
		
	// --- loop each li	
	$('div#header_feature > ul > li').each(function(index) {
		index++;
		v_hf.total++;
		$(this)
			.attr('rel', index)
			//.find('span:first')
				.css('opacity', 0)
				.hide();
	});
	
	hfCycle();
	hfSetCycle();	
}


// -- cycle header images
function hfCycle() {
	
	
	v_hf.target = (v_hf.current == v_hf.total) ? 1 : v_hf.current+1;
	
	// --- fade out current
	$('div#header_feature > ul > li[rel='+v_hf.current+']')
		.fadeTo(v_hf.speed, 0, function() {
			$(this).hide();
		});
		
	// --- fade in target	
	$('div#header_feature > ul > li[rel='+ v_hf.target+']')
		.show()
		.fadeTo(v_hf.speed, 1);	
		
	v_hf.current = v_hf.target;
	
}


// -- set inertval for header images
function hfSetCycle() {
	v_hf.interval = setInterval('hfCycle()', v_hf.delay);
}
