function r(d) {
		   d.oncontextmenu=null; 
		   d.onselectstart=null;
		   d.ondragstart=null;
		   d.onkeydown=null;
		   d.onmousedown=null;
		   d.onmouseup = null;
		   d.body.oncontextmenu=null;
		   d.body.onselectstart=null; 
		   d.body.ondragstart=null;
		   d.body.onkeydown=null; 
		   d.body.onmousedown=null;
		   d.body.onmouseup = null;
	   } 
function s(f) {
	if (f.frames.length!=0) {
		for (var i=0; i<f.frames.length; i++) {
			s(f.frames[i]);
		} 
	} 
	try {
		r(f.document); 
	} catch (error) {
	}
}
//s(top.window);
try{
	r(document);
}catch(e){
}
DragSearch = (function() {
//	try{
		var DragSelectionRange, Keyword, KeywordHtml, DragSelectionBtn, DragNewRange;
		var DragPos, DragSelectionLayer, DragDispChk;
		var DragSchIdPos = "DragSchLayerPos";
		var DragSchIdLay = "DragSchLayer";
		var MSIE = navigator.userAgent.indexOf("MSIE");
		var OPERA=navigator.userAgent.indexOf("Opera");
		
		//ref http://www.quirksmode.org/js/events_order.html
		EventAttach = function(object, type, listener) {	
			if(object.addEventListener) {
				object.addEventListener(type, listener, false)
			} else {	//for MSIE
				object["e"+type+listener] = listener;
				object[type+listener] = function(){ object["e"+type+listener] (window.event);} 
				object.attachEvent("on"+type, object[type+listener]); 
			}
		}
		EventDetach = function(event) {
			if( !e ) var e = window.event;
			e.cancelBubble = true;
			if(e.stopPropagation) e.stopPropagation();
		}
		RemoveElement = function(element) {
			var subNode = document.getElementById(element);
			var headNode = subNode.parentNode;
			if(headNode)
				 headNode.removeChild(subNode);
			return subNode;
		}	
		GetStyle=function(el, style) {
			var value = el.style[style];
			if(!value) {
				if(document.defaultView){
					if(document.defaultView.getComputedStyle){
						var css = document.defaultView.getComputedStyle(el, null);
						value = css ? css[style] : null;
					}
				}  else if (el.currentStyle) {
					if( style == "backgroundPosition" ) value = el.currentStyle["backgroundPositionX"] + " " + el.currentStyle["backgroundPositionY"] ;
					else  value = el.currentStyle[style];
				}
			}
			return value == 'auto' ? null : value;
		}
		TxtProcessing = function(str) {
			 return str.replace(/(^\s*)|(\s*$)/g, "") 
		}

		OnMouseUp = function(event) {
			try {
				//remove existing layer
				if (DragSelectionLayer || DragSelectionBtn) HideButton();
				
				//ref http://www.xs4all.nl/~ppk/js/selected.html
				if(window.getSelection) {	//ETC
					DragSelectionRange = window.getSelection();
					Keyword = DragSelectionRange.toString();
					KeywordHtml = Keyword
				} else if(document.selection) {	//MSIE
					DragSelectionRange = document.selection.createRange();
					Keyword = DragSelectionRange.text.toString();
					KeywordHtml = DragSelectionRange.htmlText;
				} else 	return;

				Keyword = TxtProcessing(Keyword);

				if ((Keyword != "")&&(Keyword.length > 1)) {	
					var DragChk = EventCheck(event);
					if (DragChk) {										
						ShowButton();
						EventDetach(event);
					} else {
						HideButton();
					}
				} else {
					HideButton();
				}
			} catch (e) { HideButton(); }
		}

		EventCheck= function(event) {
			var strChkL = KeywordHtml.length;
			var DragChk = true;
			if (Keyword.length > 30) DragChk = false;
			if (DragChk) {			
				if (navigator.appName == "Netscape") {//Netscape
					_event = event;
					_nodeName = _event.target.nodeName;
				} else {	//the others inc MSIE
					_event = window.event;
					_nodeName = _event.srcElement.nodeName;
				}
				if(_nodeName=="INPUT"||_nodeName=="SELECT"||_nodeName=="TEXTAREA"||_nodeName=="FIELDSET"){
					 DragChk = false;
				}
			}
			return DragChk;
		}
		
		ShowButton = function() {
			try {
				DragSelectionBtn = document.createElement('span')
				DragSelectionBtn.id = DragSchIdPos;
				DragSelectionBtn.style.position = 'absolute';
				DragSelectionBtn.style.width = '0px';
				DragSelectionBtn.style.height = '0px';
				DragSelectionBtn.style.fontSize = '0px';	
			
				//insert Button	
				if (MSIE!=-1) {	//MSIE				
					var tmp = document.createElement('div');
					tmp.appendChild(DragSelectionBtn);
					DragNewRange = DragSelectionRange.duplicate();
					DragNewRange.setEndPoint( "StartToEnd", DragSelectionRange);
					DragNewRange.pasteHTML(tmp.innerHTML);
					DragSelectionBtn = document.getElementById(DragSchIdPos);
				} else {
					var range = DragSelectionRange.getRangeAt(0);
					DragNewRange = document.createRange();
					DragNewRange.setStart(DragSelectionRange.focusNode, range.endOffset);
					DragNewRange.insertNode(DragSelectionBtn);
				}
				
				if(!document.getElementById(DragSchIdLay)){				
					var el_body = document.getElementsByTagName("body");
					var el_DragSchLayer = document.createElement("span");		
					el_DragSchLayer.setAttribute("id", DragSchIdLay);
					el_body[0].appendChild(el_DragSchLayer);
					document.getElementById(DragSchIdLay).style.display = "none";
				}
							
				DragSelectionLayer = document.getElementById(DragSchIdLay);
				
				DragSelectionLayer.style.display = 'block';	
				DragSelectionLayer.style.position = 'absolute';
				DragSelectionLayer.style.cursor = 'pointer';
				DragSelectionLayer.style.zIndex = '100';	//topmost
				DragSelectionLayer.style.background = 'url(http://www.dragsearch.com/Services/sversion/search.gif)';
				DragSelectionLayer.style.width = '51px';
				DragSelectionLayer.style.height = '20px'
				DragSelectionLayer.style.margin = '-23px 0 0 -5px';

				SetButtonPosition();

				EventAttach(DragSelectionLayer, 'mouseup', DSSearch);
				EventAttach(window,"resize",SetButtonPosition);

				DragDispChk = self.setInterval(ForceDisplay,1000);
			} catch (e) { HideButton(); }
		}
		
		SetButtonPosition =  function(e) {
			if (DragSelectionLayer && DragSelectionBtn){
				DragPos = GetPosition(document.getElementById(DragSchIdPos));

				DragSelectionLayer.style.top = DragPos[0] +"px";
				DragSelectionLayer.style.left = DragPos[1] +"px";
			}
		}
		GetPosition= function(obj) {
			//ref http://www.quirksmode.org/js/findpos.html
			var curleft = curtop = 0;
			if( obj.offsetParent){
				do{
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
					obj = obj.offsetParent;
				}while(obj);
			}

			//check top
			if(curtop < 20) curtop += 20;
			//check right 
			if(curleft + 60 > document.body.offsetWidth) {
				curleft -= 60;
			}
			return [curtop, curleft];
		}

		DSSearch = function(event) {
			var url = "http://service.dragsearch.com/sversion/gateway.php?type=kukinews&keyword=" + encodeURIComponent(Keyword);
			var searchWindow = window.open(url);
			if (searchWindow) searchWindow.focus();
			HideButton();
			EventDetach(event);
		}

		ForceDisplay = function() { 
			if (document.getElementById(DragSchIdPos)) {			
				var p = document.getElementById(DragSchIdPos);
				do {
					if(p.nodeType != 1) { p = null; break; } else {	p = p.parentNode; }
					var ChkDisplay = GetStyle(p,"display")
					if (ChkDisplay == "none") {
						HideButton();
						break;
					}
				} while(p.nodeName.toUpperCase() != "BODY")
			}
		}

		HideButton = function() { 
			try{
				DragSelectionRange = null;
				DragSelectionBtn = null;
				Keyword = '';
				DragNewRange && DragNewRange.pasteHTML && DragNewRange.pasteHTML('');
				DragNewRange = null;
				if (document.getElementById(DragSchIdPos)) RemoveElement(DragSchIdPos);
				if (document.getElementById(DragSchIdLay)) RemoveElement(DragSchIdLay);
				clearInterval(DragDispChk);
			} catch (e) {}
		}
		
		return {
			initialize: function() {
				EventAttach(document, 'mouseup', OnMouseUp);
				try{
					var domain = document.domain;
					if(domain.indexOf('daum.net') >= 0 || domain.indexOf('tistory.com') >= 0 ){
						var target = document.all;
						for(var i = 0 ; i < target.length; i++){
							try{
								target[i].onmouseup = OnMouseUp;
								target[i].onmousedown = null;
								target[i].ondragstart = null;
								target[i].onselectstart = null;
								target[i].oncontextmenu = null;
							}catch(e){
							}

						}
						document.onmouseup = onMouseUp;
						document.onmousedown = null;
						document.ondragstart = null;
						document.onselectstart = null;
						document.oncontextmenu = null;
					}
				}catch(e){
				}

			}
		};
	
//	} catch (e) {}
})();

try{
DragSearch.initialize();
document.onreadystatechange=function checkReady(){
  if (document.readyState=='complete'){
    DragSearch.initialize();
  }
}

}catch(e){
}

