if (!window.snp) snp = {};
snp.ToggleContent = function (heading, content, observer, eventType) {
	var self = this;
	this.heading = heading;
	this.content = content;
	this.isShow = false;
	this.observer = observer || {onToggle: function() { return false }};
	this.eventType = (eventType || 'onclick').replace('on', '');

	this.init();
	$(this.heading)[this.eventType](function () {
		self.handleActivate();
	});

	if (this.eventType !== 'onmouseover') {
		$(this.heading).mouseover(function () {
			$(this).toggleClass('hover');
		}).mouseout(function () {
			$(this).toggleClass('hover');
		});
	}
}
snp.ToggleContent.prototype = {
	init: function () {
		this.hide(true);
		$(this.heading).css('cursor', 'pointer');
	},
	hide: function (keepHeadingOn) {
		if (!keepHeadingOn) $(this.heading).toggleClass('on');
		$(this.content).css('display', 'none');
		this.isShow = false;
	},
	show: function () {
		$(this.heading).toggleClass('on');
		$(this.content).css('display', 'block');
		this.isShow = true;
	},
	handleActivate: function () {
		if (this.observer.onToggle(this, this.isShow)) return false;
		this.isShow ? this.hide() : this.show();
	}
}
snp.ToggleContents = function (headings, contents, isTab, eventType) {
	this.isTab = isTab === 'tab' ? true : false;
	this.headings = headings;
	this.contents = contents;
	this.currentToggleContent = {show: function () {},hide: function () {}};
	this.toggleContentInst = [];
	this.eventType = (eventType || 'onclick').replace('on', '');
	
	this.init();
}
snp.ToggleContents.prototype = {
	init: function () {
		for (var i=0; i < this.headings.length; i++) {
			// TODO ToolTip 만들어서 Tab && over 일때 ToolTip 사용
			this.toggleContentInst.push(new snp.ToggleContent(this.headings[i], this.contents[i], this, this.eventType));
		};
		if (this.isTab) {
			$(this.headings[0])[this.eventType]();
		}
	},
	onToggle: function (toggleContent, shown) {
		if (this.isTab && this.currentToggleContent === toggleContent) return true;
		if (this.currentToggleContent === toggleContent) toggleContent = {show: function () {}, hide: function () {}};
		return this.setCurrentToggleContent(toggleContent);
	},
	setCurrentToggleContent: function (toggleContent) {
		this.currentToggleContent.hide();
		this.currentToggleContent = toggleContent;
		this.currentToggleContent.show();
		return true;
	}
}
snp.ToolTip = function (heading, content) {
	var self = this;
	this.heading = heading;
	this.content = content;

	$(this.heading).mouseover(function () {
		self.handleMouseOver();
	}).mouseout(function () {
		self.handleMouseOut();
	})
	$(this.content).mouseover(function () {
		self.handleMouseOver();
	}).mouseout(function () {
		self.handleMouseOut();
	})
	this.init();
}
snp.ToolTip.prototype = {
	init: function () {
		this.hide(true);
	},
	hide: function (keep) {
		if (!keep) $(this.heading).toggleClass('on');
		this.content.style.display = "none";
	},
	show: function () {
		$(this.heading).toggleClass('on');
		this.content.style.display = "block";
	},
	handleMouseOver: function () {
		this.show();
	},
	handleMouseOut: function () {
		this.hide();
	}
}









