if (typeof c2 == 'undefined') {
    c2 = { };
}

c2.section = {
    strImgPrefix: '',
	strPosition: '',

    init:
        function () {
            var objThis = c2.section;

            objThis.resizeIframeBody(); 
            $listener($('iframeBody'), 'load', objThis.resizeIframeBody);
            $listener($('hrefChangeAccount'), 'click', objThis.showChangeAccountLayer);
            $listener($('aBtnGnbShowLayer'), 'click', objThis.showChangeAccountLayerGNB);
            $listener($('hrefChangeAccount'), 'dblclick', objThis.showChangeAccountLayer);
        },

    resizeIframeBody:
        function () {
            try {
                //Swaf.Dom.autoResizeIFrame($('iframeBody'));
                Swaf.Dom.autoHeightIFrame($('iframeBody'), 800);
	            var size = Swaf.Dom.getSize($("iframeBody"));
				if (size.height < 100) {
					Swaf.Dom.autoHeightIFrame($('iframeBody'), 800);
				}
            } catch (e) {
            }
        },

    showChangeAccountLayer:
        function (evt, obj) {
            var objThis = c2.section;

			if (objThis.strPosition == 'gnb') {
				$('imgGnbAltAccountShow').src = objThis.strImgPrefix + 'section/ico_gnbNameDown.gif'; 
			}
			else {
				toggleLayer('C2Layer02'); 
			}

            if (Swaf.Dom.getStyle($('C2Layer02'), 'display') == 'none') 
                $('C2Arrow02').src = objThis.strImgPrefix + 'section/ico_gnbName.gif';
            else 
                $('C2Arrow02').src = objThis.strImgPrefix + 'section/ico_gnbNameDown.gif'; 

            var rect = Swaf.Dom.getRect($('C2Arrow02'));
			var layer = Swaf.Dom.getRect($('C2Layer02'));
            //var x = rect.x - rect.width;
            var x = rect.x - (layer.width - rect.width) / 2;
            var y = rect.y + rect.height + 3;
            if (x < 0) x = 0;
            Swaf.Dom.setPosition($('C2Layer02'), x, y);
			
			objThis.strPosition = 'personal_area';

            Event.stop(evt);
        },

    showChangeAccountLayerGNB:
        function (evt, obj) {
            var objThis = c2.section;

			if (objThis.strPosition == 'personal_area') {
				$('C2Arrow02').src = objThis.strImgPrefix + 'section/ico_gnbNameDown.gif'; 
			}
			else {
				toggleLayer('C2Layer02'); 
			}

            if (Swaf.Dom.getStyle($('C2Layer02'), 'display') == 'none') 
                $('imgGnbAltAccountShow').src = objThis.strImgPrefix + 'section/ico_gnbName.gif';
            else 
                $('imgGnbAltAccountShow').src = objThis.strImgPrefix + 'section/ico_gnbNameDown.gif'; 

            var rect = Swaf.Dom.getRect($('imgGnbAltAccountShow'));
			var layer = Swaf.Dom.getRect($('C2Layer02'));
            //var x = rect.x - rect.width;
            var x = rect.x - (layer.width - rect.width) / 2;
            var y = rect.y + rect.height + 3;
            if (x < 0) x = 0;
            Swaf.Dom.setPosition($('C2Layer02'), x, y); 
			
			objThis.strPosition = 'gnb';

            Event.stop(evt);
        }
}

function personalSet(response) {
    var strID = response.value.home_id;

    $('spanAccountVisitorCnt_'+strID).innerHTML = response.value.visitor_cnt;
    $('spanAccountPublishCnt_'+strID).innerHTML = response.value.publish_cnt;
    $('spanAccountPresentCnt_'+strID).innerHTML = response.value.present_cnt;
    $('spanAccountAcornCnt_'+strID).innerHTML   = response.value.acorn_cnt;
/*    $('spanAccountMessageCnt_'+strID).innerHTML = response.value.message_cnt;
    $('spanAccountOnedegCnt_'+strID).innerHTML  = response.value.onedeg_cnt;
    $('spanAccountInviteCnt_'+strID).innerHTML  = response.value.invite_cnt;
*/    
    /*
    if (response.value.visitor_cnt > 0) 
        Swaf.Dom.setStyle($('imgAccountVisitorNew_'+strID), 'display', 'inline'); 
    */
    if (response.value.publish_cnt > 0)
        Swaf.Dom.setStyle($('imgAccountPublishNew_'+strID), 'display', 'inline');
    /*
    if (response.value.comment_cnt > 0) 
        Swaf.Dom.setStyle($('imgAccountPresentNew_'+strID), 'display', 'inline');
    */
}

function personalInit() {
    Swaf.Ajax.ajaxRequest('/section/main/retrievePersonalInfo.php', personalSet, 'post', 'JSON');
}

function accountLayerSet(response) {
    var strID = response.value.home_id;

    $('spanAccountVisitorCnt_'+strID).innerHTML = response.value.visitor_cnt;
    /*
    if (response.value.visitor_cnt > 0) 
        Swaf.Dom.setStyle($('imgAccountVisitorNew_'+strID), 'display', 'inline'); 
    */

    $('spanAccountPublishCnt_'+strID).innerHTML = response.value.publish_cnt;
    if (response.value.publish_cnt > 0)
        Swaf.Dom.setStyle($('imgAccountPublishNew_'+strID), 'display', 'inline');

    if (document.getElementById('spanAccountCommentCnt_'+strID) != null) {
        $('spanAccountCommentCnt_'+strID).innerHTML = response.value.comment_cnt;
        if (response.value.comment_cnt > 0) 
            Swaf.Dom.setStyle($('imgAccountCommentNew_'+strID), 'display', 'inline');
    }
}

function accountLayerFold(pStrID) { 
    Swaf.Dom.setStyle($('divAccountFold_'+pStrID), 'display', 'block'); 
    Swaf.Dom.setStyle($('divAccountUnfold_'+pStrID), 'display', 'none');
}

function accountLayerUnfold(pStrID) {
    Swaf.Dom.setStyle($('divAccountUnfold_'+pStrID), 'display', 'block');
    Swaf.Dom.setStyle($('divAccountFold_'+pStrID), 'display', 'none');

    if ($('spanAccountVisitorCnt_'+pStrID).innerHTML == '..') { 
        Swaf.Ajax.ajaxRequest('/section/main/retrieveNewCnt.php?withVisitbook=1&home_id='+pStrID, accountLayerSet, 'post', 'JSON');
    }
}

function accountLayerToggle(src,pStrID) {
	var onoff = $attr(src, 'onoff');
	if (onoff == 'on') {
		src.setAttribute("swaf:onoff", "off");
		Swaf.Dom.removeCSSClass($('divAccount_'+pStrID), 'select'); 
	}
	else {
		Swaf.Dom.addCSSClass($('divAccount_'+pStrID), 'select'); 
		if ($('spanAccountVisitorCnt_'+pStrID).innerHTML == '..') { 
			Swaf.Ajax.ajaxRequest('/section/main/retrieveNewCnt.php?withVisitbook=1&home_id='+pStrID, accountLayerSet, 'post', 'JSON');
		}
		src.setAttribute("swaf:onoff", "on");
	}
}

// 홈 계정 만들기 > 일촌 맺기용
function resizeIframeHeightBy() {
    c2.section.resizeIframeBody();
}

function onClickPresent(evt, strType, strID) {
    if ($('spanAccountPresentCnt_'+strID).innerHTML == 0) {
        alert('받으실 선물이 없습니다.');
        Event.stop(evt);
        return false;
    }

    if (strType == 'c1') {
        window.open('http://cyworld.com/mall/common/mall5_gift_pop.asp','giftrecieve_reopen','height=600,width=416,scrollbars=yes,resizable=no').focus();
        Event.stop(evt);
        return false;
    }
    else if (strType == 'mybase') {
        return;
    }
}

function goHome2Agree( ) { // 팝업 윈도우 호출 부분 
	var myWin = window.open('http://c2img.cyworld.com/img/html/www/policy_popup.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrolling=yes'); 
} 

