
var xhr = new Object();

xhr.rolling = function(url, bool, handler, method, data) {
	this.xhobj = null;
	this.url = url;
	this.bool = bool;
	this.handler = handler;
	this.method = method;
	this.data = data;
//	this.send_request();
}

xhr.rolling.prototype = {
	get_xhobj : function() {
		var lo_xmlhttp = null;
		try {
			lo_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
		} catch(e) {
			try {
				lo_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			} catch(sc) {
				lo_xmlhttp = null
			}
		}
		if(!lo_xmlhttp && typeof XMLHttpRequest!="undefined") {
			lo_xmlhttp = new XMLHttpRequest()
		}
		return lo_xmlhttp
	},
	send_request : function () {
		if(this.xhobj && this.xhobj.readyState!=0){
			this.xhobj.abort()
			this.xhobj = null;
		}
		this.xhobj = this.get_xhobj();

		if(this.method == null) {
			this.method = "GET";
		}
		if(this.xhobj) {
			this.xhobj.open(this.method, this.url, this.bool);
			if(this.handler) {
/*				this.xmlhttp.onreadystatechange = function(){
					loader.callback_func.call(loader,url);
				}*/
				this.xhobj.onreadystatechange=this.handler;
			}
			this.xhobj.send(this.data);
		}
	}
}

//*********************** °øÁö»çÇ× º¸±â ½ÃÀÛ ***********************

var ar_notice	= new Array();
var ar_wnotice	= new Array();
var ntxtnews = 0;	
var bwholerecv = 0;	
var bNoticeRecv = 0;	
var noticeTimeId = null;
var NEWS_INTERVAL = 7000;	
var NEWS_MIN_LEN = 3;	
var menu = "";
var tabNum = 0;
var xhr_notice = null;
var xhr_notice_w = null;

// °øÁö»çÇ× rolling ÄÁÆ®·Ñ
function news_rolling(tab,num,btmp) {
    menu = tab;
    tabNum = num;

    if((!menu || menu=="whole" || menu=="") && (bwholerecv==0 || ar_wnotice.length==0)) {
        if(bwholerecv==0 || ar_wnotice.length==0){
		    xhr_notice_w = new xhr.rolling("/e-home-s/include/main/notice_whole.xml", true, handleWhole);
			xhr_notice_w.send_request();
        }
	}    
    else if(menu=="tab"){
        if(bNoticeRecv==0 || ar_notice.length==0) {
		    xhr_notice = new xhr.rolling("/e-home-s/include/main/notice_new.xml", true, handleTab);
		    xhr_notice.send_request();
            bNoticeRecv = 1;
        }else {
            fnDivSet(tabNum);
        }
    }
	else
		txtnews_rolling();

	if(!btmp) {
		noticeTimeId = setTimeout("news_rolling()", NEWS_INTERVAL);
	}
}

// ÀüÃ¼ °øÁö»çÇ× rolling ÄÁÆ®·Ñ ÇÚµé·¯
function handleWhole()
{
	if(xhr_notice_w && xhr_notice_w.xhobj && xhr_notice_w.xhobj.readyState == 4 && xhr_notice_w.xhobj.responseXML) {
		if(xhr_notice_w.xhobj.status == 200 || xhr_notice_w.xhobj.status == 0){
			ar_wnotice = xhr_notice_w.xhobj.responseXML.getElementsByTagName("data")[0].firstChild.nodeValue.split("\n");
			if(ar_wnotice.length < NEWS_MIN_LEN) {
				xhr_notice_w.xhobj = null;
				return;
			}

			xhr_notice_w.xhobj = null;

			txtnews_rolling();
			bwholerecv = 1;
		}
	}
}

// ÅÇº° °øÁö»çÇ× rolling ÄÁÆ®·Ñ ÇÚµé·¯
function handleTab()
{
	if(xhr_notice && xhr_notice.xhobj && xhr_notice.xhobj.readyState == 4 && xhr_notice.xhobj.responseXML) {
		ar_notice    = xhr_notice.xhobj.responseXML.getElementsByTagName("data")[0].firstChild.nodeValue.split("\n");
		xhr_notice.xhobj = null;

        tabnews_rolling();
        bNoticeRecv = 1;
	}
}

//ÅÇº° DIV ¸®½ºÆ® AJAX·Î ±¸Çö (ÇÑ¹ø ½ÇÇà)
function tabnews_rolling() {
    var temp_str = "";
	for(var i=0; i<ar_notice.length; i++) {
        temp_str = temp_str + ar_notice[i];
    }
    document.getElementById("div_many").innerHTML  = temp_str;
    fnDivSet(tabNum);
}

//ÀüÃ¼º¸±â DIV ¸®½ºÆ® AJAX·Î ±¸Çö
function txtnews_rolling() {
	if(typeof(ar_wnotice[ntxtnews]) == "undefined" || ar_wnotice[ntxtnews] == "") {
		ntxtnews = 0;
	}
	if(typeof(ar_wnotice[ntxtnews]) != "undefined" && ar_wnotice[ntxtnews] != "") {
		document.getElementById("txtnews").innerHTML = ar_wnotice[ntxtnews];
	    ntxtnews++;
	}
}

//ÀüÃ¼ °øÁö»çÇ× º¸±â ¸®½ºÆ®¿¡¼­ ÅÇº° ¸®½ºÆ® È­¸é º¸±â(onmouseover)ÀÌµ¿½Ã DIV ¹× ÅÇ ÀÌ¹ÌÁö ±³Ã¼ ÇÔ¼ö
function fnDivSet(num){
    document.getElementById("txtnews").style.display="none";
    document.getElementById("div_many").style.display="";

    var obj_tab;
    var cnt = 0;
    for(var i=0; obj_tab=eval("document.frm.tab"+i); i++){
        cnt = i+1;
        if(i==num){
            obj_tab.src = "/images/main/new/k"+cnt+"_on.gif";
            document.getElementById("news"+i).style.display="";
        }else{
            obj_tab.src = "/images/main/new/k"+cnt+"_off.gif";
            document.getElementById("news"+i).style.display="none";
        }
    }
}

//ÅÇº° ¸®½ºÆ® È­¸é º¸±â -> ÀüÃ¼ °øÁö»çÇ× º¸±â È­¸é º¸±â·Î ÀÌµ¿½Ã(ÀüÃ¼º¸±â ¹öÆ° Å¬¸¯) DIV ¹× ÅÇ ÀÌ¹ÌÁö ±³Ã¼ ÇÔ¼ö
function wholeView(){
    document.getElementById("txtnews").style.display="";
    document.getElementById("div_many").style.display="none";
    
    var cnt = 0;
	document.frm.notic_code.value = 0;
    for(var i=0; obj_tab=eval("document.frm.tab"+i); i++){
        cnt = i+1;
        obj_tab.src = "/images/main/new/k"+cnt+"_off.gif";
        document.getElementById("news"+i).style.display="none";
    }
	
	start_news_rolling();
}

// °øÁö»çÇ× rolling ¸ØÃã
function stop_news_rolling() {
	clearTimeout(noticeTimeId);
}

// °øÁö»çÇ× rolling ½ÃÀÛ
function start_news_rolling() {
	noticeTimeId = setTimeout("news_rolling()", NEWS_INTERVAL);
}
//*********************** °øÁö»çÇ× º¸±â ³¡ ***********************/



var ar_imgnews	= new Array();
var ar_imgtxtnews = new Array();
var ntxt_imgnews = 0;	
var inewssrecv = 0;	
var img_newstimeid = null;
var IMG_NEWS_INTERVAL = 5000;	
//var NEWS_MIN_LEN = 3;	
//var menu = "";
//var tabNum = 0;
var xhr_news = null;

// ´º½º ÀÌ¹ÌÁö rolling ÄÁÆ®·Ñ
function img_news_rolling(btmp) {
    if((menu=="whole"||menu=="")&&inewssrecv == 0) {
        if(menu=="whole" || menu=="undefined"){
		    xhr_news = new xhr.rolling("/e-home-s/include/main/img_news_new.xml", true, handleNewNews);
		    xhr_news.send_request();
        }
	}

	img_news_next();

	if(!btmp) {
		img_newstimeid = setTimeout("img_news_rolling()", IMG_NEWS_INTERVAL);
	}
}

// ´º½º ÀÌ¹ÌÁö rolling ÄÁÆ®·Ñ ÇÚµé·¯
function handleNewNews()
{
	if(xhr_news && xhr_news.xhobj && xhr_news.xhobj.readyState == 4 && xhr_news.xhobj.responseXML) {
		var xmlDoc = xhr_news.xhobj.responseXML;

		// data ÅÂ±×ÀÇ °ªÀ» °´Ã¼·Î º¯È¯
		var commentList = eval("(" + xmlDoc.getElementsByTagName('data').item(0).firstChild.nodeValue + ")");

		// ´ñ±Û È­¸éÀ» »ý¼ºÇÑ µÚ¿¡, ¸ñ·Ï ¿µ¿ª¿¡ ÀÚ½Ä ³ëµå·Î Ãß°¡
		for(var i=0; i<commentList.length; i++) {
			ar_imgnews[i]	= makeDivImg(commentList[i].img, commentList[i].url);
			ar_imgtxtnews[i]	= makeDivTxt(commentList[i].subject, commentList[i].url);
		}
		inewssrecv = 1;
		img_news_next();
	}
}

function makeDivImg(con, url)
{
	var result = "";

	if(url && url!="")
	{
		if(url.length>7 && url.substr(0, 7)=="http://")
			result = "<a href='" + url + "' target='_blank' onfocus='this.blur();' onmouseover='stop_img_news_rolling()' onmouseout='start_img_news_rolling()'><img src='" + con + "' width='141' height='63' align='middle' alt='' border='0'></a>";
		else
			result = "<img src='" + con + "' width='141' height='63' align='middle' alt='' style='cursor:pointer;' onclick=\"open_news_main('" + url + "');\" onmouseover='stop_img_news_rolling()' onmouseout='start_img_news_rolling()'>";
	}
	return result;
}

function makeDivTxt(con, url)
{
	var result = "";

	if(url && url!="")
	{
		if(url.length>7 && url.substr(0, 7)=="http://")
			result = "<a href='" + url + "' target='_blank' onmouseover='stop_img_news_rolling()' onmouseout='start_img_news_rolling()'>" + con + "</a>";
		else
			result = "<a href=\"javascript:open_news_main('" + url + "');\" onmouseover='stop_img_news_rolling()' onmouseout='start_img_news_rolling()'>" + con + "</a>";
	}
	return result;
}

//ÀüÃ¼º¸±â DIV ¸®½ºÆ® AJAX·Î ±¸Çö
function img_news_next() {
	if(typeof(ar_imgnews[ntxt_imgnews]) == "undefined" || ar_imgnews[ntxt_imgnews] == "") {
		ntxt_imgnews = 0;
	}
	if(typeof(ar_imgnews[ntxt_imgnews]) != "undefined" && ar_imgnews[ntxt_imgnews] != "") {
		document.getElementById("new_news_img").innerHTML = ar_imgnews[ntxt_imgnews];
		document.getElementById("new_news_txt").innerHTML = ar_imgtxtnews[ntxt_imgnews];
	    ntxt_imgnews++;
	}
}

// ´º½º ÀÌ¹ÌÁö rolling ¸ØÃã
function stop_img_news_rolling() {
	clearTimeout(img_newstimeid);
}

// ´º½º ÀÌ¹ÌÁö rolling ½ÃÀÛ
function start_img_news_rolling() {
	img_newstimeid = setTimeout("img_news_rolling()", IMG_NEWS_INTERVAL);
}




var ar_zine = new Array();
var ntxt_zine = 0;
var zinerecv = 0;
var zinetimeid = null;
var ZINE_INTERVAL = 5000;
var xhr_zine = null;

// À¥Áø rolling ÄÁÆ®·Ñ
function zine_rolling(btmp) {
    if((menu=="whole"||menu=="")&&zinerecv == 0) {
        if(menu=="whole" || menu=="undefined"){
		    xhr_zine = new xhr.rolling("/e-home-s/include/main/zine_new.xml", true, handleNewZine);
		    xhr_zine.send_request();
        }
	}

	zine_next();

	if(!btmp) {
		zinetimeid = setTimeout("zine_rolling()", ZINE_INTERVAL);
	}
}

// À¥Áø rolling ÄÁÆ®·Ñ ÇÚµé·¯
function handleNewZine()
{
	if(xhr_zine && xhr_zine.xhobj && xhr_zine.xhobj.readyState == 4 && xhr_zine.xhobj.responseXML) {
		ar_zine = xhr_zine.xhobj.responseXML.getElementsByTagName("data")[0].firstChild.nodeValue.split("\n");
		
		if(!ar_zine || ar_zine.length < 1) {
        	xhr_zine.xhobj = null;
            return;
		}
		
		xhr_zine.xhobj = null;

            zine_next();
            zinerecv = 1;
	}
}

// À¥Áø DIV ¸®½ºÆ® AJAX·Î ±¸Çö
function zine_next() {
	if(typeof(ar_zine[ntxt_zine]) == "undefined" || ar_zine[ntxt_zine] == "") {
		ntxt_zine = 0;
	}
	if(typeof(ar_zine[ntxt_zine]) != "undefined" && ar_zine[ntxt_zine] != "") {
		document.getElementById("new_zine").innerHTML = ar_zine[ntxt_zine];
	    ntxt_zine++;
	}
}

// À¥Áø ÀÌ¹ÌÁö rolling ¸ØÃã
function stop_zine_rolling() {
	clearTimeout(zinetimeid);
}

// À¥Áø ÀÌ¹ÌÁö rolling ½ÃÀÛ
function start_zine_rolling() {
	zinetimeid = setTimeout("zine_rolling()", ZINE_INTERVAL);
}

