var current_picture_number = 0;
var picture_number = 0;
var flag_switch = 1;

$(document).ready(function(){ 
	
	$("li:eq(0)", "#content_top_out").css("display", "block");
	$('#button' + current_picture_number ).addClass('selected');
	setTimeout( "auto_switch()" , 4000);
	
	$('span.button').each(function () {
		$(this).click(function () {
			picture_number = $(this).attr('id').replace('button', '');
			if ( picture_number != current_picture_number) {
				switch_picture(picture_number);
			}
		});
	});
	
	$('#content_top_out').each(function () {
		$(this).hover(
			function() {
				flag_switch=0;
			},
			function() {
				flag_switch=1;
			}
		);
	});
	
	final_text_quote = $("#testimonial_content #quote_start_picture").html() + $("#testimonial_content .text_quote").html() + $("#testimonial_content #quote_end_picture").html();
	$("#testimonial_content .text_quote").html(final_text_quote);
	$("#testimonial_content li").each(function() {
		final_text_li = "<span>"+$(this).html()+"</span>";
		$(this).html(final_text_li);
	});
	
	
}); 

function switch_picture(picture_number) {
	
	$("li:eq("+current_picture_number+")", "#content_top_out").fadeTo(2000,0);
	$("li:eq("+picture_number+")", "#content_top_out").fadeTo(2000,1);
	$('.button').removeClass('selected');
	$('#button' + picture_number ).addClass('selected');
	current_picture_number = picture_number * 1;
}

function auto_switch () {

	if (flag_switch == 1) {
		picture_number = (document.getElementById("button"+ (current_picture_number+1) )) ? current_picture_number+1 : 0 ;
		switch_picture(picture_number);
	}

	setTimeout( "auto_switch()" , 4000);
}



