var l;
var c;
var txtl;
var txtc;

$(document).ready(function(){
	
	l = $('#slideshow #pics img').size() - 1;
	c = l;
	txtl = $('#banner-text h3').size() - 1;
	txtc = 0;
	$('#banner-text h3').eq(0).addClass('highlight');
	
	create_loop();
	
});

function create_loop(){
	var t = setTimeout('new_fade()', 4000);
	var tt = setTimeout('change_txt()', 4100);
}

function new_fade(){
	if(c != 0){
		var el = $('#slideshow #pics img').eq(c);
		el.animate({
			opacity: 0
		});
		c -= 1;
		create_loop();
	} else {
		reload();
	}
}

function reload(){
	if(c == 0){
		$('#slideshow #pics img').eq(l).animate({
			opacity: 1
		}, function(){
			$('#slideshow #pics img').css('opacity', 1);
		})
		c = l;
		create_loop();
	}
}

function change_txt(){
	if(txtc != txtl){
		txtc += 1;
		$('#banner-text h3.highlight').removeClass('highlight');
		$('#banner-text h3').eq(txtc).addClass('highlight');
		Cufon.replace('h3', {fontFamily:'Meta'});
	} else {
		txtc = 0;
		$('#banner-text h3.highlight').removeClass('highlight');
		$('#banner-text h3').eq(txtc).addClass('highlight');
		Cufon.replace('h3', {fontFamily:'Meta'});
	}
}
