Ad_Player=function(container){
	this.container=container;
	this.timer=null;
	this.delay=10 * 1000;

	this.ads=DOM.getElementsByClassName("ad",container);
	this.current_index=0;

	this.selectors=new Array();

	if(this.ads.length>1){
		this.build_navigation();

		this.change(this.current_index);
		this.start();
	}
}
Ad_Player.prototype.build_navigation=function(){
	var nav=DOM.createElement("div");
	DOM.setClass(nav,"nav small");

	var selector;
	var index;
	for(var i=0;i<this.ads.length;i++){
		index=i+1;

		selector=DOM.createElement("a",index);
		selector.setAttribute("href","#"+index);
		DOM.setClass(selector,"flat button");

		selector.onclick=STD.delegate(this,this.selector_click);

		nav.appendChild(selector);

		this.selectors.push(selector);
	}

	this.container.appendChild(nav);
}
Ad_Player.prototype.start=function(){
	this.timer=setInterval(STD.delegate(this,this.next),this.delay);
}
Ad_Player.prototype.stop=function(){
	clearInterval(this.timer);
}
Ad_Player.prototype.change=function(index){
	this.ads[this.current_index].style.visibility="hidden";
	this.ads[index].style.visibility="visible";

	var selected="selected";
	DOM.removeClass(this.selectors[this.current_index],selected);
	DOM.addClass(this.selectors[index],selected);

	this.current_index=index;
}
Ad_Player.prototype.next=function(){
	var next_index=(this.current_index+1) % this.ads.length;
	this.change(next_index);
}
Ad_Player.prototype.selector_click=function(event){
	this.stop();

	var target=STD.target(event);
	var index=parseInt(DOM.get_href_anchor(target))-1;

	this.change(index);

	this.start();

	return false;
}
