var NewsWizard = function(id) {
	this.newsMain = document.getElementById(id);
	this.news = this.newsMain.childNodes[0];
	this.newses = this.getAllNewses("mini_article");
	this.position = 0;
	for(var i =0; i < this.newses.length; ++i) {
			var val = 450*i;
			this.newses[i].style.position = "absolute";
			this.newses[i].style.left = val+"px";
			this.newses[i].style.top = "0";
	}
	this.newsLength = this.newses.length;
	this.createControlPanel();
	
}

NewsWizard.prototype.slide = function(direction) {
	if(direction == "left") {
		--this.newsIndex;
		if(this.newsIndex <= 0) {
			this.newsIndex = 1;
			return;
		}
			
		this.position = Number(this.position) + 450;
		this.news.style.left = this.position+"px";
	} else {
		++this.newsIndex;
		if(this.newsIndex > this.newsLength) {
			this.newsIndex = this.newsLength;
			return;
		}
		this.position = Number(this.position) - 450;
		this.news.style.left = this.position+"px";
	}
	this.changeControlPanel();
};

NewsWizard.prototype.createControlPanel = function() {
	this.newsIndex = 1;
	this.activeNews = document.createElement("span");
	this.activeNews.style.fontSize = "12px";
	this.activeNews.style.position = "absolute";
	this.activeNews.style.left = "27px";
	this.activeNews.style.top = "3px";
	this.activeNews.style.fontWeight = "bold";
	this.activeNews.innerHTML = this.newsIndex+"/"+this.newsLength;
	this.panel = document.createElement("div");
	this.prev = document.createElement("input");
	
	this.prev.type = "image";
	//this.prev.style.marginRight = "15px";
	//this.prev.className = "floatingLeft";
	//this.prev.style.padding = "0 3px";
	this.prev.src = "/public/images/special/back_gray.png";
	this.prev.onclick = function(oEvent) {
		Event = oEvent || window.event;
		othis.slide("left");
		if(oEvent.stopPropagation) {
			oEvent.stopPropagation();
		} else {
			oEvent.cancelBubble = true;
		} 
		return false;
	}
	this.next = document.createElement("input");
	this.next.type = "image";
	if(this.newsLength == 1)
		this.next.src = "/public/images/special/forward_gray.png";
	else
		this.next.src = "/public/images/special/forward.png";
	//this.next.style.marginLeft = "15px";
	//this.next.className = "floatingRight";
	//this.next.style.padding = "0 3px";
	var othis = this;
	this.next.onclick = function(oEvent) {
		Event = oEvent || window.event;
		othis.slide("right");
		if(oEvent.stopPropagation) {
			oEvent.stopPropagation();
		} else {
			oEvent.cancelBubble = true;
		} 
		return false;
	}
	this.panel.appendChild(this.prev);
	this.panel.appendChild(this.activeNews);
	this.panel.appendChild(this.next);
	this.panel.id = "news_panel";
	this.panel.style.position = "absolute";
	this.panel.style.right = "30px";
	this.panel.style.bottom = "0";
	//this.panel.style.height = "20px";
	this.news.parentNode.appendChild(this.panel);
	var tmp = this.activeNews.scrollWidth;
	tmp = (Number(tmp) + 8 + 7)/2;
	this.next.style.marginLeft = tmp+"px";
	this.prev.style.marginRight = tmp+"px";
};

NewsWizard.prototype.changeControlPanel = function() {
	if(this.newsIndex == 1) {
		this.prev.src = "/public/images/special/back_gray.png";
	} else {
		this.prev.src = "/public/images/special/backward.png";
	}
	
	if(this.newsIndex == this.newsLength) {
		this.next.src = "/public/images/special/forward_gray.png";
	} else {
		this.next.src = "/public/images/special/forward.png";
	}
	this.activeNews.innerHTML = this.newsIndex+"/"+this.newsLength;
	var tmp = this.activeNews.scrollWidth;
	tmp = (Number(tmp) + 8 + 7)/2;
	this.next.style.marginLeft = tmp+"px";
	this.prev.style.marginRight = tmp+"px";
	
};

NewsWizard.prototype.getAllNewses = function(className) {
	var tmp = this.newsMain.getElementsByTagName("div");
	var ret = new Array();
	for(var i = 0; i < tmp.length; ++i) {
		if(tmp[i].className.indexOf(className) != -1)
			ret.push(tmp[i]);
	}
	return ret;
};
