function randomRange(min,max,precision)
{
  var rand = min+(Math.random()*(max-min));
  return typeof precision=='undefined'?Math.round(rand):rand.toFixed(precision);
}

function shootingStar() {
    var direction = Math.random() * 10;
    ss_h1 = Math.random() * getDocWidth();
    if (direction > 5) {
        ss_h2 = ss_h1 + 500;
        ss_image = 'url(../img/shooting-star-right.png)';
    }
    else {
        ss_h2 = ss_h1 - 500;
        ss_image = 'url(../img/shooting-star-left.png)';
    }
    $('.shooting-star').css({
        backgroundPosition: ss_h1 + 'px -100px',
        backgroundImage: ss_image,
        opacity: 1
    });
    $('.shooting-star').animate({
        backgroundPosition: '(' + ss_h2 + 'px 600px)',
        opacity: 0
    }, 2000);
    ss_int = randomRange(2000, 8000, 0);
}

ss_int = randomRange(2000, 8000, 0);

$(document).ready(function () {
    var ss = setInterval(shootingStar,ss_int);
});
