var EPSN={};
var setwidth;
var setheight;
var mappanelheight;

var TopPanelHeight=87;
var LeftPanelWidth;
var LeftPanelSWidth=30;
var BottomPanelHeight=200;
var RightPanelWidth=314;
var CopyPanelHeight=50;
var DMargin=5;
var Gap=7;

var L_State=false;
var B_State=false;
var R_State=false;

var RNB="B";

//var $j = jQuery.noConflict();


$(document).ready(function(){
	
	//document.createElement("<div>");
	//$("#SearchPopup > ul").tabs();
	
	var imap= document.createElement("iframe");
	
	imap.style.width='100%';
	imap.id='mapiframe';
	imap.name='mapiframe';
	imap.style.height='100%';
	imap.style.paddingTop="0px";
	imap.frameBorder='0'
	//imap.style.border='0'
	imap.style.marginheight='0'
	imap.style.marginWidth='0'
	imap.scrolling='no'
	imap.src='map.php'
	
	//maploadid.appendChild(imap);

	$("#mappanel").append(imap)

		
	
	LeftPanelWidth=300

	EPSN.SetdivReSize();
	
	setwidth=$(window).width();
	setheight=$(window).height();

	$("#mainpanel").height(setheight -10)
	$("#mainpanel").width(setwidth -10)
	

	mappanelheight=$("#mappanel").height();

	//LeftPanel
	leftpanel_height=parseInt(setheight) - (parseInt(TopPanelHeight) + CopyPanelHeight);

	$("#leftpanel").css({top:parseInt(TopPanelHeight + DMargin) ,width:LeftPanelSWidth, height : leftpanel_height})
	
	//CopyPanel
	$("#copypanel").css({top: (setheight - (CopyPanelHeight  + TopPanelHeight -(DMargin * 2) )),height : CopyPanelHeight})
	
	//MapPanel
	$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin,width : setwidth - (LeftPanelSWidth + (DMargin*2) + Gap)  , height : leftpanel_height , left: LeftPanelSWidth + Gap })
	

	$("#left_hidden").hide();

	$("#left_hidden").click(function(){
		EPSN.LeftPanelResize(LeftPanelWidth,"","")
	});
	$("#left_show").click(function(){
		EPSN.LeftPanelResize(LeftPanelWidth,"","+")
	});

	$("#BTB").add("#bottom_hidden").add("#bottom_location").click(function(){
		EPSN.BottomPanelResize(false);
	});
	$("#BTR").add("#right_hidden").add("#right_location").click(function(){
		EPSN.RightPanelResize(false);
	});
	

	//등록
	$("#regist_button").click(function(){

		if (!USERID.getid.uid)
		{
			OnBlind("",250,150,"loginchk","로그인 확인");
		}else{
			LeftPanelWidth=357;
			EPSN.LeftPanelResize(LeftPanelWidth,"resize","regist");
			Button_click("regist_button")
		}
	});
	
	//마이이포지션
	$("#myep_button").click(function(){
		if (!USERID.getid.uid)
		{
			OnBlind("",250,150,"loginchk","로그인 확인");
		}else{

			LeftPanelWidth=357;
			EPSN.LeftPanelResize(LeftPanelWidth,"resize","myep");
			Button_click("myep_button")
		}
	});
	//즐겨찾기
	$("#favorite_button").click(function(){
		if (!USERID.getid.uid)
		{
			OnBlind("",250,150,"loginchk","로그인 확인");
		}else{
			LeftPanelWidth=357;
			EPSN.LeftPanelResize(LeftPanelWidth,"resize","favorite");
			Button_click("favorite_button")
		}
	});

	$("#open_button").click(function(){
		LeftPanelWidth=357;
		EPSN.LeftPanelResize(LeftPanelWidth,"resize","open");
		Button_click("open_button")
	});
	
	$("#cate_button").click(function(){
	
		
			LeftPanelWidth=357;
			EPSN.LeftPanelResize(LeftPanelWidth,"resize","cate");
			Button_click("cate_button")

		
		//Button_click("open_button")
	});
	$("#recent_button").click(function(){
	
		
			LeftPanelWidth=357;
			EPSN.LeftPanelResize(LeftPanelWidth,"resize","recent");
			Button_click("recent_button")

		
		//Button_click("open_button")
	});

	$("#thema_button").click(function(){
		LeftPanelWidth=357;
		EPSN.LeftPanelResize(LeftPanelWidth,"resize","thema");
		Button_click("thema_button")
	});
	$("#BTMEMBER").click(function(){
		 if (isUndefined(USERID.getid.uid)){
			OnBlind("",430,350,"membermodify","회원정보수정");
		 }else{
			 OnBlind("",430,600,"memberjoin","회원가입");
		 }
		//EPSN.NewDiv("","200","300");
	});
    

	$("#BTLOGIN").click(function(){
   	 
		 if (isUndefined(USERID.getid.uid)){
			// alert(USERID.getid.uid)
			OnBlind("",300,100,"memberlogout","로그아웃");

		 }else{

			 OnBlind("",410,250,"memberlogin","회원 로그인");
		 }
		
		//EPSN.NewDiv("","200","300");
	});

	$("#BTENG").click(function(){
   		alert(USERID.getid.uname)
		//EPSN.NewDiv("","200","300");
	});

	$("#BTSEARCHBAR").click(function(){
   		//alert(USERID.getid.uname)
		//EPSN.NewDiv("","200","300");
		  $("#SearchPopup").slideToggle("fast");

	});
	
	$("#mytel_button").click(function(){
		if (!USERID.getid.uid)
		{
			OnBlind("",250,150,"loginchk","로그인 확인");
		}else{
			OnBlind("",550,400,"mytelbox","MY 주소록");

		}


	});
	//google_mapload()
	
	//setTimeout("MAPS.Control.mapload()",1000)
	
});

$(window).resize( function() {  EPSN.SetdivReSize(); } );
var a=true;
EPSN.SetdivReSize=function(){

	setwidth=$(window).width();
	setheight=$(window).height();
	mappanelheight=$("#mappanel").height();
	$("#mainpanel").height(setheight -10)
	$("#mainpanel").width(setwidth -10)
	
	//LeftPanel

	leftpanel_height=parseInt(setheight) - (parseInt(TopPanelHeight) + CopyPanelHeight);
	$("#toppanel").css({height : TopPanelHeight})

	$("#leftpanel").css({top:parseInt(TopPanelHeight) + 5 ,height : leftpanel_height})
	

	//CopyPanel
		$("#copypanel").css({top: (setheight - (CopyPanelHeight  + TopPanelHeight - (DMargin * 2) )),height : CopyPanelHeight})

	//$("#copypanel").css({top: (setheight - (CopyPanelHeight + DMargin))})
	//$("#copypanel").css({top: (setheight - (CopyPanelHeight + DMargin)),height : CopyPanelHeight})

	//MapPanel
	
	if (L_State==true){
		$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin,width : setwidth -(LeftPanelWidth + (DMargin*2) + Gap) , height : leftpanel_height })	
	}else{
		$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin,width : setwidth -(LeftPanelSWidth + (DMargin*2) + Gap) , height : leftpanel_height })	
	}
	
	if (B_State==true){
		EPSN.BottomPanelResize(true)
	}
	
	if (R_State==true){
		if (L_State==true){
			$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin,width : setwidth -(LeftPanelWidth + RightPanelWidth + (DMargin*2) + Gap) , height : leftpanel_height})	
		}else{
			$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin,width : setwidth -(LeftPanelSWidth+RightPanelWidth + (DMargin*2) + Gap), height : leftpanel_height })	
		}
		EPSN.RightPanelResize(true)
	}

	
	$("#SearchPopup1").css({top:(TopPanelHeight + (DMargin *2 )) ,left:(setwidth/2) - (200)});


	//Log
	/*
	$("#toppanel").html(
		"mainpanel width:"+setwidth + " mainpanel height:" + setheight + 
		"<br> leftpanel setwidth : " + parseInt(setwidth) 
	
	);
	*/
}	

EPSN.LeftPanelResize=function(LeftPanelWidth,add,contents){
	//LeftPanelWidth=LeftPanelWidth


	
	if (L_State==true){
		
		
		if (add=="resize")
		{

			if (contents!="")
			{
				OnContents(contents)

			}else{
				OffContents()
			}


			var width=$("#leftpanel").width();

			if (width==LeftPanelWidth) return false;

			$("#leftpanel").animate( { width:LeftPanelWidth}, {queue:false,duration: 500} )
		
			if (R_State==true){
				$("#mappanel").animate({"left": "+="+ (LeftPanelWidth - width)}, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth + RightPanelWidth + (DMargin*2) +Gap)});
			}else{
				$("#mappanel").animate({"left": "+="+ (LeftPanelWidth - width)}, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth +(DMargin*2)+Gap) });
			}
			
			if (B_State==true){
			
				$("#bottompanel").animate({"left": "+=" + (LeftPanelWidth - (width) ) }, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth+ (DMargin*2) + Gap)});
			}


			return false;
		}
		
		
		
		
		L_State=false;

		$("#leftpanel").animate( { width:LeftPanelSWidth}, {queue:false,duration: 500})
		
		
		
		if (R_State==true){
			$("#mappanel").animate({"left": "-="+ (LeftPanelWidth - LeftPanelSWidth) }, {queue:false,duration: 500}).css( {width:setwidth - (RightPanelWidth + LeftPanelSWidth+ (DMargin*2) +Gap )});
		}else{
			$("#mappanel").animate({"left": "-="+ (LeftPanelWidth - LeftPanelSWidth) }, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelSWidth+ (DMargin*2)+Gap) });
		}
		
		if (B_State==true){
			$("#bottompanel").animate({"left": "-="+ (LeftPanelWidth - (LeftPanelSWidth)) }, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelSWidth+ (DMargin*2) + Gap)});
			//alert(LeftPanelSWidth + " " + Gap)
		}
		
		$("#left_hidden").hide();
		$("#left_show").show();

	
	}else{
		L_State=true;

		$("#leftpanel").animate( { width:LeftPanelWidth}, {queue:false,duration: 200} )
		
		if (R_State==true){
			$("#mappanel").animate({"left": "+="+ (LeftPanelWidth - LeftPanelSWidth)}, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth + RightPanelWidth + (DMargin*2)+Gap )});
		}else{
			$("#mappanel").animate({"left": "+="+ (LeftPanelWidth - LeftPanelSWidth)}, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth +(DMargin*2)+Gap) });
		}
		
		
		$("#left_show").hide();
		$("#left_hidden").show();

		if (B_State==true){
		
			$("#bottompanel").animate({"left": "+=" + (LeftPanelWidth - (LeftPanelSWidth)) }, {queue:false,duration: 500}).css( {width:setwidth - (LeftPanelWidth+ (DMargin*2) + Gap)});
		}

	}

	if (contents!="")
	{
		OnContents(contents)

	}else{
		OffContents()
	}

	

}

EPSN.BottomPanelResize=function(RS){
	RNB="B";
//	EPSN.contents.Contents_Basic_infoview();

	mappanelheight=$("#mappanel").height();
	mappanelwidth=$("#mappanel").width();

	if (R_State==true){
		R_State=false
		$("#rightpanel").hide()
		$("#mappanel").animate({"width": "+=" + RightPanelWidth}, {queue:false,duration: 500});
		//mappanelheight=mappanelheight+200
	}
 
	//보톰판넬 true 이면서 리사이즈 가 false 일때
	if (B_State==true && RS==false){
		B_State=false;
		$("#mappanel").animate({"height": "+="+BottomPanelHeight}, {queue:false,duration: 500});
		
		$("#bottompanel").hide()
	
	}else{
		B_State=true;
		//리사이즈 가 false 일때
		if (RS==false){
			
			
			$("#mappanel").animate({"height": "-="+BottomPanelHeight}, {queue:false,duration: 500});
			
			if (L_State==true){
				$("#bottompanel").css({left: LeftPanelWidth +Gap ,top:parseInt( TopPanelHeight + mappanelheight - BottomPanelHeight) + DMargin,width : setwidth - (LeftPanelWidth + (DMargin*2) +Gap) , height : BottomPanelHeight })
			}else{
				$("#bottompanel").css({left: LeftPanelSWidth+Gap,top:parseInt( TopPanelHeight + mappanelheight -BottomPanelHeight ) + DMargin,width : setwidth -(LeftPanelSWidth + (DMargin*2)+Gap) , height : BottomPanelHeight })
			}
			
			

			$("#bottompanel").show()
			//alert($("#mappanel").width() + " " +  $("#bottompanel").width())
			$("#bottom_hidden ").show()
			$("#right_location ").show()
		}else{
		
			if (L_State==true){
				$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin, height : leftpanel_height- BottomPanelHeight })	
				//$("#bottompanel").css({left: LeftPanelWidth ,top:parseInt( TopPanelHeight + mappanelheight -BottomPanelHeight) + DMargin,width : setwidth -(LeftPanelWidth + (DMargin*2)) , height : BottomPanelHeight })
				$("#bottompanel").css({left: LeftPanelWidth + Gap ,top:parseInt( TopPanelHeight + mappanelheight -BottomPanelHeight) + DMargin,width : setwidth -(LeftPanelWidth + (DMargin*2) + Gap) , height : BottomPanelHeight })
				//alert(LeftPanelWidth + " "  + (DMargin*2))
			}else{
				$("#mappanel").css({top:parseInt(TopPanelHeight) + DMargin, height : leftpanel_height-BottomPanelHeight })	
				$("#bottompanel").css({left: LeftPanelSWidth+Gap,top:parseInt( TopPanelHeight + mappanelheight -BottomPanelHeight) + DMargin,width : setwidth -(LeftPanelSWidth + (DMargin*2) + Gap) , height : BottomPanelHeight })
			}
		
		}
		


		//$("#bottompanel").css({top: "500px",width : "500px" , height : leftpanel_height })
	}
	setTimeout("EPSN.contents.Contents_Basic_infoview(false)",1000)

	
}

EPSN.RightPanelResize=function(RS){
	mappanelheight=$("#mappanel").height();
	mappanelwidth=$("#mappanel").width();
	
	RNB="R";
//	
	if (B_State==true){
		B_State=false
		$("#bottompanel").hide()
		$("#mappanel").animate({"height": "+=" + BottomPanelHeight}, {queue:false,duration: 500});
		mappanelheight=mappanelheight+BottomPanelHeight
	}

	if (R_State==true && RS==false){
		R_State=false;
		$("#mappanel").animate({"width": "+=" + (RightPanelWidth)}, {queue:false,duration: 500});
		$("#rightpanel").hide();
		$("#right_hidden").hide()
		$("#bottom_location").hide()
	
		}else{
		
		if (RS==false){

			R_State=true;
			$("#mappanel").animate({"width": "-=" + (RightPanelWidth)}, {queue:false,duration: 500});
			$("#rightpanel").css({left: setwidth - (RightPanelWidth+ (DMargin*2)) ,top:parseInt( TopPanelHeight) + DMargin,width : RightPanelWidth , height : mappanelheight })
			$("#rightpanel").show();
			$("#right_hidden").show()
			$("#bottom_location").show()
		}else{

			$("#rightpanel").css({left: setwidth - (RightPanelWidth+ (DMargin*2)) ,top:parseInt( TopPanelHeight) + DMargin,width : RightPanelWidth , height : mappanelheight })

		}

	}
	setTimeout("EPSN.contents.Contents_Basic_infoview(false)",1000)
}


Button_click=function(thisid){

	//open_button myep_button regist_button

	switch(thisid){
		case "regist_button" : $("#regist_button").attr("src","img/menu_1C.gif"); $("#myep_button").attr("src","img/menu_2.gif");$("#thema_button").attr("src","img/menu_3.gif"); $("#open_button").attr("src","img/menu_4.gif");$("#cate_button").attr("src","img/menu_5.gif");$("#recent_button").attr("src","img/menu_6.gif");break;
		case "myep_button" : $("#regist_button").attr("src","img/menu_1.gif"); $("#myep_button").attr("src","img/menu_2C.gif");$("#thema_button").attr("src","img/menu_3.gif");$("#open_button").attr("src","img/menu_4.gif");$("#cate_button").attr("src","img/menu_5.gif");$("#recent_button").attr("src","img/menu_6.gif");break;
		case "open_button" : $("#regist_button").attr("src","img/menu_1.gif"); $("#myep_button").attr("src","img/menu_2.gif");$("#thema_button").attr("src","img/menu_3.gif"); $("#open_button").attr("src","img/menu_4C.gif");$("#cate_button").attr("src","img/menu_5.gif");$("#recent_button").attr("src","img/menu_6.gif");break;
		//case "favorite_button" : $("#regist_button").attr("src","img/menu_2.gif"); $("#myep_button").attr("src","img/menu_3.gif");  $("#open_button").attr("src","img/menu_5.gif");break;
		case "thema_button" : $("#regist_button").attr("src","img/menu_1.gif"); $("#myep_button").attr("src","img/menu_2.gif");$("#thema_button").attr("src","img/menu_3C.gif");$("#open_button").attr("src","img/menu_4.gif");$("#cate_button").attr("src","img/menu_5.gif");$("#recent_button").attr("src","img/menu_6.gif");break;
		case "cate_button" : $("#regist_button").attr("src","img/menu_1.gif"); $("#myep_button").attr("src","img/menu_2.gif");$("#thema_button").attr("src","img/menu_3.gif");$("#open_button").attr("src","img/menu_4.gif");$("#cate_button").attr("src","img/menu_5C.gif");$("#recent_button").attr("src","img/menu_6.gif");break;
		case "recent_button" : $("#regist_button").attr("src","img/menu_1.gif"); $("#myep_button").attr("src","img/menu_2.gif");$("#thema_button").attr("src","img/menu_3.gif");$("#open_button").attr("src","img/menu_4.gif");$("#cate_button").attr("src","img/menu_5.gif");$("#recent_button").attr("src","img/menu_6C.gif");break;

	}

}
/*$("#thema_img1").attr("src",src);
var uid;
var ufname;
var uname;
var uemail;
var uhp;
*/

var USERID={
	setid:function(uid,uname,uemail,uhp,mobile_auto){
		this.uid=uid;
		this.uname=uname;
		this.uemail=uemail;
		this.uhp=uhp;
		this.mobile_auto=mobile_auto;
		
	}
	,getid : {
		uid:this.uid
		,uname:this.uname
		,uemail:this.uemail
		,uhp:this.uhp
		,mobile_auto:this.mobile_auto
	}
	
}


var Getid={

	newid:function(no,x,y,epname,epid,domain,homepage,hp,tel,fax,gx,gy,nx,ny,image,userid,simplemap,simplemap_str,addr){
		//alert(gx)
		this.no=no;
		this.x=x;
		this.y=y;
		this.epname=epname;
		this.epid=epid;
		this.domain=domain;
		this.homepage=homepage;
		this.hp=hp;
		this.tel=tel;
		this.fax=fax;
		this.gx=gx;
		this.gy=gy;
		this.nx=nx;
		this.ny=ny;
		this.image=image;
		this.userid=userid;
		this.simplemap=simplemap;
		this.simplemap_str=simplemap_str;
		this.addr=addr;
	}
	,eposition:{
		no:this.no
		,x:this.x
		,y:this.y
		,epname:this.epname
		,epid:this.epid
		,domain:this.domain
		,homepage:this.homepage
		,hp:this.hp
		,tel:this.tel
		,fax:this.fax
		,gx:this.gx
		,gy:this.gy
		,nx:this.nx
		,ny:this.ny
		,image:this.image
		,userid:this.userid
		,simplemap:this.simplemap
		,simplemap_str:this.simplemap_str
		,addr:this.addr

	}
	,newxy:function(ggx,ggy,nnx,nny,html){
		
		this.ggx=ggx;
		this.ggy=ggy;
		this.nnx=nnx;
		this.nny=nny;
		this.html=html;
	
	}
	,getxy:{
	
		ggx:this.ggx
		,ggy:this.ggy
		,nnx:this.nnx
		,nny:this.nny
		,html:this.html
	
	}

}

function xylocation(a,type,n,m){

	if (type=="e"){
		//alert(decodeURIComponent(a))
		/*
		LeftPanelWidth=350;
		EPSN.LeftPanelResize(LeftPanelWidth,"resize","");
		EPSN.contents.Contents_Basic(a)
		*/
		EPSN.search.search_eposition_view(a)

	}else if (type=="x")
	{
		a1=a.split(",");

		if (m=="M")
		{
			m="M";
			px=a1[0];
			py=a1[1];

		}else if (m=="G")
		{
			m="G"
			px=a1[1];
			py=a1[0];
		}else if (m=="N")
		{
			m="N"
			px=a1[0];
			py=a1[1];
		}else{
			m="G"
			px=a1[1];
			py=a1[0];
		}
		//alert(x + " " + y + " " + m)
		document.getElementById('mapiframe').contentWindow.MAPS.Control.viewpoint(px,py,decodeURIComponent(n),m)
	}else if (type=="db")
	{

		if (m=="join")
		{
			OnBlind("",400,400,"memberjoin","회원가입");
		}

	}else{
		
		LeftPanelWidth=357;
		EPSN.LeftPanelResize(LeftPanelWidth,"resize","recent");
		Button_click("recent_button")
	}


}

function getAbsLeft(element){ 
	if(typeof element!='object') 	element=document.getElementById(element); 
	var LEFT=0; 
	while(element){ 
		LEFT+=element.offsetLeft; 
		element=element.offsetParent; 
	} 

	return LEFT; 
} 

function getAbsTop(element){ 
	if(typeof element!='object') element=document.getElementById(element); 
	var TOP=0; 
	while(element){ 
		TOP+=element.offsetTop; 
		element=element.offsetParent; 
	} 

	return TOP; 
} 


function getBounds(tag) 
{ 
    var ret = new Object(); 
    if(document.all) { 
        var rect = tag.getBoundingClientRect(); 
        ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
        ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
        ret.width = rect.right - rect.left; 
        ret.height = rect.bottom - rect.top; 
    } else { 
        var box = document.getBoxObjectFor(tag); 
        ret.left = box.x; 
        ret.top = box.y; 
        ret.width = box.width; 
        ret.height = box.height; 
    } 
    return ret; 
} 

function fadeToalpha(a){
	//style="filter:alpha(opacity='70');-moz-opacity:0.7;"
	if (a==1)
	{
		$("#SearchPopup1").css({"filter":"alpha(opacity='100')","-moz-opacity":"1.0"});
	}else{
		$("#SearchPopup1").css({"filter":"alpha(opacity='70')","-moz-opacity":"0.7"});

	}

}
//setTimeout(xylocation('파란','e'),2000);
//alert(USERID.getuid())
