	var cloudnum = 7;

	function destroyClouds() {
		for(i=0;i<cloudnum;++i) {
			$('#cloud' + i).remove();
			if (window.console != undefined) console.log('destroying #cloud' + i);
		}
	}

	function remove(selection){
	   selection.parentNode.removeChild(selection);
	}
	
	function hideClouds() {
		$('.cloud').hide();
	}
	function showClouds() {
		$('.cloud').show();
	}

	$.fn.pause = function(milli,type) {
	  milli = milli || 1000;
	  type = type || "fx";
	  return this.queue(type,function(){
		  var self = this;
		  setTimeout(function(){
			  $.dequeue(self);
		  },milli);
	  });
	};

	$.fn.clearQueue = $.fn.unpause = function(type) {
		return this.each(function(){
			type = type || "fx";
			if(this.queue && this.queue[type]) {
				this.queue[type].length = 0;
			}
		});
	};

	jQuery.fn.movingClouds = function(start, end, delay, duration, easing, loopcount) {
		delay = delay || 0 ;
		var n= 1;
		do {
			$(this).pause(delay).animate(
			  {left: end},duration, easing, function() {
				   $(this).css("left",start);
				   });
			n++;
		} while (n<loopcount);
	}
	
	function randOrd(){ return (Math.round(Math.random())-0.5); } 

	function generateClouds() {
		if ($('#top-picture-effect-0').html().length > 0) return;
		var dw = $('#top-picture-effect-0').width();
		var dh = $('#top-picture-effect-0').height();
		var xdivisions = new Array();
		var ydivisions = new Array();
		
		for(i=0;i<cloudnum;++i) {
			xdivisions[i] = (dw*2 / cloudnum) * i;
			ydivisions[i] = ((dh / cloudnum) * i);
		}
		xdivisions.sort(randOrd);
		xdivisions.sort(randOrd);
		for(i=0;i<cloudnum;++i) {
			$('#top-picture-effect-0').append('<div class="clouds" id="cloud' + i +'"></div>');
			$('#cloud' + i).css('z-index','0').css('position','absolute').css('left',xdivisions[i]).css('top',ydivisions[i]).addClass('cloud').movingClouds(dw+"px", "-120px", 0, 30000 + (xdivisions[i] * 10), "linear", 999);	
		}
	}


//$(document).ready(function() {
//	generateClouds();
//});

