Cufon.replace('#navigation ul li a', { fontFamily : 'Helvetica', textShadow: '0px -1px #999999', hover : { color:'#e9ef8f' } });
Cufon.replace('.order h2', { fontFamily : 'Bitstream Vera Serif' });
Cufon.replace('.testimonials p', { fontFamily : 'Georgia Italic' });

function fly(cloud, speed, direction) {
	var animate_options = {};
	animate_options[direction] = screen.width + 'px';
		
	cloud.css( { 'left' : null } );

	cloud.animate(animate_options, speed, 'linear', function () {
		cloud.css(direction, parseInt(-1 * cloud.width()) + 'px');
		speed = randomNumberBetween(40000,80000);
		fly(cloud, speed, direction);
	});
 
}

function randomNumberBetween(minVal,maxVal,floatVal){
  var randVal = minVal+(Math.random()*(maxVal-minVal));
  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

jQuery(function($) {
	
	var screen = {
		width : $('body').width()
	}
	
	
	$(window).resize(function(){
		screen.width = $('body').width();
	});
	
	max_index = jQuery('.testimonials .item').length;
	jQuery('.description .left.item:nth-child(3n+1)').css('clear', 'left');
	
	// slider
	$(".testimonials .item").hide();
	$(".testimonials .item").eq(0).show();
	start_slideshow();
	
	$clouds = $('.cloud-t-l,.cloud-t-r,.cloud-b-l,.cloud-b-r');
		
	$clouds.each(function(){
		
		this_width = (screen.width - parseFloat($(this).css('width')));
				
		right_val = randomNumberBetween(0,this_width);
		top_val = randomNumberBetween(0,600);
		
		$(this).css({
			right : right_val+"px",
			top : top_val+"px"
		});

		if((screen.width/1.1) < right_val){
			animation_speed = randomNumberBetween(8000,12000);
		} else if((screen.width/1.3) < right_val){
			animation_speed = randomNumberBetween(12000,16000);
		}	else if((screen.width/1.6) < right_val){
			animation_speed = randomNumberBetween(16000,22000);
		}	else if((screen.width/1.9) < right_val){
			animation_speed = randomNumberBetween(22000,34000);
		} else 
			animation_speed = randomNumberBetween(60000,100000);
		
		if($(this).not(":animated"))
			fly($(this), animation_speed, 'right');
			
	});
});

var current_index = 0;

function start_slideshow() {
	interval = window.setInterval(function() {
		current_index++;
		
		show_image(current_index);
	}, 10000);
}

function show_image(index) {

	$testimonials = jQuery(".testimonials");

	if (index == 0) {
		jQuery(".testimonials .item").eq(index).fadeIn(2000);
	}
	else if (index == max_index)
	{
		current_index = index = 0;
		old_one = jQuery(".testimonials .item").eq(max_index-1);
		old_one_height = old_one.height();
		
		new_one = jQuery(".testimonials .item").eq(index);
		new_one_height = new_one.height();

		$testimonials.height(old_one_height);
		
		old_one.fadeOut(500, function(){ 
			$testimonials.animate({
				height : new_one_height
				},500,function(){
					new_one.fadeIn(500);
			});
			
		});
	}
	else
	{
		old_one = jQuery(".testimonials .item").eq(index-1);
		old_one_height = old_one.height();
		
		new_one = jQuery(".testimonials .item").eq(index);
		new_one_height = new_one.height();

		$testimonials.height(old_one_height);
		
		old_one.fadeOut(500, function(){ 
			$testimonials.animate({
				height : new_one_height
				},500,function(){
					new_one.fadeIn(500);
			});
			
		});
	}
}
