/******************************************************************************/
/*																			  */
/*    This is the f*ckrgb environment, where wonderful things can happen!     */
/*    -------------------------------------------------------------------	  */
/*    Code copyright by Simon Jentsch 2009									  */
/*																			  */
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

$(document).ready(function() {
	
	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
       		var self = this;
        	setTimeout(function() {
           		$(self).dequeue();
			}, time);
		});
	};
	
	function getRandom( min, max ) {
		if( min > max ) {
			return( -1 );
		}
		if( min == max ) {
			return( min );
		}
		return( min + parseInt( Math.random() * ( max-min+1 ) ) );
	}
	
	//HEADS
	
	/* David */
	$('#kopfDavid').hover(
	//Mouseover
	function(){
		$(this).stop().animate({bottom: 0, left: 375}, 250);
		$('#kopfSimon').css("backgroundPosition","0 0");
	},
	//Mouseout
	function(){
		$(this).stop().animate({bottom: -52, left: 360}, 250);
		$('#kopfSimon').css("backgroundPosition","0 100%");
	}
	);
	
	/* Reen */
	$('#kopfReen').mouseenter(
		//Mouseover
		function(){
			$('#reenOhneKamera').stop().animate({bottom: -107}, 200, function(){
				//$('#reenMitKamera').wait(150);
				$('#reenMitKamera').animate({bottom: 0}, 200); 
			});
		}).mouseleave(
		
	//Mouseout
	function(){
		$('#reenMitKamera').stop().animate({bottom: -147}, 200, function(){
			$('#reenMitKamera').animate({bottom: -147}, 200);
			//$('#reenOhneKamera').stop().wait(150);
			$('#reenOhneKamera').stop().animate({bottom: 0}, 200); 
		});
	});
	
	/* simon */
	$('#kopfSimon').hover(
	//Mouseover
	function(){
		$(this).css("backgroundPosition","0 0");
	},
	//Mouseout
	function(){
		$(this).css("backgroundPosition","0 100%");
	}
	);
	

	
	//CLOUDS
	function moveCloudOneUp() {	$('#wolkeEins').animate({left: getRandom(70, 120)+"px"}, getRandom(5000,6000), 'linear', moveCloudOneDown); }
	function moveCloudOneDown() { $('#wolkeEins').animate({left: getRandom(0, 30)+"px"}, getRandom(5000,6000), 'linear', moveCloudOneUp); }
	
	function moveCloudTwoUp() {	$('#wolkeZwei').animate({left: getRandom(230, 370)+"px"}, getRandom(6000,7000), 'linear', moveCloudTwoDown); }
	function moveCloudTwoDown() { $('#wolkeZwei').animate({left: getRandom(370, 390)+"px"}, getRandom(6000,7000), 'linear', moveCloudTwoUp); }
			
	function moveCloudThreeUp() { $('#wolkeDrei').animate({left: getRandom(600, 650)+"px"}, getRandom(7000,8000), 'linear', moveCloudThreeDown); }
	function moveCloudThreeDown() { $('#wolkeDrei').animate({left: getRandom(470, 600)+"px"}, getRandom(7000,8000), 'linear', moveCloudThreeUp); }

	moveCloudOneUp();
	moveCloudTwoUp() 
	moveCloudThreeUp() 
	
});
