var UI={};
UI.$=function(s) { return document.getElementById(s) };
UI.random=function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min) };
UI.tvpotSWF=function(src,w,h){
    width = (w)? w : 168;
    height = (h)? h : 136; 
	src+='&ver=0001&stype=m';
	var tvpot = '<object type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" align="middle" id="V000165992" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
	tvpot += '<param name="movie" value="'+src+'"/>';
	tvpot += '<param name="allowScriptAccess" value="always"/>';
	tvpot += '<param name="allowFullScreen" value="true"/>';
	tvpot += '<param name="loop" value="false"/>';
	tvpot += '<param name="menu" value="false"/>';
	tvpot += '<param name="wmode" value="transparent"/>';
	tvpot += '<param name="swLiveConnect" value="true"/>';
	tvpot += '<embed src="'+src+'" width="'+width+'" height="'+height+'" loop="false" menu="false" swLiveConnect="true" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" allowFullScreen="true" nowow="true"/>';
	tvpot += '</object>';
	document.write(tvpot);
};
UI.parseQuery=function(s){
	var str=s||location.search.substr(1);
	var r={},t=[];
	var a=str.split('&');
	for(var i=0;i<a.length;i++){t=a[i].split("=");r[t[0]] = t[1];}
	return r;
};

UI.Rolling=function(cid,count,interval,n) {
	this.cid = cid;
	this.count = count;	
	this.n = (n)?n:"1";
	this.onchange = null;
	for(var k=1; k<=this.count; k++) UI.$(this.cid+"_"+k).style.display="none";
	UI.$(this.cid+"_"+this.n).style.display="block";
	this.div = UI.$(this.cid);//전체div
	this.div.onmouseover=function(){this.isover=true; }
	this.div.onmouseout=function() {this.isover=false;}
	this.btn_next = UI.$("btn_"+this.cid+"_next");
	this.btn_prev = UI.$("btn_"+this.cid+"_prev");
	var self=this;
	if(this.btn_next) this.btn_next.onclick=function(){self.next() }
	if(this.btn_prev) this.btn_prev.onclick=function(){self.prev() }
	if(interval>0) setInterval(function(){self.play()}, interval);
}
UI.Rolling.prototype = {
	play : function() {
		if(this.div.isover) return;
		this.next();
	},
	change :function(){
		if(this.onchange) this.onchange();
	},
	prev :function(){
		UI.$(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==1)?this.count:--this.n;
		UI.$(this.cid+"_"+this.n).style.display="block";
		this.change();
	},
	next :function(){
		UI.$(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==this.count)? 1:++this.n;
		UI.$(this.cid+"_"+this.n).style.display="block";
		this.change();
	},
	random : function() {
		var rn=Math.round((this.count-1)*Math.random());
		for(var i=0;i<rn;i++) this.next();
	}
};
function viewP(_src){
	img_src=_src;
	var _wrap = UI.$(_src).src;
	UI.$(_src).src="http://img-media.daum-img.net/media3/mobile/icon_loading.gif";
	UI.$(_src).width="16";
	var timerID = setTimeout("viewP_ImgChg('"+ _src + "','" + _wrap +"');",100);
}
function viewP_ImgChg(_src,_wrap){
	if(_wrap.indexOf('120x120_')>-1){
		UI.$(_src).src =_wrap.replace('120x120_','');
		UI.$(_src+"_txt").innerHTML = "[이미지 원래 크기]";
		UI.addEvent(UI.$(_src), "load",function(){UI.resizeImage(UI.$(img_src),458,1000);}); 
	}else{
		var tmp = _wrap.substring(_wrap.lastIndexOf('/')+1,_wrap.length);		
		UI.$(_src).src=_wrap.replace(tmp,'120x120_'+tmp);
		UI.$(_src+"_txt").innerHTML = "[이미지 크게 보기]";
		UI.addEvent(UI.$(_src), "load",function(){UI.resizeImage(UI.$(img_src),120,120);}); 
	}
}
UI.addEvent=function(object, type, listener) {	
	if(object.addEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.addEventListener(type, listener, false)}
	else { object.attachEvent("on"+type, listener); }
};
UI.delEvent=function(object, type, listener){
	if (object.removeEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.removeEventListener(type, listener, false)}
	else object.detachEvent('on'+type, listener);
};
UI.stopEvent=function(event) {
	var e=event || window.event;
	if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
	else {e.returnValue = false; e.cancelBubble = true;}
};
UI.resizeImage=function(img,w,h){
	var t = new Image();
	t.src=img.src;	
	if(t.width==0 || t.height==0) return;
	if(t.width>w || t.height >h){
		img.width=w;img.height=h;
		if((t.width/w) > (t.height/h) )	img.height=Math.round(t.height * (w / t.width));
		else img.width = Math.round(t.width *  (h / t.height));
	}else{
		img.width=t.width;
		img.height=t.height;
	}
	if(img.width==0 || img.height==0) setTimeout(function(){UI.resizeImage(img,w,h)},500);
};
function FontBig(type){
	var font = UI.$('news_content');
	var img = UI.$('mobile_btn');
	img.src=(font.style.fontSize=="17px")?"http://img.mobile.daum.net/static_img/iphone/media/btn_big.gif":"http://img.mobile.daum.net/static_img/iphone/media/btn_normal.gif";
	font.style.fontSize  = (font.style.fontSize=="17px")?"15px":"17px";
}
function secTp(num){
	UI.$("New"+num).style.display="";
	(num=='1')?UI.$("New2").style.display="none":UI.$("New1").style.display="none";
}
function include_script(type, defer, src){
	var script = document.createElement("script");
	script.type = type, script.defer = defer;
	script.src = src;
	script.charset = 'euc-kr';
	document.getElementsByTagName('head')[0].appendChild(script);
	return script;
}
function getNavigatorType(){
	if(navigator.appName == "Microsoft Internet Explorer")
		return 1;  
	else if(navigator.appName == "Netscape")
		return 2;	
	else 
		return 0;
}
function callMdown(event){
	var _event;
	switch (getNavigatorType()) {
		case 1 : // IE
			_event = window.event;
			node = _event.srcElement;
			nodeName = _event.srcElement.className;
			break;
		case 2 : // Netscape
			_event = event;
			node = _event.target;
			nodeName = _event.target.className;
			break;
		default :
			_event = window.event;
			node = _event.srcElement;
			nodeName = _event.srcElement.className;
			break;
	}
	if(nodeName == "dselObj" || nodeName == "dselObjT" || nodeName == "s2" || nodeName.indexOf("Timg_")>-1){
	}else{
		try{
			document.getElementById("sType_list").style.display = "none";
		}catch(e){}
	}
}
/**
* @author daum
*/
var _ua = window.navigator.userAgent.toLowerCase();

var browser = {
    model: _ua.match(/(sonyericssonx1i|ipod|iphone)/) ? _ua.match(/(sonyericssonx1i|ipod|iphone)/)[0] : "",
	skt : /msie/.test( _ua ) && /nate/.test( _ua ),
	lgt : /msie/.test( _ua ) && /([010|011|016|017|018|019]{3}\d{3,4}\d{4}$)/.test( _ua ),
	opera : /opera/.test( _ua ) || /opera mobi/.test( _ua ),
	ipod : /webkit/.test( _ua ) && /\(ipod/.test( _ua ) ,
	iphone : /webkit/.test( _ua ) && /\(iphone/.test( _ua )
};

// Scroll Button _ FB
function setNav() {
	if(!document.getElementById)	return false;
	if(!document.getElementById('scrollNav'))	return false;

	var nav = document.getElementById('scrollNav');
	var prev = getElementsByClassName(document, "btGoPrev");

	if (hasScroll()) {
		if(browser.skt || browser.lgt) { showScroll(nav); }
		else									 { hideScroll(nav); }
	} else { hideScroll(nav); }
}

function moveNav(dir, amount) {
	if (amount == undefined) amount = 250;

	switch (dir)
	{
		case 'top':
			window.scrollTo(0,0);
			break;
		case 'up':
			window.scrollTo(0, document.documentElement.scrollTop - amount);
			break;
		case 'down':
			window.scrollTo(0, document.documentElement.scrollTop + amount);
			break;
		defalut:
			break;
	}
}

function hasScroll(){
	var screenHeight = document.documentElement.scrollHeight;
	var clientHeight = document.documentElement.clientHeight;
	return clientHeight < screenHeight ? true : false;
}

function showScroll(nav){
	var offset = 208;

	nav.style.display = "";
	nav.style.top = (document.documentElement.scrollTop + offset) + 'px';
}

function hideScroll(nav){
	nav.style.display = "none";
}

function getElementsByClassName(_element, className){
	var elem = typeof _element == "string" ? document.getElementById(_element) : _element;

	var _all = elem.getElementsByTagName("*");
	var element = [];
	for(var i=0,len=_all.length; i<len; i++) {
		if(_all[i].className == className) element.push(_all[i]);
	}
	return (element.length > 0) ? element : null;
}

if (window.attachEvent)	window.attachEvent("onscroll", setNav);
else								window.addEventListener("scroll", setNav, false);
window.setInterval(setNav, 100);


function goToPC(){
	try{
		var url =  document.location.href;
		if(url.indexOf('m.media.daum.net/sports') > -1){//스포츠일때는 스포츠 탑으로 이동
			document.location.href = "http://sports.media.daum.net/";
		}else if(url.indexOf('m.media.daum.net/tvnews') > -1){//TV뉴스일때는 url이 좀 달라서 예외처리
			var subUrl = url.split("/tvnews/")[1] ? url.split("/tvnews/")[1] : "";
			document.location.href = "http://tvnews.media.daum.net/" + subUrl;
		}else if(url.indexOf('newsid=') > -1){
			var param = UI.parseQuery();
			document.location.href = "http://newslink.media.daum.net/news/" + param['newsid'];
		}else if(url.indexOf('m.media.daum.net/entertain/breakingnews/') > -1){//연예속보일때는 url이 달라서 예외처리
			document.location.href = "http://media.daum.net/breakingnews/entertain/";
		}else{//그 외는 호스트만 변경
			document.location.href =url.replace('m.media.daum.net', 'media.daum.net');
		}
	}catch(e){}
}
window.onload = function(){
	if(navigator.userAgent.indexOf("Android") > -1){
		document.getElementById("wrap").style.minWidth = 302 +"px";
		document.getElementById("foot_btn").style.minWidth = 302 +"px";
		document.getElementById("footerWrap").style.minWidth = 302 +"px";
	}
}