function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function Lantern(objname,targetobj,pageobj) {
	this.objName=objname;
	this.obj=$(objname);
	this.targetObj=$(targetobj);
	this.pageObj=$(pageobj);
	this.conf = {
		direction:0,
		auto:false,
		timegap:1000	
	}
	this.nowId = 0;
	this.lanternCnt = 0;
	this.objlist=new Array();
	this.Interval=new Object();
	this.stat=0;//0,Í£Ö¹£¬1ÔÝÍ££¬2²¥·Å
}

Lantern.prototype.init=function() {
	this.lantrenCnt=this.targetObj.childNodes.length;
	for (var i =0;i<this.lantrenCnt;i++) {
		this.objlist[i]=this.targetObj.childNodes[i];
		this.hidden(i);
	}
	this.nowId=0;	
	if (this.conf.auto) {
		this.goto();
		this.play();
	} else {
		this.goto();
	}
}
Lantern.prototype.setId=function(id) {	
	this.nowId=id%this.lantrenCnt;
}
Lantern.prototype.getId=function() {
	return this.nowId;
}
Lantern.prototype.hidden=function(id) {
	this.objlist[id].style.display='none';	
}
Lantern.prototype.show=function(id) {
	this.objlist[id].style.display='block';
}

Lantern.prototype.next=function() {
	this.setId(this.getId()+1);
	this.goto();
}
Lantern.prototype.prev=function() {
	if (this.getId()>0)
	 {
	  this.setId(this.getId()-1);
	 }
	
	this.goto();
}
Lantern.prototype.getpage=function() {
	return (this.getId()+1)+"/"+this.lantrenCnt;
}
Lantern.prototype.showpage=function() {
	this.pageObj.innerText=this.getpage();
}
Lantern.prototype.goto=function() {	
	for (var i =0;i<this.lantrenCnt;i++) {
		this.hidden(i);
	}
	this.show(this.getId());
	this.showpage();
}

Lantern.prototype.auto=function() {	
	if (this.conf.direction==0) {
		this.next();
	} else {
		this.prev();
	}	
	
}
Lantern.prototype.play=function() {
	if (this.stat!=2) {
		this.Interval=window.setInterval(this.objName+".auto()",this.conf.timegap);	
		this.stat=2;
	}
}
Lantern.prototype.stop=function() {
	if (this.stat!=0) {
		window.clearInterval(this.Interval);
		this.setId(0);
		this.goto();
		this.stat=0;
	}
}
Lantern.prototype.pause=function() {
	if (this.stat==2) {
		window.clearInterval(this.Interval);
		this.stat=1;
	}
}


