﻿var item, meetingSeq, userSeq, registDate, slURL, content;
var totalLength = 0;
var meetBannerIndex = 0;
var imageRoot = "http://image.serakorea.com/Renewal/";
var URLsForTeleport = new Array();

//URLsForTeleport[0] = "http://slurl.com/secondlife/Sera%20Korea%201/19/223/35";                                          
//URLsForTeleport[1] = "";
//URLsForTeleport[2] = "http://slurl.com/secondlife/Sera%20Korea%203/58/47/23";
//URLsForTeleport[3] = "http://slurl.com/secondlife/Sera%20Korea%204/127/127/25";
////URLsForTeleport[4] = "http://slurl.com/secondlife/Sera%20Korea%205/65/127/23";
//URLsForTeleport[4] = "";
//URLsForTeleport[5] = "http://slurl.com/secondlife/Sera%20Korea%206/97/184/25";
//URLsForTeleport[6] = "http://slurl.com/secondlife/Sera%20Korea%207/96/44/36";
//URLsForTeleport[7] = "http://slurl.com/secondlife/Sera%20Korea%208/127/122/23";
//URLsForTeleport[8] = "http://slurl.com/secondlife/Sera%20Korea%209/90/177/26";
//URLsForTeleport[9] = "http://slurl.com/secondlife/Sera%20Korea%2010/183/112/22";
//URLsForTeleport[10] = "http://slurl.com/secondlife/Sera%20Korea%2011/8/243/29";
//URLsForTeleport[11] = "http://slurl.com/secondlife/Sera%20Korea%2012/94/101/23";
//URLsForTeleport[12] = "http://slurl.com/secondlife/Sera%20Korea%2013/223/113/51";
//URLsForTeleport[13] = "http://slurl.com/secondlife/Sera%20Korea%2014/239/228/31";
//URLsForTeleport[14] = "http://slurl.com/secondlife/Sera%20Korea%2015/33/223/31";
//URLsForTeleport[15] = "http://slurl.com/secondlife/Sera%20Korea%2016/234/157/24";
////URLsForTeleport[16] = "http://slurl.com/secondlife/Sera%20Korea%2017/190/199/34";
//URLsForTeleport[16] = "";
//URLsForTeleport[17] = "http://slurl.com/secondlife/Sera%20Korea%2018/226/120/31";
//URLsForTeleport[18] = "http://slurl.com/secondlife/Sera%20Korea%2019/131/68/29";
//URLsForTeleport[19] = "http://slurl.com/secondlife/Sera%20Korea%2020/173/231/22";


URLsForTeleport[0] = "secondlife://Sera%20Korea%201/19/223/35";   
URLsForTeleport[1] = "";
URLsForTeleport[2] = "secondlife://Sera%20Korea%203/58/47/23";
URLsForTeleport[3] = "secondlife://Sera%20Korea%204/127/127/25";
URLsForTeleport[4] = "";
URLsForTeleport[5] = "secondlife://Sera%20Korea%206/97/184/25";
URLsForTeleport[6] = "secondlife://Sera%20Korea%207/96/44/36";
URLsForTeleport[7] = "secondlife://Sera%20Korea%208/127/122/23";
URLsForTeleport[8] = "secondlife://Sera%20Korea%209/90/177/26";
URLsForTeleport[9] = "secondlife://Sera%20Korea%2010/183/112/22";
URLsForTeleport[10] = "secondlife://Sera%20Korea%2011/8/243/29";
URLsForTeleport[11] = "secondlife://Sera%20Korea%2012/94/101/23";
URLsForTeleport[12] = "secondlife://Sera%20Korea%2013/223/113/51";
URLsForTeleport[13] = "";
URLsForTeleport[14] = "secondlife://Sera%20Korea%2015/33/223/31";
URLsForTeleport[15] = "secondlife://Sera%20Korea%2016/234/157/24";
URLsForTeleport[16] = "secondlife://Sera%20Korea%2017/190/199/34";
URLsForTeleport[17] = "secondlife://Sera%20Korea%2018/226/120/31";
URLsForTeleport[18] = "secondlife://Sera%20Korea%2019/131/68/29";
URLsForTeleport[19] = "secondlife://Sera%20Korea%2020/173/231/22";



 
// Add onload event to window.
// Thanks to Simon Willison (http://simon.incutio.com).
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function popUpList()
{
	window.open("../../Popup/Community/MeetList.aspx", "ListBox", "left=100,top=100,toolbar=no,status=no,width=502,height=381,directories=no,scrollbars=no,location=no,resizable=no,menubar=no");
}
	
	
function ViewerOpen(openUrl)
{
	window.open(openUrl, "ViewerOpen", "left=-1500,top=-1500,toolbar=no,status=no,width=1,height=1,directories=no,scrollbars=no,location=no,resizable=no,menubar=no");
}	
		
function popUpWrite()
{
	window.open("../../Popup/Community/MeetWrite.aspx", "ListBox", "left=100,top=100,toolbar=no,status=no,width=454,height=485,directories=no,scrollbars=no,location=no,resizable=no,menubar=no");
}

function on_loadedMeetXML(oj)
{
	var res = oj.responseXML;
	var resHTML = chgXMLtoVariables(res);
}

function chgXMLtoVariables(xdoc)
{
	item = xdoc.getElementsByTagName("item");
	meetingSeq = xdoc.getElementsByTagName("MeetingSeq");
	userSeq = xdoc.getElementsByTagName("UserSeq");
	registDate = xdoc.getElementsByTagName("RegistDate");
	slURL = xdoc.getElementsByTagName("SLURL");
	content = xdoc.getElementsByTagName("Content");
	
	totalLength = item.length;
	meetBannerIndex = 0;
	
	var rollingArea = document.getElementById("RollingArea");
	var lnkTeleport = document.getElementById("LnkTeleport");
	var newDiv = document.createElement("div");
	newDiv.setAttribute("id", "meetMessage" + meetBannerIndex);
	newDiv.style.position = "absolute";
	newDiv.style.height = "18px";
	newDiv.style.width = "204px";
	newDiv.style.paddingLeft = "5px";
	newDiv.style.overflow = "hidden";
	newDiv.style.lineHeight = "18px";
	newDiv.appendChild(document.createTextNode(content[meetBannerIndex].firstChild.nodeValue));
	lnkTeleport.setAttribute("href", slURL[meetBannerIndex].firstChild.nodeValue);
	lnkTeleport.style.display = "block";
	
	rollingArea.appendChild(newDiv);
	
	setTimeout("addShowMeetBanner(1)", 5000);
}

function addShowMeetBanner(arg)
{	
	if (totalLength == meetBannerIndex + 1)
	{
		meetBannerIndex = 0;
	}
	else
	{
		meetBannerIndex += 1;
	}
	
	var rollingArea = document.getElementById("RollingArea");
	
	// 이상하게도 전체 너비가 한 번 늘어난 후에는 더 늘지 않는다. 늘어나고 계속 오른쪽에 레이어가 붙는 셈.
	if (arg == 0)
	{
		rollingArea.getElementsByTagName("div")[0].style.left = "0";
	}
	
	var lnkTeleport = document.getElementById("LnkTeleport");
	var newDiv = document.createElement("div");
	newDiv.style.position = "absolute";
	newDiv.style.height = "18px";
	newDiv.style.width = "204px";
	newDiv.style.paddingLeft = "5px";
	newDiv.style.overflow = "hidden";
	newDiv.style.lineHeight = "18px";
	newDiv.appendChild(document.createTextNode(content[meetBannerIndex].firstChild.nodeValue));
	var newLeftPosition = eval(rollingArea.style.width.substr(0,3));
	newDiv.style.left = (newLeftPosition) + "px";
	newDiv.style.top = "0";
	rollingArea.appendChild(newDiv);
	lnkTeleport.setAttribute("href", slURL[meetBannerIndex].firstChild.nodeValue);
	lnkTeleport.style.display = "none";
	
	slideShowMeetBanner(0);
}

function slideShowMeetBanner(leftPosition)
{
	var rollingArea = document.getElementById("RollingArea");
	var lnkTeleport = document.getElementById("LnkTeleport");
	rollingArea.style.left = leftPosition + "px";
	rollingArea.style.top = "0";
	
	leftPosition -= 10;
	
	if (leftPosition < -210)
	{
		//leftPosition = 0;
		//rollingArea.style.left = leftPosition + "px";
		rollingArea.removeChild(rollingArea.getElementsByTagName("div")[0]);
		lnkTeleport.style.display = "block";
		setTimeout("addShowMeetBanner(0)", 5000);
	}
	else
	{
		setTimeout("slideShowMeetBanner(" + leftPosition + ")", 100);
	}
}

function setupMeetBanner()
{
	sendRequest(on_loadedMeetXML, "", "GET", "../../GetMeetListXml.aspx", true, true);
}

function gotoSLURL(arg)
{
	if (arg == "2" || arg == "5" || arg == "14")
	{
		alert("서비스 점검중입니다. 다른 지역을 이용해주세요.");
	}
	else
	{
		window.open(arg, "_blank", "");
	}
	return false;
}

// 지도 부분 스크립트
function make2ByteNumber(arg)
{
	var returnStr = "";
	
	if (arg < 10)
	{
		returnStr = "0" + arg;
	}
	else
	{
		returnStr = arg;
	}
	
	return returnStr;
}

function turnOnArea(arg)
{
	var targetNo = eval(arg);
	var targetString = make2ByteNumber(targetNo);
	var MapTable = document.getElementById("MapTable");
	var targetElement = MapTable.getElementsByTagName("img")[targetNo -1];
	targetElement.setAttribute("src", imageRoot + "board/meetzone/zone_" + targetString + "_over.gif");
}

function turnOffArea(arg, Status)
{
	var targetNo = eval(arg);
	var targetString = make2ByteNumber(targetNo);
	var MapTable = document.getElementById("MapTable");
	var targetElement = MapTable.getElementsByTagName("img")[targetNo -1];
	if (Status == "Off")
	{
	targetElement.setAttribute("src", imageRoot + "board/meetzone/bigcell05/zone_icon_" + targetString + ".gif");
	}
	else
	{
	targetElement.setAttribute("src", imageRoot + "board/meetzone/zone_" + targetString + ".gif");
	}
}

function teleportTo(arg)
{
	if (arg == "2" || arg == "5" || arg == "14" )
	{
		alert("서비스 점검중입니다. 다른 지역을 이용해주세요.");
	}
	else
	{
		ViewerOpen(URLsForTeleport[eval(arg)-1]);
		//window.open(URLsForTeleport[eval(arg)-1], "_blank", "");
	}
}

addLoadEvent(setupMeetBanner);