$(document).ready(function() {
	/* modal popup */
	$('.open-layer').click(function(){
		wrapWindowByMask();
		var layerId = $(this).attr('href');
		var zIndex = $('#mask').css('z-index') * 1;
		$(layerId).css({
			position: 'absolute',
			top: '50%',
			left: '50%',
			zIndex : zIndex + 1
		})
		.show();
		
		return false;
	});
	$('.close-btn').click(function(){
		$('.layer-pop').hide();
		$('#mask').remove();
		return false;
	});


});


function wrapWindowByMask(){
	var maskHeight = $(document).height();
	var maskHTML = $('<div />',{
			id : 'mask'
		})
		.css({
			position: 'absolute',
			top: 0,
			left: 0,
			width: '100%',
			height: maskHeight,
			backgroundColor: '#000',
			zIndex : 98
		})
		.fadeTo('fast',0.3);
	$('body').append(maskHTML);
	return false;
}

/* Tab Content */
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return;

			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", "_off.gif");
				} else {
					currentmenu.className = currentmenu.className.replace("on", ""); 
				}
			}

			this.targetEl.style.display = "block";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace("_off.gif", "_on.gif");
			} else {
				this.className += " on";
			}
			this.container.current = this;

			return false;
		};

		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
//	if (tabContainer.first)
//		tabContainer.first.onclick(); 2013-01-04 디바이스 선택 창 첫번째 활성화 막음
}

jQuery(function () {
	if (!("placeholder" in document.createElement("input"))) { 
		jQuery(":input[placeholder]").each(function () {
			var $this = jQuery(this);
			var pos = $this.offset();
			if (!this.id) this.id = "jQueryVirtual_" + this.name;
			if (this.id) {
				if (jQuery.browser.version  < 8) {
					$this.after("<label for='" + this.id + 
						"' id='jQueryVirtual_label_" + this.id + 
						"' class='absolute'>" + $this.attr("placeholder") + 
						"</label>");
				}
				else {
					$this.after("<label for='" + this.id + 
					"' id='jQueryVirtual_label_" + this.id + 
					"' class='absolute'>" + 
					$this.attr("placeholder") + "</label>");
				}
			}
		}).focus(function () {
			var $this = jQuery(this);
			$this.addClass("focusbox");
			jQuery("#jQueryVirtual_label_" + $this.attr("id")).hide();
		}).blur(function () {
			var $this = jQuery(this);
			$this.removeClass("focusbox");
			if(!jQuery.trim($this.val())) 
				jQuery("#jQueryVirtual_label_" + $this.attr("id")).show();
			else jQuery("#jQueryVirtual_label_" + $this.attr("id")).hide();
		}).trigger("blur");
	}
}); 