google.load("jquery", "1.3.2");
//google.load("jqueryui", "1.7.2");
google.load("language", "1");

google.setOnLoadCallback(function() {
//	$("#body").slideDown(200);
/*
	$("a").click(function(e) {
		if($(this).attr("rel")=="menu")
		{
			$("#body").slideUp(200,function(){
				window.location=e.target;
			
			});
			return false;
		}
	});*/
	$("#banner img").mouseover(function(e) {
		$(this).fadeTo(300,1.0);		
		});
	$("#banner img").mouseout(function(e) {
		$(this).fadeTo(300,0.4);		
		});

	if(location.pathname.indexOf("/guest")>-1)
	{
		$("#menu li")[4].setAttribute("class","selected");
	}
	else if(location.pathname.indexOf("/blog")>-1)
	{
		$("#menu li")[2].setAttribute("class","selected");
	}
	else if(location.pathname=="/")
	{
//		warningbox("<h3>블로그 복구중!!!!!!</h3>");
	}


	function close_blockscreen()
	{
		$("#blockscreen").fadeTo(300,0.0,function(){closediv("blockscreen");});
	}
	function close_warning()
	{
		$("#warningbox").slideUp("slow",function(){closediv("warningbox");});
		close_blockscreen();
	}
	function closediv(_obj)
	{
		var obj;
		if(!_obj.style)obj=document.getElementById(_obj);
		else obj=_obj;
		if(obj!=null)
		{
			if(obj.style.display!="none")
			{
				obj.style.display="none";
			}
		}
	}

	function blockscreen()
	{
		if(document.getElementById("blockscreen")!=null)
		{
			document.getElementById("blockscreen").style.display="block";
			$("#blockscreen").fadeTo(300,0.6);
			return false;
		}
		var blsc=document.createElement("div");
		//blsc.style.display="none";
		blsc.id="blockscreen";
		blsc.style.position="fixed";
		blsc.style.top="0";
		blsc.style.left="0";
		blsc.style.width="100%";
		blsc.style.height="100%";
		blsc.style.backgroundColor="#ffffff";
		blsc.style.color="#eeeeee";;
		var opacity_value=0;
		//blsc.style.filter="Alpha(Opacity="+opacity_value+")";
		//blsc.style.opacity=opacity_value/100;
		$(blsc).css("opacity",0);
		blsc.style.zindex="100";
		document.body.appendChild(blsc);
		$(blsc).fadeTo(300,0.6);
		return true;
	}
	function warningbox(text)
	{
		blockscreen();
		var contents="<p><img src='/images/warning.jpg' alt='warning'/><br />"+text+"</p>"
		if(document.getElementById("warningbox")!=null)
		{
			document.getElementById("warningbox").innerHTML=contents;
			//document.getElementById("warningbox").style.display="block";
			$("#warningbox").slideDown("slow");
			return true;
		}
		var w=300;
		var h=400;
		var popup=document.createElement("div");
		popup.id="warningbox";
		popup.style.display="none";
		popup.style.position="fixed";
		popup.style.width=w+"px";
		popup.style.height=h+"px";
		popup.style.top="50%";
		//popup.style.left="50%";
		popup.style.left="360px";
		popup.style.marginLeft="-"+w/2+"px";
		popup.style.marginTop="-"+h/2+"px";
		popup.style.backgroundColor="#ffffff";
		popup.style.color="#000000";
		popup.style.border="3px double #999999";
		popup.style.textAlign="center";
		var opacity_value=80;
		$(popup).css("opacity",0.8)
		//popup.style.filter="Alpha(Opacity="+opacity_value+")";
		//popup.style.opacity=opacity_value/100;
		popup.style.zindex="100";
		popup.onclick=function(){close_warning();}
		popup.innerHTML=contents;

		document.body.appendChild(popup);
		$(popup).slideDown("slow");
		return false;
	}
	var op=0;
	$("#box").mouseup(function()
	{
		var text="";
		try
		{
			if (document.selection)
			{
				text=document.selection.createRange().text+"";
				event.cancelBubble=true;
			}
			else if(document.getSelection)
				text=document.getSelection()+"";
			else if(window.getSelection)
				text=window.getSelection()+"";
		}
		catch(ex){text="";}
		if(text.trim()!="")
		{
			if(op==0)op=1;
			else $("#caption").fadeOut("slow");
			google_trans(text,function(t){$("#caption").html(t).fadeIn("fast");});
		}
		else {$("#caption").fadeOut("fast");op=0;}
	});
	function google_trans(text,func)
	{
		google.language.detect(text, function(result)
		{
			if (!result.error && result.language)
			{
				var destlang="ko";
				if(result.language=="ko")destlang="en";
				google.language.translate(text, "", destlang, function(result)
				{
					if(!result.error)
					{
						func(result.translation);
					}
				});
			}
		});
	}

});

String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function top()
{
	if(document.body)
		document.body.scrollTop=0;
	else if(document.documentElement)
		document.documentElement.scrollTop=0;
}
var restore=new Array();
function silentlink(obj,layer,script,option)
{
	var xmlHttp;
	if(option)
	{
		if(obj.href!=null)choose_menu(obj);
		else menu(obj);
	}
	if(window.ActiveXObject || window.XMLHttpRequest)
	{
		if(window.ActiveXObject)
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		else if(window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
					var result = xmlHttp.responseText.split("<div id='errmsg' />");
					if(result.length>1)
					{
						alert(result[1]);
					}
					else
					{
						restore[layer]=document.getElementById(layer).innerHTML;
						document.getElementById(layer).innerHTML=xmlHttp.responseText;
						eval(script);
						//if(document.getElementById("code"))alditorById("code");
						//if(document.getElementById("code"))createEditor();
					}
				}
				else
				{
					//document.getElementById(layer).innerHTML="error";
					blockscreen();
					warningbox("<br/>"+href+"는 유효하지 않는 경로입니다.");
				}
			}
			else
			{
				//alert(xmlHttp.readyState);
			}
		};
		if(obj.href==null)href="/?page="+obj;
		else href=obj.href;
		if(href.indexOf("?")==-1)last_url=href+"?bo=1";
		else last_url=href+"&bo=1";
		xmlHttp.open("POST", last_url, true);
		
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlHttp.send("");
		return false;
	}
	else return true;
}