/****************************************************************
** URL 정리
****************************************************************/
function urlParse(url) {
	var strLocation = url.split('?');
	var strResult = new Array();
	var i =0;

	if(strLocation.length > 1) {
		strsplitLocation = strLocation[1].split('&');

		for(i=0; i<strsplitLocation.length; i++) {
			strsplitLocation[i] = strsplitLocation[i].split('=');

			if(strsplitLocation[i][1] != 'undefined') {
				strResult[i] = strsplitLocation[i][0] + "=" + strsplitLocation[i][1];
			}
		}
	}
	result = strLocation[0] + "?" + strResult.join('&');
	return result;
}

/****************************************************************
** 메인서브 이동
****************************************************************/
function goMain( id, mode, type, met, vt, category, no ) {
	Url = "main_sub.html?mTop=" + id + "&mode=" + mode + "&type=" + type + "&met=" + met + "&vt=" + vt +"&category=" + category + "&no=" + no;
	xUrl = urlParse(Url);
	location.href = xUrl;
}


/* 새 창 띄우기 */
function PopWin( Url, Xsize, Ysize, Scroll )
{
	var opt = "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,copyhistory=1,"

	if( Xsize  == null ) Xsize  = 500
	if( Ysize  == null ) Ysize  = 400
	if( Scroll == null ) Scroll = 1

	opt = "width=" + Xsize + ",height=" + Ysize + ",scrollbars=" + Scroll
	newWindow = window.open( Url, 'popSub', opt)
	newWindow.focus()
}

/* 링크된 텍스트 칼라 바꾸기 */
function setHover( color )
{
    var object = window.event.srcElement

    object.defaultColor = object.style.color
    object.style.color = color

	if( object.title )
	{
		window.status = object.title
	}

    object.onmouseout = function()
    {
        object.style.color = object.defaultColor

		if( object.title )
		{
			window.status = ''
		}
    }

	return true
}

/* 마우스 오버 이미지 바꾸기 */
var overImage = new Array(1000);

for( var i = 0; i < 1000; i++ )
overImage[i] = new Image();

overImage[1].src = 'img/menuHouse01e.gif';
overImage[2].src = 'img/menuHouse02e.gif';
overImage[3].src = 'img/menuHouse03e.gif';
overImage[4].src = 'img/menuHouse04e.gif';
overImage[5].src = 'img/menuHouse05e.gif';

overImage[11].src = 'img/menuTopA0000e.gif';
overImage[12].src = 'img/menuTopB0000e.gif';
overImage[13].src = 'img/menuTopC0000e.gif';
overImage[14].src = 'img/menuTopD0000e.gif';


overImage[101].src = 'img/menuSubA1000e.gif';
overImage[102].src = 'img/menuSubA2000e.gif';
overImage[103].src = 'img/menuSubA3000e.gif';
overImage[104].src = 'img/menuSubA4000e.gif';
overImage[105].src = 'img/menuSubA5000e.gif';

overImage[201].src = 'img/menuSubB1000e.gif';
overImage[202].src = 'img/menuSubB2000e.gif';
overImage[203].src = 'img/menuSubB3000e.gif';

overImage[301].src = 'img/menuSubC1000e.gif';
overImage[302].src = 'img/menuSubC2000e.gif';

overImage[401].src = 'img/menuSubD1000e.gif';
overImage[402].src = 'img/menuSubD2000e.gif';
overImage[403].src = 'img/menuSubD3000e.gif';


function inner_rolloverMenu( num, image )
{
	if( !image.gimaSet )
	image.defaultSrc = image.src;
	image.src = overImage[num].src;

	if( !image.gimaSet )
	{
		image.onmouseout = function()
		{
			image.src = image.defaultSrc;
			image.gimaSet = true;
		}
	}
}

/* input 폼의 기본 글씨 사라지게 */
function OnEnter( Obj ){ if( Obj.value == Obj.defaultValue ) Obj.value = '' }
function OnExit ( Obj ){ if( Obj.value == '' ) Obj.value = Obj.defaultValue }


/* 스크롤해도 따라다니는 메뉴 */
function initMoving(target, position, topLimit, btmLimit) {
    if (!target)
        return false;

    var obj = target;
    obj.initTop = position;
    obj.topLimit = topLimit;
    obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

    obj.style.position = "absolute";
    obj.top = obj.initTop;
    obj.left = obj.initLeft;

    if (typeof(window.pageYOffset) == "number") {
        obj.getTop = function() {
            return window.pageYOffset;
        }
    } else if (typeof(document.documentElement.scrollTop) == "number") {
        obj.getTop = function() {
            return document.documentElement.scrollTop;
        }
    } else {
        obj.getTop = function() {
            return 0;
        }
    }

    if (self.innerHeight) {
        obj.getHeight = function() {
            return self.innerHeight;
        }
    } else if(document.documentElement.clientHeight) {
        obj.getHeight = function() {
            return document.documentElement.clientHeight;
        }
    } else {
        obj.getHeight = function() {
            return 500;
        }
    }

    obj.move = setInterval(function() {
        if (obj.initTop > 0) {
            pos = obj.getTop() + obj.initTop;
        } else {
            pos = obj.getTop() + obj.getHeight() + obj.initTop;
            //pos = obj.getTop() + obj.getHeight() / 2 - 15;
        }

        if (pos > obj.bottomLimit)
            pos = obj.bottomLimit;
        if (pos < obj.topLimit)
            pos = obj.topLimit;

        interval = obj.top - pos;
        obj.top = obj.top - interval / 3;
        obj.style.top = obj.top + "px";
    }, 30)
}
