
var iter = 0 ;
var iterAD = 0 ;
var timerT ;
var timerView ;

function trim10 (str) {
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

function view_ad(str, vstr, id){
	link1 = "http://www.inews24.com/tools/ad_redirect1.php?ad_key=" + encodeURI( trim10(vstr)) + "&url=http://www.sktelecom.com/" ; 
	link2 = "http://www.inews24.com/tools/ad_redirect1.php?ad_key=" + encodeURI( trim10(vstr)) + "&url=http://www.postman.co.kr" ; 
	link3 = "http://www.inews24.com/tools/ad_redirect1.php?ad_key=" + encodeURI( trim10(vstr)) + "&url=http://information.inews24.com/visionit/" ; 
	if (id ==1) {
		vvlink = link1 ; 
	} else if (id ==2) {
		vvlink = link3 ; 
	}
	var vvvv = "<SPAN id='mobile" + id + "' OnMouseOver ='javascript:showAD(" + id + " )' onmouseout ='javascript:hideAD(" + id + " )' ><a href ='" + vvlink  + "' target='_new'><font color=blue ><b>" + vstr + "</b></font></a></SPAN>" ;
	
	document.getElementById("content").innerHTML  = str.replace(vstr , vvvv ) ;


	var el =  getPos( document.getElementById("mobile" + id ) )  ;
	var xx = el.x -30 ;
	var yy = el.y +15 ;
	var str_ad = "" ;
	

	if (id ==1 ) {
		str_ad = "<div id='ad_img_t00" + id + "' style='position:absolute; left: " + xx + "px; top: " + yy + "px; z-index:10; display:none ;' OnMouseOver ='javascript:showAD(" + id + " )' onmouseout ='javascript:hideAD(" + id + " )' > " ; 
		str_ad += "<table border='0' cellpadding='0' cellspacing='2' bgcolor='#808080'> " ; 
		str_ad += "	<tr> " ; 
		str_ad += "		<td bgcolor='#dbdbdb' width='137' align='center' height='59' valign='middle'> " ; 
		str_ad += "			<table width='137' border='0' cellpadding='4' cellspacing='0' bgcolor='#ffffff'> " ; 
		str_ad += "				<tr> " ; 
		str_ad += "					<td width='50'><a href ='" + link1 + "' target='_new' ><img src='http://www.inews24.com/image/key_ad_img/skt_logo.jpg' border=0 width=137 height=59 ></a></td> " ; 
		str_ad += "				</tr> " ; 
		str_ad += "			</table> " ; 
		str_ad += "		</td> " ; 
		str_ad += "	</tr> " ; 
		str_ad += "</table> " ; 
		str_ad += "</div>  " ; 

	} else if (id ==2 ) {

	
	} 

	document.getElementById("content").innerHTML = str_ad + document.getElementById("content").innerHTML ;
	return true ;
}

function showAD(id ) {
	document.getElementById("ad_img_t00"+id ).style.display = "block"
}

function hideAD(id ) {
	document.getElementById("ad_img_t00" + id ).style.display = "none"
}

function getPos(el) {
    // yay readability
    for (var lx=0, ly=0;
         el != null;
         lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return {x: lx,y: ly};
}

function setTimerAD(id_show){
	iterAD += 1 ;
	switch(iterAD)
	{
		case 1 :
			timerView = setTimeout('setTimerAD(id_show)',200);
			break;    
		case 2 :
			showAD(id_show); 
			timerView = setTimeout('setTimerAD(id_show)',3000);
			break;
		case 3 :
			hideAD(id_show);
			clearTimeout(timerView);
			break;
		default :
			timerView = setTimeout('setTimerAD(id_show)',1000);
			break;    
	}
} 
		
function MorphSpin(){
	var str ;
	var vstr ;
	iter += 1 ;
	id_show = 0 ; 
	switch(iter)
	{
		case 3 : 
			str = document.getElementById("content").innerHTML ;
			id = 1 ; 
			vstr = " SKT"  ;

			if (str.indexOf(vstr) > 0  ) {
				view_ad(str, vstr, id ) ;
				id_show = id ; 
			}else {
				vstr = " SKÅÚ·¹ÄÞ"  ;
				if (str.indexOf(vstr) > 0  ) {
					view_ad(str, vstr, id ) ;
					id_show = id ; 
				}
			}
		//	timerT = setTimeout('MorphSpin()',200);
			break ; 
		case 4 :
			id_show = 1;
			clearTimeout(timerT);
			timerView = setTimerAD(id_show); 
			break ; 
			
		default :
			timerT = setTimeout('MorphSpin()',700);
			break ; 		
	}
}
