var cloud_num = 0;
var star_num = 0;

function body_resize()
{
	height =  $(window).height();
	$("body").css("height",height+"px");
}

function clouds()
{
	cloud_num++;
	
	ct = Math.floor(Math.random()*2);
	
	$("#main").append("<div class='cloud"+ct+"' id='c_"+cloud_num+"'></div>");
	
	t = Math.floor(Math.random()*240)+960;
	s = Math.floor(Math.random()*50000)+50000;

	l = ($("#main").width()-$(window).width())/2+$(window).width()+50;
	l2 = ($("#main").width()-$(window).width())/2-100;
	$("#c_"+cloud_num).css("top",t+"px");
	$("#c_"+cloud_num).css("left",l+"px");

	$("#c_"+cloud_num).fadeTo("slow",0.3).animate({ left: '+=0'},5000).animate({ left: l2+'px'},s).fadeOut("slow", function(){
		$(this).remove();
	});

}

function stars()
{
	star_num++;

	$("#main").append("<div class='star' id='s_"+star_num+"'>.</div>");

	to = Math.floor(Math.random()*700)+40;
	le = Math.floor(Math.random()*1920);
	
	$("#s_"+star_num).css("top",to+"px");
	$("#s_"+star_num).css("left",le+"px");
	
	$("#s_"+star_num).animate({ left: "+=0"},Math.floor(Math.random()*100000)).fadeOut("slow", function(){
		$(this).remove();
	});
}

function reset(speed)
{

	if (speed=="fast")
	{
		tim = 0;
	}
	else
	{
		tim = 200;
	}

	$("#dino").fadeOut(3000);
	$(".tweetbox").fadeOut(tim, function(){
		$("#linker").animate({top: "0px", left: "80px", width: "50px", height: "50px"},tim, function(){
			$("#ovni").animate({top: "-100px"},tim).fadeOut(500);
		});
	});
}

$(function(){
//	body_resize();
//	$(window).resize(function(){ body_resize(); });	

	$("#slides").slides({ 
		play: 5000,
		pause: 2500,
		hoverPause: true,
		generatePagination: true
	});
	
	clouds();
	cla = setInterval("clouds()", 5000);

	for(i=0;i<100;i++)
		stars();
	sta = setInterval("stars()", 5000);
	
	$("#antonio").animate({top: "100px"}, 1500).effect("bounce", {direction: "up", distance: 10, mode: "effect", times: 1 },1000,function(){
		$("#nav").fadeIn("slow");
		
	});

	$("#antonio").click(function(){
		reset();
		$("#main").animate({top: "-900px"},2000);
		return false;
	});
	
	$("#services_link").click(function(){		
		reset();
		$("#rocket").css("top",$(window).height()+"px").css("left","0px").fadeIn("fast").animate({top: "-100px", left: $(window).width()+"px"},3000).fadeOut();
	
		$("#main").animate({top: "0px"},2000);
		return false;
	});
	
	$("#work_link").click(function(){
		reset();
		$("#dino").fadeIn(3000);
		$("#main").animate({top: "-1300px"},2000, function(){
		});
		return false;
	});

	$("#about_link").click(function(){
		reset("fast");
		$("#main").animate({top: "-900px"},500, function(){
			$("#ovni").css("top","0px").css("left",$(window).width()+"px").fadeIn("fast").animate({top: "200px", left: "100px" },1000).animate({top: "450px", left: "100px"},500, function(){
				$("#linker").animate({top: "-50px", left: "150px", width: "75px", height: "75px" },300).animate({top: "30px", left: "250px", width: "100px", height: "100px" },300, function(){
					$(".tweetbox").fadeIn();
				});
			});
		});
		return false;
	});
	
	$("#linker").click(function(){ reset(); });
	$("#ovni").click(function(){ reset(); });

});
