$.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 twinkle(element, fadein, fadeout, delay, dimension) {
  var el = $(element);
	var newx = Math.round((el.parent().width() - dimension) * Math.random());
	var newy = Math.round((el.parent().height() - dimension) * Math.random());
	el.css({top:newy,left:newx}).wait(delay+Math.round(Math.random()*delay)).fadeIn(fadein).fadeOut(fadeout, function(){twinkle(element, fadein, fadeout, delay, dimension)});
};
 
$(document).ready(function(){
if (jQuery.support.opacity) {
	var stars = new Array();
	// id=filename, fadein, fadeout, delay, dimension
	stars[0] = new Array("star-1", 30, 300, 300, 2000, 7); 
	stars[1] = new Array("star-2", 5, 1000, 1000, 3000, 22);
	stars[2] = new Array("star-3", 1, 3000, 3000, 8000, 178);
	stars[3] = new Array("star-4", 2, 1500, 1500, 5000, 103);

	for (var i=0; i<stars.length; i++) {
		for (var j=0; j<stars[i][1]; j++) {
			var id = stars[i][0] + '-' + j;
			$("#stars").append('<img id="' + id + '" class="star ' + stars[i][0] + '" src="../../fileadmin/templates/images/' + stars[i][0] + '.png" alt="" />');
			twinkle("#"+id, stars[i][2], stars[i][3], stars[i][4], stars[i][5]);
		}
	}
}
});

