// On Load
jQuery(document).ready(function () {

	// 트리
	jQuery('ul.cat-tree').tree();

	// navigation
	jQuery('#navi .gnb').Mnav();

	// tab same height
	//jQuery('div.m-height ul li a strong').Mheight();

	jQuery('ul.side-menu').sideHover();
	jQuery('ul.side-menu').sideOn();

	initTabs();
	initInputs();
	screenZoom();

	// mypage family member
	jQuery('#content div.page-cont div.smile-box').loopGallery({active: 5, group: 1});

	// FAQ
	faq('.faq-list');


	//selectbox design
	//jQuery('#header div.svc-area .gn-lnk select').sSelect();

})


// Cookie
function createCookie(name, value, days) {
	var expires = '';
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		expires = '; expires=' + date.toGMTString();
	}
	document.cookie = name + '=' + value + expires + '; path=/';
}

function readCookie(name) {
	var nameEQ = name + '=',
		ca = document.cookie.split(';'),
		ca_len = ca.length,
		i, c;
	for (i = 0; i < ca_len; i++) {
		c = ca[i];
		while (c.charAt(0) === ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) === 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, '', -1);
}


/* tab */
function initTabs() {
	var tabs = jQuery('ul.tab:not(div.side-menu ul.tab)').tab();
	tabs.each(function () {
		this.init();
	});
}

function initInputs() {
	var inputs = jQuery('#header .total-search :text[title], div.re-login .name :text[title], div.re-login .tel :text[title]');
	inputs.each(function () {
		var title = jQuery(this).attr("title"),
			value = jQuery(this).val();
		if (!value) {
			jQuery(this).val(title);
		}
		jQuery(this).bind("focus", function (e) {
			if (jQuery(this).val() == title)
				jQuery(this).val("");
		});
		jQuery(this).bind("blur", function (e) {
			if (jQuery(this).val().length == 0)
				jQuery(this).val(title);
		});
	});
}

// FAQ
function faq(selector) {
	var faq_lists = jQuery(selector);
	if (faq_lists.length) {
		var items = faq_lists.find('li'),
			answers = items.find('.faq-answer');
		items.each(function () {
			var question = jQuery(this).find('.faq-question'),
				items_btn = jQuery(this).find('a.close'),
				answer = jQuery(this).find('.faq-answer');
			answer.hide();
			question.bind('click', function () {
				if (answer.css('display') == 'block') {
					answer.slideUp('fast');
				} else {
					//answers.slideUp('fast');
					answer.slideDown('fast');
				}
			});

			items_btn.bind('click', function () {
				if (answer.css('display') == 'block') {
					answer.slideUp('fast');
				} else {
					answers.slideUp('fast');
					answer.slideDown('fast');
				}
			});
		});
	}
}

function chkIE() {
	var rv = false;
	if (navigator.appName == "Microsoft Internet Explorer") {
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat(RegExp.jQuery1);
	}
	return rv;
}

/* ie screen zoom */
function screenZoom() {
	var body = jQuery('body'),
		wrapper = jQuery('#header div.svc-area'),
		zoom_in = wrapper.find('.zoom-in'),
		zoom_out = wrapper.find('.zoom-out'),
		setting = readCookie('screenZoom');
		//alert(setting);

	if (setting) {
		zoom(false, setting);
	}

	zoom_in.bind('click', function () {
		zoom();
	});

	zoom_out.bind('click', function () {
		zoom('out');
	});

	function zoom(out, zoom_to) {
		var jQuerywrapper = jQuery('body'),
			zoom = jQuerywrapper.css('zoom'),
			current = (zoom === 'normal') ? 100 : parseInt(zoom),
			ratio = 5,
			min = 100 - (ratio * 0),
			max = 100 + (ratio * 5),
			new_zoom, abs;

		if (out) {
			ratio = -5;
		}

		new_zoom = current + ratio;

		if (zoom_to) {
			new_zoom = zoom_to;
		}

		if (min > new_zoom) {
			new_zoom = min;
			alert('현재 '+ min +'% 입니다.');
		} else if (max < new_zoom) {
			new_zoom = max;
			alert('현재 '+ max +'% 입니다.');
		}


		jQuerywrapper.css('zoom', new_zoom + '%');

		//createCookie('screenZoom', new_zoom, 365);
	}

}












/*ActiveX Flash*/
// id: flash id
// url: source url
// w: source width
// h: source height
// t: wmode (window/transparent/opaque)
function Flash(id,url,w,h,bg,t){
document.write("\
<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9.0.124.0' width="+w+" height="+h+" id="+id+">\
<param name='movie' value="+url+">\
<param name='wmode' value="+t+">\
<param name='bgcolor' value="+bg+">\
<param name='allowScriptAccess' value='always'>\
<param name='quality' value='high'>\
<param name='menu' value='false'>\
<embed src="+url+" width="+w+" height="+h+" wmode="+t+" name="+id+" bgcolor="+bg+" allowScriptAccess='sameDomain' quality='high' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer'>\
</object>\
");
}

function gnb(){
	Flash('sub_gnb','/images/fla/gnb_test.swf','960','195','#FFFFFF','transparent');
}


