$(document).ready(function(){

		//quick scroll init top value
		var int_gotopTop = parseInt($("#gotop").css('top'));
		//var int_gotopTop = $('#gotop').offset().top;
		
		//smartbar center align
		fixLeft();
		$(window).resize(function() {
			setTimeout("fixLeft()", 1);
		});	

		//header
		$('.additional_sphere a').eq(0).css({
			'background':'none',
			'padding':'0 4px 0 6px'
		});
		$('.popular_keyword_sphere ul li').eq(0).css({
			'background':'none',
			'padding':'0 4px 0 3px'
		});	
		
		//header login focus
	
		$('.h_login_area fieldset input').focus(function(){
			$(this).css('background','none');		
		});

		//header login focus
		$('.mylogininfo').focus(function(){
			$(this).val('');
		}); 

		// login page focus
		$('#login_area .login_sphere input').focus(function(){
			$(this).css('background','none');		
		}); 

		//all search key
		$('.whole_search_sphere .search_write').keypress(function(event){
		  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
            $('.whole_search_sphere .btn_search').click();  
            return false;  
			} else {  
				return true;  
			}  
		});		

		$('.unify_search_sphere .search_write').keypress(function(event){
		  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
            $('.unify_search_sphere .btn_search').click();  
            return false;  
			} else {  
				return true;  
			}  
		});		

		$('.board_search_sphere .words').keypress(function(event){
		 if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
            $('.board_search_sphere .btn_search').click();  
            return false;  
			} else {  
				return true;  
			}  
		});

		$('.event_name_sphere .event_name').keypress(function(event){
		 if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
            $('.event_search_area .btn_search').click();  
            return false;  
			} else {  
				return true;  
			}  
		});

		$('.faq_search_frequency_area .faq_search_word').keypress(function(event){
		 if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
            $('.faq_search_frequency_area .btn_search').click();  
            return false;  
			} else {  
				return true;  
			}  
		});


		//location
		$('.location_area .location_depth:last span').css('color','#339999');
		
		
		//quick scroll	
		var gotopHeight =$('#gotop').height(); 
		stopLine = $('#inner_body_wrap_02').height() - gotopHeight - 350; 		

		$('#body_wrap').scroll(function () { 		

				var scrollTop = $(this).scrollTop(); 
				var gotopGoal = int_gotopTop + scrollTop; 

				if (gotopGoal > stopLine){ 
					gotopGoal = stopLine;
				}

				$("#gotop").stop();
				//alert("scrollTop : " + scrollTop + " = stopLine.scroll : " + stopLine.scroll + " ; windowHeight : " + windowHeight);
				$("#gotop").animate({top: gotopGoal}, 1000);

		});

		//tab_navi
		$(".tab_navi > a").focus(function(){$(this).blur();});
		var tab_length = $(".tab_navi > a").length;

		$('.tab_navi_area_3').hide();
		$('.tab_navi_area_3').eq(0).show();
		//$('.card_type_sphere_2','.tab_navi_area:eq(0)').css('position','relative');
		$('.board_list_type_7','.tab_navi_area .contents_box_list_area').hide();
		$('.board_list_type_7','.tab_navi_area:eq(0)').show();

		$('.my_proposal_list_area').eq(0).css({'visibility':'visible','position':'static'});	

		 $(".tab_navi > a").click(function(){
		 var i = 0;
		 $(this).siblings().each(function(){
		  $(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
		  i ++;
		  $(this).css('z-index', tab_length - i);//alert($(this).attr('class') + '=' + (tab_length - i));
		 });

		 $(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));
		 $(this).css('z-index', tab_length);
		 
		 $(".tab_navi_area").css({'visibility':'hidden','position':'absolute'});		
		 $('.tab_navi_area_3').hide();

		 thisIdx = $(">a", $(this).parent()).index($(this));
		 $viewTab = $(".tab_navi_area").eq(thisIdx);
		 $viewTab3 = $(".tab_navi_area_3").eq(thisIdx);
		 
		 $viewTab.css({'visibility':'visible','position':'static'});
		 $viewTab3.show();


		 $('.search_tab_navi_area', $viewTab3).hide();
		 $('.search_tab_navi_area:eq(0)', $viewTab3).show();

		 $('.search_tab_navi_2 a:eq(0)', $viewTab3).each(function(){
			var viewLeft =  $(this).offset().left - $(this).parent().offset().left;
			var tabWidth =  $(this).width();
			var halftabWidth = (tabWidth/2);
			var realPosition =  viewLeft+halftabWidth + parseInt($(this).css('padding-left'));
			$('.search_tab_navi_2').css('backgroundPosition',realPosition+'px bottom');
			$('.search_tab_navi_2 a').removeClass('selected');
			$(this).addClass('selected');
		});	


		$('.search_tab_navi_2 a', $viewTab3).click(function(){
			
			$(".search_tab_navi_area",$viewTab3).hide();

			 thisIdx = $(">a", $(this).parent()).index($(this));
			 $searchviewTab = $(".search_tab_navi_area",$viewTab3).eq(thisIdx);
			 $searchviewTab.show();

		});



		 $('.card_type_sphere', $viewTab3).show();

		 $('.card_type_sphere').each(function(){

			var cardareaHeight = $(this).height();
			var cardImgTop = (cardareaHeight/2) - 66;

			$('.card_img', $(this)).css('top', cardImgTop);
		});

		 //$('.card_type_sphere_2', $viewTab).fadeOut(1);
		 //$('.card_type_sphere_2', $viewTab).fadeIn(1);
		 $('.board_list_type_7', $viewTab).show();

		 });


		//tab_navi_2
		$(".tab_navi_2 > a").eq(0).css('background','none');
		 $(".tab_navi_2 > a").click(function(){
			$(this).siblings().each(function(){
				$(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
			});
			$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));

		});

		
		$('.tab_navi_area_4').hide();
		$('.tab_navi_area_4').eq(0).show();
		var tab_length_4 = $(".tab_navi_4 > a").length;
		 $(".tab_navi_4 > a").click(function(){
			var i = 0;
			 $(this).siblings().each(function(){
			  $(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
			  i ++;
			  $(this).css('z-index', tab_length_4 - i);//alert($(this).attr('class') + '=' + (tab_length - i));
			 });

			 $(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));
			 $(this).css('z-index', tab_length_4);

			 thisIdx = $(">a", $(this).parent()).index($(this));
			$viewTab4 = $(".tab_navi_area_4").eq(thisIdx);

			 $('.tab_navi_area_4').hide();
			 $viewTab4.show();
		});
		

		//site_jump_navi
		 $(".site_jump_navi > a").mouseover(function(){
			$(this).siblings().each(function(){
				$(">img", $(this)).attr("src",  $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
			});
			$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_off\./, "_on."));
		});

		 $(".site_jump_navi > a").mouseout(function(){
			$(this).siblings().each(function(){
				$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
			});
			$(">img", $(this)).attr("src", $(">img", $(this)).attr("src").replace(/_on\./, "_off."));
			
		});

		
		//m_amass_tab
		
		$(".m_amass_tab > a").eq(0).click(function(){
			$('.m_conditional_area').show();
			$('.m_online_type_sort_area').hide();
			});
		$(".m_amass_tab > a").eq(1).click(function(){
			$('.m_conditional_area').hide();
			$('.m_online_type_sort_area').show();
			});

		 //gallery_typ_1 
		 var obj_gallery_type_1 = $('.gallery_type_1 > p');
		 var gallery_type_1_length = obj_gallery_type_1.length;
		 for(var i=3; i <= gallery_type_1_length; i = i + 3){
			$('.gallery_type_1 > p').eq(i-1).css('width','89px');
		 }		

		 //gallery_typ_2 
		 var obj_gallery_type_2 = $('.gallery_type_2 > div');
		 var gallery_type_2_length = obj_gallery_type_2.length;
		 for(var i=4; i <= gallery_type_2_length; i = i + 4){
			$('.gallery_type_2 > div').eq(i-1).css('padding-right','0');
		 }	
		 
		 //friends_list_type_1 
		$('.friends_list_type_1').each(function(){
			var obj_friends_list_type_1 = $('li', $(this));
			 var friends_list_type_1_length = obj_friends_list_type_1.length;
			 for(var i=4; i <= friends_list_type_1_length; i = i + 4){
				$('li', $(this)).eq(i-1).css('width','143px');
			 }	
		});

		 
		//card area

		$('.card_type_sphere').each(function(){

			var cardareaHeight = $(this).height();
			var cardImgTop = (cardareaHeight/2) - 66;

			$('.card_img', $(this)).css('top', cardImgTop);
		});

		$('.card_type_sphere_2').each(function(){

			var cardareaHeight = $(this).height();
			var cardImgTop = (cardareaHeight/2) - 66;

			$('.card_img', $(this)).css('top', cardImgTop);
		});

		$('.online_type_card_area .card_type_sphere:first').css('border','none');
		$('.offline_type_card_area .card_type_sphere:first').css('border','none');
		$('.coline_type_card_area .card_type_sphere:first').css('border','none');

		$('.card_type_sphere table').each(function(){
			$('th:last', $(this)).css('background','#fbfbfb');
			$('td:last', $(this)).css('background','#fbfbfb');
		});

		$('.card_type_sphere_2 table').each(function(){
			$('th:last', $(this)).css('background','#fbfbfb');
			$('td:last', $(this)).css('background','#fbfbfb');
		});

		//joining store area
		$('.joining_store_list_area').each(function(){
				$('.joining_store_list_sphere:first',$(this)).css('border','none');
		});

		$('.joining_store_list_sphere').each(function(){

			var cardareaHeight = $(this).height();
			var cardImgTop = (cardareaHeight/2)-20;
			$('.store', $(this)).css('top', cardImgTop);
		});

		$('.joining_store_list_area:last').css('border-bottom','1px solid #d9d9d9');

		$('.store_search_length_area div').each(function(){
				$('p:eq(0)', $(this)).css('background', 'none');
		});

		//region store info_1
		var cooperStoreHeight = $('.cooper_store_sphere').height();

		if (cooperStoreHeight == 70)
		{
					$('.cooper_store_sphere').each(function(){
						$('.store', $(this)).css('top', '10');
			});
		}
		else {

			$('.cooper_store_sphere').each(function(){

					var cardareaHeight = $(this).height();
					var cardImgTop = (cardareaHeight/2) - 30;

					$('.store', $(this)).css('top', cardImgTop);
			});
		}

		$('.store_belong_area').each(function(){

			var cardareaHeight = $(this).height();
			var exceptHeight = $('.store_belong_intro').height();
			var infoHeight = (cardareaHeight-exceptHeight);

			var cardImgTop = ((cardareaHeight-exceptHeight)/2) - 40;

			if (infoHeight < 120)
			{
				$('.store_belong_area .info').css('height','110px');
				$('.store', $(this)).css('top', '10px');
			}else
			{$('.store', $(this)).css('top', cardImgTop);}

		});

		$('.online_cooper_store_area').each(function(){

			var cardareaHeight = $(this).height();			
			var cardImgTop = (cardareaHeight/2) - 45;

			if(cardareaHeight < 106)
			{
				$('.store', $(this)).css('top', '5px');
			}
			else{
				$('.store', $(this)).css('top', cardImgTop);
			}
			
		});

		//region store info_2
		 $(".store_image_sphere .btns > button").click(function(e) {
			  $(this).siblings().each(function(){
				$(this).css("background-image",  $(this).css("background-image").replace(/_on\./, "_off."));
			  });

			  $(this).css("background-image",  $(this).css("background-image").replace(/_off\./, "_on."));

			  $(".store_image_sphere p img").addClass("haze");
			  thisIdx = $(">button", $(this).parent()).index($(this));
			  $(".store_image_sphere p img").eq(thisIdx).removeClass("haze")
		 });

		//pointCard layer Control
		$('.btn_fit_card button').click(function(){
			$('#fit_for_me_layer').removeClass('haze');
		});

		$('#fit_for_me_layer .btn_close button').click(function(){
			$(this).parent().parent().addClass('haze');
		});

		$('#fit_for_me_list_layer .btn_close button').click(function(){
			$(this).parent().parent().addClass('haze');
		});

		//coupon layer Control
		$('#coupon_print_layer .btn_close button').click(function() { $(this).parent().parent().hide(); });

		//PointJoin calendar Control
		$('.event_preiod_sphere button').eq(0).click(function(){
			$('#select_calendar_layer').show().css('left','91px');
		});
		$('.event_preiod_sphere button').eq(1).click(function(){
			$('#select_calendar_layer').show().css('left','190px');
		});

		//event
		$('.selected_event_sphere span').text($('.select_event_radio[checked]').val());

		$('.select_event_radio').click(function(){
			$('.selected_event_sphere span').text($(this).val());
		});

		$('.event_name_sphere .event_name').one('click',function(){
			$(this).val('');
		});
		
	 	//evet_email
		$('.email_select_address').change(function(){
					
			var address = $('.email_select_address').val();

			if(address == 01){
				$('.email_selectedaddress').removeAttr("disabled") 
				$('.email_selectedaddress').focus();
				$('.email_selectedaddress').val('');
			}
			else{
				$('#selectedaddress').val(address);
			}
	
		});

		$('.email_id_write').one('click',function(){
			$(this).val('');
		});

		$('.receive_preson_sphere textarea').one('click',function(){
			$(this).val('');
		});

		//FAQ	
		
		//faq_tab_navi
		$(".faq_tab_navi > a").eq(0).css('background','none');
		 $(".faq_tab_navi > a").click(function(){
			$(".faq_tab_navi > a").removeClass();
			$(this).addClass('selected');
		});
		
		//100122
		//faq_tab_navi 
		$(".faq_tab_navi_mcp > a").eq(0).css('background','none');
		 $(".faq_tab_navi_mcp > a").click(function(){
			$(".faq_tab_navi_mcp > a").removeClass();
			$(this).addClass('selected');
		});
		
		//join submain
		$('.m_event_winner_sphere_02 .info_write').one('click',function(){
			$(this).val('');
		});

		//joinhands store result
		$('.store_event_area .release_sphere div:even').css('padding-right','54px');
		$('.store_event_area .release_sphere_2 div:even').css('padding-right','54px');

		$('.joinhands_ad_movie_sphere button').click(function() {
				$('.joinhands_ad_movie_sphere .movie').slideToggle();
		});


//file field for design
    var appendFile = $(".ghost_file_field");
    $(appendFile).css('opacity', 0);
    $(appendFile).change(function() {
        if ($(appendFile).val().toLowerCase().match(/.(ppt|pdf|doc|hwp|zip)$/i)) {
            $('.file_append_field').attr('value', appendFile.attr('value'));
        } else {
            $('.file_append_field').val('');
            $('#chkSize').jqmShow();
            //$(appendFile).select();
            //document.selection.clear();
            $(appendFile).val('');
            $('.file_append_field').focus();
        }
    });

		//search auto complete

		$('.search_auto_complete_sphere .array_modify button').focus(function(){$(this).blur();});		
		
		$('.search_auto_complete_sphere_2 .array_modify button').focus(function(){$(this).blur();});
	
		
		//faq search

		$('.etc_search_sphere .range button').toggle(
				function(){$('.etc_search_sphere .range div').show();},
				function(){$('.etc_search_sphere .range div').hide();}
		);

		$('.etc_search_sphere .search .search_write').focus(
				function(){$('.etc_search_sphere .range div').hide();}
		);

		$('.etc_search_sphere .range ul li').hover(
				function(){$(this).css('cursor','pointer');}
		);
		$('.etc_search_sphere .range ul li').click(
				function(){
				$('.etc_search_sphere .range input').attr('value',$(this).text());
				$('.etc_search_sphere .range div').hide();		
		});
		
		$('a:last' ,'.unify_popular_word_sphere p').css('background','none');

		
		//unify search navi area
		$('.search_tab_navi a:first').css('background','none');
		$('.search_tab_navi a:eq(1)').css('background','none');
		$('.search_tab_navi a').focus(function(){$(this).blur();});
		
		$('.search_tab_navi a').click(function(){
			$('.search_tab_navi a').removeClass('selected');
			$(this).addClass('selected');
			$('.search_tab_navi a').css('background',"url('../Images/Common/Util/bg_bar_1.gif') no-repeat left 8px");
			$('.search_tab_navi a:first').css('background','none');
			$(this).next().css('background','none');
			$(this).css('background','none');
		});

		//$('.search_tab_navi_2 a:first').css({'background':'none', 'padding-left':'0'});
		$('.search_tab_navi_2').each(function(){
			$('a:first', $(this)).css({'background':'none', 'padding-left':'0'});
		});

		$('.search_tab_navi_2 a').focus(function(){$(this).blur();});

		$('.search_tab_navi_area').hide();
		$('.search_tab_navi_area').eq(0).show();

		$('.search_tab_navi_2 a').click(function(){
			var viewLeft =  $(this).offset().left - $(this).parent().offset().left;
			var tabWidth =  $(this).width();
			var halftabWidth = (tabWidth/2);
			var realPosition =  viewLeft+halftabWidth + parseInt($(this).css('padding-left'));
			var realPositionfirst =  viewLeft+halftabWidth;
			$('.search_tab_navi_2').css('backgroundPosition', realPosition+'px bottom');
			$('.search_tab_navi_2').each(function(){
				$('a:first', $(this)).css({'background':'none', 'padding-left':'0'});
			});
			$('.search_tab_navi_2 a').removeClass('selected');
			$(this).addClass('selected');

			$(".search_tab_navi_area").hide();

			thisIdx = $(">a", $(this).parent()).index($(this));
			$viewTab = $(".search_tab_navi_area").eq(thisIdx);
			$viewTab.show();

		});

		//print layer

		$('.btn_print_contents').click(function(){
			$('.jqmWindow_print').jqmShow();
			contentsPreview = $('#contents_zone').html();
			$('#contents_print_preview .contents_for_print').html(contentsPreview);
			$('#contents_print_preview .control_sphere').hide();
			
		});

		$('.print_layer_btns .btns_1').click(function(){
			$('.jqmWindow_print').jqmHide();
			 window.print();
		});

		$('.print_layer_btns .btns_2').click(function(){
			 $('.jqmWindow_print').jqmHide();
		});


		var bodyHeight = $('#body_wrap').height();
		var printPreviewHeight = parseInt(bodyHeight*0.7);
		var printContentsHeight = parseInt(printPreviewHeight-170);

		$('#contents_print_preview').css('height',printPreviewHeight);
		$('.contents_for_print').css('height',printContentsHeight);



		//coupon print layer

		$('#coupon_print_layer').addClass('haze');
		$('#coupon_print_layer').css('top','-900px');

		$('.btn_to_print_coupon').click(function(){
			contentsPreview = $('#coupon_print_layer').html();
			$('#coupon_preview div').html(contentsPreview);
			$('.jqmWindow_print_coupon').jqmShow();
		});

		$('.#coupon_preview .btn_print').click(function(){
			$('head').append("<link rel='stylesheet' media='print' href='../css/coupon_print.css' type='text/css' />");
			$(this).hide();
			window.print();
			$(this).show();
			$('.jqmWindow_print_coupon').jqmHide();
			
		});
		
		$('#coupon_preview .btn_close').click(function(){
			 $('.jqmWindow_print_coupon').jqmHide();
		});

		//PointAmass joining hands view

		var storeInfoWrap1 = $('.store_image_sphere').parent(); 
		
		$('.basic_info_list', storeInfoWrap1).css({
			'float':'left',
			'width':'509px'		
		});

		// ?쒗쑕移대뱶 ?곸꽭蹂닿린 ?リ린
		$('.card_info_detail_layer .btns button').click(function(){$(this).parent().parent().hide();});

				
		// Mypage
		$('.refer_goods_area .goods_sphere .goods').eq(4).css('padding','0');

		$('.additional_info_4').each(function(){
			var infoHeight = $('div', $(this)).height();
			var infoTitleOffsetTop = (infoHeight/2)-20;
			$('h3', $(this)).css('padding-top',infoTitleOffsetTop);		
			var infoTitleinfoHeight = ($('h3', $(this)).height()) + infoTitleOffsetTop;
			$('button.add', $(this)).css('top',infoTitleinfoHeight+35);
		});

		$('.additional_info_5').each(function(){
			var infoHeight = $('div', $(this)).height();
			var infoTitleOffsetTop = (infoHeight/2)-20;
			$('h3', $(this)).css('padding-top',infoTitleOffsetTop);		
			var infoTitleinfoHeight = ($('h3', $(this)).height()) + infoTitleOffsetTop;
			$('button.add', $(this)).css('top',infoTitleinfoHeight+35);
		});

});



//smartbar center align
	
function fixLeft(){
	$('#smart_bar_zone').css('left',$("#contents_wrap").offset().left);
}


//IE6 png?⑥튂
function setPng24(obj) { 
    obj.width=obj.height=1; 
    obj.className=obj.className.replace(/\bpng24\b/i,''); 
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image'); "
    obj.src='../../Images/Common/Util/blank.gif'; // 1*1?쎌????щ챸??blank.gif ?대?吏媛 諛섎뱶??議댁옱?댁빞 ?쒕떎.
    return ''; 
}

//GNB HeightReset
 function setNaviHeightReset(height){	
		$('#top_navi').css('height', height);
		$('#gnb_area').css('height', height);
		$('#gnb_area iframe').css('height', height);}

//location HeightReset
 function sendToJS(value){	
		$('#locationMap').css('height', value);
		$('.location_area').css('height', value);
		$('.location_area iframe').css('height', value);}

 function gotoTop(){	
	$('#body_wrap').animate( { scrollTop: 0 }, 'fast' );
 }

//goTop HeightReset
 function sendToHeight(value){	
		$('#gotop').css('height', value);		
		$('#TopBanner').css('height', value);	
		}

//
function siteJumpWidthReset(){
	var siteJumgWidht = $('#site_jump_gnb_aaa').width();
	if (siteJumgWidht < 995)
	{
		$('#site_jump_gnb_aaa').css('width', 995);
	}
}



// 怨듯넻 ?덉씠?댄뙘?
function ShowCommLayerPopup(mode, objId, strTitle, strContents) {
$(window).load(function() {
if (mode == 'TC') {
$('#' + objId + ' h1').html(strTitle);
$('#' + objId + ' .msg').html(strContents);
}
else {
$('#' + objId + ' .msg_center').html(strContents);
}
$('#' + objId).jqmShow();
});
}

function HideCommLayerPopup(objId) {
$('#' + objId).hide();
} 


