var com = {};
com.eitetu = {};

com.eitetu.SwitchBanner = function(btn, target) {
	var len = btn.length;
	var item = null;
	var button = null;
	var self = this;
	this.items = new Array();
	this.buttons = new Array();
	for(var i=0; i<len; i++) {
		item = $(target[i]);
		button = $(btn[i]);
		button.click(function() {
			self.__changeHandler(this);
		});

		this.items.push(item);
		this.buttons.push(button);
	}
	this.selectedIndex = -1;
	this.next();
};

com.eitetu.SwitchBanner.prototype = {
	items:null,
	buttons:null,
	selectedIndex:null,
	__interval:null,
	start:function() {
		if(this.__interval == null) {
			var self = this;
			this.__interval = setInterval(function() {
				self.next();
			}, 3000);
		}
	},
	stop:function() {
		if(this.__interval != null) {
			clearInterval(this.__interval);
		}
	},
	next:function() {
		if((this.items.length - 2) < this.selectedIndex)
			this.selectedIndex = -1;
		
		this.selectedIndex++;
		this.__changeHandler(this.buttons[this.selectedIndex]);
	},
	prev:function() {
		if(this.selectedIndex < 1)
			this.selectedIndex = this.items.length;
		
		this.selectedIndex--;

		this.__changeHandler(this.button[this.selectedIndex]);
	},
	__changeHandler:function(target) {
		target = $(target);
		var len = this.buttons.length;
		var img;
		for(var i=0; i<len; i++) {
			img = this.buttons[i].find("img:first-child");
			if(target.attr("id") == this.buttons[i].attr("id")) {
				if(img.attr("src").indexOf("_on.gif") == -1) {
					img.attr("src",img.attr("src").replace(".gif", "_on.gif"));
				}

				this.items[i].show();
				this.selectedIndex = i;
			} else {
				img.attr("src",img.attr("src").replace("_on.gif", ".gif"));
				this.items[i].hide();
			}
		}
	}
};

//quick
function initMoving(target, position, topLimit, btmLimit) {
		if (!target)
			return false;

		var obj = target;
		obj.initTop = position;
		obj.topLimit = topLimit;
		obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

		obj.style.position = "absolute";
		obj.top = obj.initTop;
		obj.left = obj.initLeft;

		if (typeof(window.pageYOffset) == "number") {
			obj.getTop = function() {
				return window.pageYOffset;
			}
		} else if (typeof(document.documentElement.scrollTop) == "number") {
			obj.getTop = function() {
				return document.documentElement.scrollTop;
			}
		} else {
			obj.getTop = function() {
				return 0;
			}
		}

		if (self.innerHeight) {
			obj.getHeight = function() {
				return self.innerHeight;
			}
		} else if(document.documentElement.clientHeight) {
			obj.getHeight = function() {
				return document.documentElement.clientHeight;
			}
		} else {
			obj.getHeight = function() {
				return 500;
			}
		}

		obj.move = setInterval(function() {
			if (obj.initTop > 0) {
				pos = obj.getTop() + obj.initTop;
			} else {
				pos = obj.getTop() + obj.getHeight() + obj.initTop;
				//pos = obj.getTop() + obj.getHeight() / 2 - 15;
			}

			if (pos > obj.bottomLimit)
				pos = obj.bottomLimit;
			if (pos < obj.topLimit)
				pos = obj.topLimit;

			interval = obj.top - pos;
			obj.top = obj.top - interval / 3;
			obj.style.top = obj.top + "px";
		}, 20)
	}
