function LoadPage(id,pages,duration){
	this.idx = 0;
	this.id = id;
	this.duration = duration;
	this.pages = pages;
	this.timer = null;
	this.playing = true;
	var t = this;
	this.load = function(){
	  if (t.playing == false){
	  	return;
	  }
		$('#'+t.id).load(t.pages[t.idx],{},function(){
			t.idx++;
			if (t.idx >= t.pages.length){
				t.idx = 0;
			}
			if (t.timer){
				window.clearTimeout(t.timer);
			}
			t.timer = window.setTimeout(function(){
					t.load();
			},t.duration);
		});
	}
	this.stop = function(){
		t.playing = false;
	}
	this.play = function(){
		t.playing = true;
		t.load();
	}
	return t;
}

var lp1;
var lp2;
var lp3;
$(function(){
	lp1 = new LoadPage('content1',['/js/on_add.php'],20000);
	lp2 = new LoadPage('content2',['/js/listchat.html'],2000);
	lp3 = new LoadPage('content3',['/playing/playing.php'],10000);
	lp1.load();
	lp2.load();
	lp3.load();
});

