
function castGoogle()	//네이버뉴스 검색
{
	var query = "홍익대학교";

	url = "./hongikinCast/getRss.php";
		
	//진행 상태창 보이기
	//$('apiResult').update('<div style="margin-top:100px; text-align:center;"><img src="/adwatcher/img/ajax-loader.gif"></div> ');

	param = { sid : "news", q : encodeURI(query), page : 1 };

	new Ajax.Request(
	url, {
			parameters : param , 
			onSuccess: function(oXml)
			{
				oXml = oXml.responseXML;

				this._data = oXml.getElementsByTagName('item');

				$('editor').update("구글뉴스에서 '"+ query + "'로 검색된 내용입니다");
				$('editorIcon').style.background = "url(./hongikinCast/images/editors.gif) 0 -80px no-repeat";

				$("castMenu_hongikin").style.fontWeight = "normal"; 
				$("castMenu_google").style.fontWeight = "normal";
				$("castMenu_hongika").style.fontWeight = "normal"; 
				$("castMenu_google").style.fontWeight = "bold"; 

				//$('apiResult').setStyle('font-size:11px; line-height:15px;');
				//$('resultDesc').update("\"" + query.substr(0,30) + "\" 로 검색한 뉴스 검색 결과");
				//$('paging').update("<a href='#' onclick='searchNews(" + _page + "-1)'>이전</a> " + _page + " <a href='#' onclick='searchNews(" + _page + "+1)'>다음</a>");

				if( this._data ) {	//검색된 내용이 있을때	
					$('newsCastImage').update("");
					$('newsCastText').update("");
					
					$A(this._data).each(function(item, index) {
						if (index >= 7)	{
							return false;
						}

						try {
							var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
							var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
							var pubDate = item.getElementsByTagName("pubDate")[0].childNodes[0].nodeValue;
							var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
						}
						catch(e) {};

						
						if(index%2 == 1){
							oe = "odd";
						}
						else {
							oe = "even";	
						}

						if (index == 0)	{
							var temp1 = Array();
							var temp2 = Array();
							temp1 = description.split("img src=\""); 

							if(temp1[1] != null) {
								temp2 = temp1[1].split('"');
								var imgUrl = temp2[0];
								$('newsCastImage').insert("<div class='imgImage'><a href='" + link + "'><img src='" + imgUrl + "' /></a></div><div class='imgText'>" + title.substr(0,32) + "</div>");
							}
							else {
								$('newsCastImage').insert("<div class='imgImage'><a href='" + 0 + "'><img src='" + 0 + "' /></a></div><div class='imgText'>" + title.substr(0,32) + "</div>");
							}
						}
						else {
							$('newsCastText').insert(				
								"<div class='newsItem " + oe + "'>" + 
								"<a class='blogTitle' href='" + link + "'>· " + title.substr(0,40) + "</a><br/>" + 
								"</div>"
							);
						}
					});
				}
				else {
					//$('apiResult').update('검색결과가 없습니다.');
				}
			},
			onFailure : function()
			{
				alert("__ERROR__");
			}
		}
	)
}



function castHongikin()	//네이버뉴스 검색
{
	url = "./?mid=column&act=rss";

	
	new Ajax.Request(
	url, {
			onSuccess: function(oXml)
			{

				oXml = oXml.responseXML;

				this._data = oXml.getElementsByTagName('item');

				$('editor').update("홍익인 오픈뉴스에서 편집합니다");
				$('editorIcon').style.background = "url(./hongikinCast/images/editors.gif) 0 0px no-repeat";
				
				$("castMenu_hongikin").style.fontWeight = "normal"; 
				$("castMenu_google").style.fontWeight = "normal";
				$("castMenu_hongika").style.fontWeight = "normal"; 
				$("castMenu_hongikin").style.fontWeight = "bold"; 

				//$('apiResult').setStyle('font-size:11px; line-height:15px;');
				//$('resultDesc').update("\"" + query.substr(0,30) + "\" 로 검색한 뉴스 검색 결과");
				//$('paging').update("<a href='#' onclick='searchNews(" + _page + "-1)'>이전</a> " + _page + " <a href='#' onclick='searchNews(" + _page + "+1)'>다음</a>");

				if( this._data ) {	//검색된 내용이 있을때	
					$('newsCastImage').update("");
					$('newsCastText').update("");


					$A(this._data).each(function(item, index) {
						if (index >= 7)	{
							return false;
						}

						try {
							var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
							var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
							var pubDate = item.getElementsByTagName("pubDate")[0].childNodes[0].nodeValue;
							var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
						}
						catch(e) {};

						
						if(index%2 == 1){
							oe = "odd";
						}
						else {
							oe = "even";	
						}

						if (index == 0)	{
							var temp1 = Array();
							var temp2 = Array();
							temp1 = description.split("img src=\""); 
							temp2 = temp1[1].split('"');
							var imgUrl = temp2[0];

							$('newsCastImage').insert("<div class='imgImage'><a href='" + link + "'><img src='" + imgUrl + "' /></a></div><div class='imgText'>" + title.substr(0,35) + "</div>");
						}
						else {
							$('newsCastText').insert(				
								"<div class='newsItem " + oe + "'>" + 
								"<a class='blogTitle' href='" + link + "'>· " + title.substr(0,35) + "</a><br/>" + 
								"</div>"
							);
						}
					});
				}
				else {
					//$('apiResult').update('검색결과가 없습니다.');
				}
			},
			onFailure : function()
			{
				alert("__ERROR__");
			}
		}
	)
}


function castHongikA()	//네이버뉴스 검색
{
	var query = "홍익대학교";

	url = "./hongikinCast/getRss.php";
		
	//진행 상태창 보이기
	//$('apiResult').update('<div style="margin-top:100px; text-align:center;"><img src="/adwatcher/img/ajax-loader.gif"></div> ');

	param = { sid : "hongika", q : encodeURI(query), page : 1 };

	new Ajax.Request(
	url, {
			parameters : param , 
			onSuccess: function(oXml)
			{
				oXml = oXml.responseXML;

				this._data = oXml.getElementsByTagName('item');

				$('editor').update("홍익대학교 총학생회 공지사항입니다");
				$('editorIcon').style.background = "url(./hongikinCast/images/editors.gif) 0 -60px no-repeat";

				$("castMenu_hongikin").style.fontWeight = "normal"; 
				$("castMenu_google").style.fontWeight = "normal";
				$("castMenu_hongika").style.fontWeight = "normal"; 
				$("castMenu_hongika").style.fontWeight = "bold"; 

				//$('apiResult').setStyle('font-size:11px; line-height:15px;');
				//$('resultDesc').update("\"" + query.substr(0,30) + "\" 로 검색한 뉴스 검색 결과");
				//$('paging').update("<a href='#' onclick='searchNews(" + _page + "-1)'>이전</a> " + _page + " <a href='#' onclick='searchNews(" + _page + "+1)'>다음</a>");

				if( this._data ) {	//검색된 내용이 있을때					
					$('newsCastImage').update("");
					$('newsCastText').update("");
					
					$A(this._data).each(function(item, index) {
						if (index >= 7)	{
							return false;
						}

						try {
							var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
							var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
							var pubDate = item.getElementsByTagName("pubDate")[0].childNodes[0].nodeValue;
							var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
						}
						catch(e) {};
				
						if(index%2 == 1){
							oe = "odd";
						}
						else {
							oe = "even";	
						}

						if (index == 0)	{
							var temp1 = Array();
							var temp2 = Array();
							temp1 = description.split("img src=\""); 

							if(temp1[1] != null) {
								temp2 = temp1[1].split('"');
								var imgUrl = temp2[0];
								$('newsCastImage').insert("<div class='imgImage'><a href='" + link + "' target='_blank'><img src='" + imgUrl + "' /></a></div><div class='imgText'>" + title.substr(0,30) + "</div>");
							}
							else {
								var imgUrl = "./hongikinCast/images/hongika.gif";
								$('newsCastImage').insert("<div class='imgImage'><a href='" + link + "' target='_blank'><img src='" + imgUrl + "' /></a></div><div class='imgText'>" + title.substr(0,30) + "</div>");
							}
						}
						else {
							$('newsCastText').insert(				
								"<div class='newsItem " + oe + "'>" + 
								"<a class='blogTitle' href='" + link + "' target='_blank'>· " + title.substr(0,30) + "</a><br/>" + 
								"</div>"
							);
						}
					});
				}
				else {
					//$('apiResult').update('검색결과가 없습니다.');
				}
			},
			onFailure : function()
			{
				alert("__ERROR__");
			}
		}
	)
}

function randCast() 
{
	var now = new Date();
	var r = now.getSeconds();

	switchTime = r%4; 

	switch( switchTime )
	{ 
		case 0: castHongikA(); break;
		case 1: castHongikA(); break;
		case 2: castGoogle(); break;
		default: castGoogle(); break;
	}	

}

randCast();


