function Premik(name, id, shiftBy, interval){
  this.name     = name;
  this.id       = id;
  this.shiftBy  = shiftBy ? shiftBy : 1;
  this.interval = interval ? interval : 20;
  this.runId	= null;
  this.div = document.getElementById(id);

  var node = this.div.firstChild;
  var next;
  while (node){
    next = node.nextSibling;
    if (node.nodeType == 3)
      this.div.removeChild(node);
    node = next;}

  this.left = 0;
  this.shiftLeftAt = this.div.firstChild.offsetWidth;
  this.div.style.height	= this.div.firstChild.offsetHeight;
  this.div.style.width = 2 * screen.availWidth;
  this.div.style.visibility = 'visible';}

function startPremik(){
  this.stop();
  this.left -= this.shiftBy;
  if (this.left <= -this.shiftLeftAt){
    this.left = 0;
    this.div.appendChild(this.div.firstChild);
    this.shiftLeftAt = this.div.firstChild.offsetWidth;}
  this.div.style.left = (this.left + 'px');
  this.runId = setTimeout(this.name + '.start()', this.interval);}

function stopPremik(){
  if (this.runId)
    clearTimeout(this.runId);
	this.runId = null;}

function spremeniPremikInterval(novinterval){
  if (typeof(novinterval) == 'string')
    novinterval =  parseInt('0' + novinterval, 10);
  if (typeof(novinterval) == 'number' && novinterval > 0)
    this.interval = novinterval;
    this.stop();
    this.start();}

Premik.prototype.start = startPremik;
Premik.prototype.stop = stopPremik;
Premik.prototype.changeInterval = spremeniPremikInterval;

var premik = null; 

function startpremik(){
	premik = new Premik('premik', 'premikID', 1, 20);
	premik.start();}


