$(document.body).ready(function(){
	/////////////////////////////////////////////////////////
	var time = 500;
	$("#coffee")
		.animate({top: '0px'},2000,function(){})
		.draggable
		({
			revert: false,
			cursor: "move",
			containment: 'window',
			zIndex: 1000,
			stop: function(ev, ui) {
				$("#coaster").animate({top: $(this).css("top"),left: $(this).css("left")},400,function(){})
			}
		});
	$("#coaster")
		.animate({top: '0px'},1500,function(){})
		.draggable
		({
			revert: false,
			cursor: "move",
			containment: 'window',
			zIndex: 1000
		});
	$(".watermark").hideandtype();
	var is_front = 	true;
	var front = 	$("#logo_outer").html();
	var back = 		$("#contact_outer").html();
	
	//$("#shell").draggable({"revert":true});
	$(".box, .container").draggable({"revert":true});
	
	$(".handle").live('click', function() {
		var is_opened = ($(this).parent().css("left") == "50%");
		var pos = (is_opened) ? "70%" : "50%";
		
		$(this).parent().animate(
			{left:  pos}, {
			duration: 1000, 
			specialEasing: {
			  left: 'easeOutBounce'
			}, 
			complete: function() {
			}
		  });				
	});												
	$(".left,.right").live('click', function() {
		$("#shell").removeClass("shadow");
		$("#shell").removeClass("flip_left");
		$("#shell").removeClass("flip_right");
		
		var direction = (is_front) ? 'lr' : 'rl';
		var content = (is_front) ? back : front;
		var flip = (is_front) ? "flip_right" : "flip_left";
		
		$("#shell").flip({
			direction:direction,
			content:content,
			speed:300,
			color:"#ffffff",
			onEnd: function(){
				is_front = !is_front;
				
				$("#shell").addClass("shadow");
				$("#shell").addClass(flip);
				$("#shell").draggable({"revert":true});
				
				$(".watermark").hideandtype({active_color:"#333",inactive_color:"#999"});
			}
		});
	});
	$(window).scroll(function(){
		$("#effects").keep({bump:10});
	});		
});

function form_submit(){
	$.ajax({
		type: "post",
		url: "php/ajax/mail.php",
		data: $("#form_contact").serialize(),
		success: function(msg){
			alert("Mail sent successfully!")
			$("#form_contact").reset();
		}
	});
}


function rn(min, max) {
	var offset = min;
	var range = (max - min) + 1;

	var randomNumber = Math.floor( Math.random() * range) + offset;
	return randomNumber;
}


function nightlife(){
	$("#coffee").animate({top: '-800px', left:'0px'},700);
	$("#beer").animate({top: '0px', left:'0px'},700);
	$("body").append($("<div>").attr("id","dubstep"));
	var d = "#dubstep";
	var s = 500;
	var c = {b:'black',r:'red',g:'green',u:'blue',y:'yellow',t:'transparent'}
	$(d).animate({backgroundColor: c.b},s,
		function(){
			$(d).animate({backgroundColor: c.r},s,
				function(){
					$(d).animate({backgroundColor: c.g},s,
						function(){
							$(d).animate({backgroundColor: c.u},s,
								function(){
									$(d).animate({backgroundColor: c.y},s,
										function(){
											$(d).animate({backgroundColor: c.b},s,
												function(){
													$(d).animate({opacity: 0},s,
														function(){
															$(d).remove();
															$("#coffee").animate({top: '0px', left:'0px'},700);
															$("#beer").animate({top: '-800px', left:'0px'},700);
														}
													);
												}
											);
										}
									);
								}
							);
						}
					);
				}
			);
		}
	);
}
function earthquake(){
	$('.earthquake').effect("shake", { times:60, distance:5 }, 8);
}
function move_x(div,range){
	$(div).each(function(i){
		$(this).animate({ 
		left: rn((-1*range),range)+"px"
		}, 1500 );
	});
}
function move_y(div,range){
	$(div).each(function(i){
		$(this).animate({ 
			top: rn((-1*range),range)+"px"
		}, 1500 );
	});
}
function move_all(div,range){
	$(div).each(function(i){
		$(this).animate({ 
			left: rn((-1*range),range)+"px",
			top: rn((-1*range),range)+"px"
		}, 1500 );
	});
}
function move_around(){
	move_x(".move_x",100);
	move_y(".move_y",100);
	move_all(".move_all",100);
}
function cleanup(){
	$('.move_x').animate({ 
		left: "0px",
		top: "0px"
	}, 1500 );
	$('.move_y').animate({ 
		left: "0px",
		top: "0px"
	}, 1500 );
	$('.move_all').animate({ 
		left: "0px",
		top: "0px"
	}, 1500 );
}