// JavaScript Document
function MusicTitleLoader(port, b, divid, rwtitle) {
  this.inheritFrom = sack;
  this.inheritFrom();
  this.port = port;
  this.b = b;
  this.divid = divid;
  this.rewritetitle = rwtitle;
  this.locktimer = null;
  var self = this;
  this.mintime = 7000;
  this.randtime = 6000;
  
  this.getobj = function(obj) {
    return ((document.getElementById) ? document.getElementById(obj) : eval("document.all[" + obj + "]"));
  }
  
  this.rand = function ( n ) {
    return ( Math.floor ( Math.random ( ) * n + 1 ) );
  }

  this.writehtml = function(){
    divelement = this.getobj(this.divid);
    divelement.innerHTML = this.response;
	  if (this.rewritetitle) document.title = 'Starmusic.hu - '+this.response;
  }

  this.getmusictitle = function() {
    this.reset();
  	this.setVar('p', this.port);
	  this.setVar('b', this.b);
	  this.requestFile = 'load_music.php';
	  this.onCompletion = function() {this.writehtml()};
    this.runAJAX();
  }
  
  this.delayed = function() {
    window.clearTimeout(this.locktimer);
    this.refreshmusic();
  }
  
  this.refreshmusic = function() {
    this.getmusictitle();
    this.locktimer = window.setTimeout(function(){self.delayed()},this.mintime+this.rand(this.randtime));
  }
  // start the loop
  this.refreshmusic();
}

