$(function(){

fadeAllIn();


});
		
		function fadeAllIn(){
			 $('#logo_wrapper a').mouseover(function(e){
			 		e.stopPropagation();//machts noch nich
			 		var title =$(this).attr('title');
			 		$('#logo_wrapper #hoverText').append('<p>'+title+'</p>');
					$('#hoverText').fadeIn(200);
			 }).mouseout(function(){
			 		$('#hoverText').hide();
				$('#hoverText p').remove();		
			 });
			 
			 
			 
			 $('#linkImprint,#closeImprint').click(function(e){
			 	e.preventDefault();
			 	$('#imprint').toggle();
			 	
			 });
			 
			 
			 
			
			$('#container').fadeIn(400, function(){
				$('header').fadeIn(200, function(){
					$('#main').fadeIn(200, function(){
						 
						$('footer').fadeIn(function(){
          				  animateRoy();
          				  
						});
										
					});
				});
			});
		}
		
		function animateRoy(){
		  var easeType="easeOutExpo";
		   $("#roy").animate({
		   		opacity:"show", 
		   		top:"0px",
		   		left:"658px" 
		   		
		   		}, 500, easeType,  function(){
		   			
		   		});
			
		};
		
		
		
	  function fadeInImprint(){
	  	$('#imprint').fadeIn();
	  };
	  function fadeOutImprint(){
	  	$('#imprint').fadeOut();
	  };


var roy = [], smoke = "83,77,79,75,69";
$(document).keydown(function(e) {
  roy.push( e.keyCode );
  if ( roy.toString().indexOf( smoke ) >= 0 ){
    $(document).unbind('keydown',arguments.callee);
	$('#container').append('<div id="lucky"></div>');
	SmokeEffect.makeEffect("smoke", 117, 70); 
  }
});


/*smoke*/
var SmokeEffect = {
	
	imgLocation: "img/smoke_01.png", 
	smokeWidth: 17,
	smokeHeight: 70, 
	
	//don't touch this:
	smokePos: new Array(),
		
	makeEffect: function(id, posX, posY) {
		//set position from the "parent"
		SmokeEffect.smokePos[id] = new Array();
		SmokeEffect.smokePos[id]['x'] = posX;
		SmokeEffect.smokePos[id]['y'] = posY;
		
		//set a random time to start puffing
		var time = (Math.floor(Math.random()*3001));
		setTimeout("SmokeEffect.animate('" + id + "')", time);
	},
	
	animate: function(id) {

		//create the smoke cloud
		var puff = document.createElement("IMG");
		$(puff).attr("src", SmokeEffect.imgLocation);
		$(puff).attr("alt", "puff");
		$(puff).attr("class", "puff");
		
		//create a temp id for the cloud so we can delete it later on
		var tempId = "puff" + Math.floor(Math.random()*1001);
		$(puff).attr("id", tempId);
		
		//append the cloud to the body
		$(document.body).append($(puff));
		
		var objPos = $('#' + id).offset();
		
		//do smoke animation
		$(puff).css({
			top: (objPos['top'] + SmokeEffect.smokePos[id]['y']) + "px",
			left: (objPos['left'] + SmokeEffect.smokePos[id]['x']) + "px",
			zIndex: 25,
			opacity: 0.4
		});
		$(puff).animate({
			width: SmokeEffect.smokeWidth + "px",
			height: SmokeEffect.smokeHeight + "px",
			marginLeft: "-" + (SmokeEffect.smokeWidth / 2) + "px",
			marginTop: "-" + (SmokeEffect.smokeHeight * 1.2) + "px",
			opacity: 0.9
		},{
			duration: 1700
		}).animate({
			marginTop: "-" + (SmokeEffect.smokeHeight * 3.1) + "px",
			opacity: 0.0
		},{
			duration: 2500
		});
		
		//create timeout and run the animation again
		var time = 5500 + (Math.floor(Math.random()*4501));
		
		setTimeout("SmokeEffect.animate('" + id + "')", time);
		
		//remove the old one
		setTimeout("$('#" + tempId + "').remove()", 4200);
		
	}
}



/*vimeo stuff*/


