function CM_headline()
{
	this.data = null;
	this.itemCount = 0;
	this.name = '';
	this.itemsName = '';

	this.isChangeable = 1;
	this.curIndex = 0;
	this.prevItem = 0;
	this.timeoutFunction = '';
	this.timeoutIndex = "";

	this.imageElement = null;
	this.linkElement = null;
	this.titleElement = null;
	this.displayElement = null;
	this.newsTypeElement = null;

	this.changeItem = function(opcode)
	{		
		this.clearTimeout();

		this.curIndex += opcode;

		if(this.curIndex > this.itemCount)
			this.curIndex = 1;
		else if (this.curIndex < 1)
			this.curIndex = this.itemCount;

		if(this.imageElement)
		{
			this.imageElement.src = "images/news/" + this.data[this.curIndex]['image'] + ".jpg";
		}

		if(this.linkElement)
		{
			this.linkElement.href = this.data[this.curIndex]['link'];
		}

		if(this.newsTypeElement)
		{
			if(this.data[this.curIndex]['news_type'])
			{
				_WIDTH = 440;
				_HEIGHT = 270;
				_SRC = 'images/flash_news_type_'+ this.data[this.curIndex]['news_type'] + '.swf';
				
				str = '<div style="width: ' + _WIDTH + 'px; height: ' + _HEIGHT + 'px;">';
				str += '<object width="' + _WIDTH + '" height="' + _HEIGHT + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0">';
				str += '<param name="movie" value="' + _SRC + '">';
				str += '<param name="quality" value="high">';
				str += '<param name="wmode" value="transparent">';
				str += '<param name="scale" value="1">';
				str += '<embed src="' + _SRC + '" width="' + _WIDTH + '" height="' + _HEIGHT + '" scale="exactfit" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>';
				str += '</object>';
				str += '</div>';

				this.newsTypeElement.style.display = 'block';
				this.imageElement.style.width = '440px';
				this.imageElement.style.height = '270px';
			}
			else
			{
				str = '';

				this.newsTypeElement.style.display = 'none';
				this.imageElement.style.width = '440px';
				this.imageElement.style.height = '270px';
			}

			this.newsTypeElement.innerHTML = str;
		}

		if(this.itemsName)
		{
			document.getElementById(this.itemsName + this.curIndex).className = "active";

			if(this.prevItem != 0)
			{
				document.getElementById(this.itemsName + this.prevItem).className = "";
			}
		}

		if(this.displayElement)
		{
			this.displayElement.innerHTML = this.curIndex + ' / ' + this.itemCount;
		}

		if(this.titleElement)
		{
			this.titleElement.innerHTML = this.data[this.curIndex]['title'];
		}

		//document.getElementById("news_arrow").style.backgroundPosition = (22 + curIndex * 58 ) + "px 0px";

		this.prevItem = this.curIndex;

		if(this.isChangeable)
			this.timeoutIndex = setTimeout(this.timeoutFunction, 8000);
	}

	this.clearTimeout = function()
	{
		if(this.timeoutIndex != "")
		{
			clearTimeout(this.timeoutIndex);
			this.timeoutIndex = "";
		}
	}

	this.jumpTo = function(idx)
	{
		if(idx == this.prevItem)
			return;

		this.isChangeable = 0;
		this.clearTimeout();
		this.changeItem(idx - this.prevItem);
	}

	this.forwClick = function()
	{
		this.isChangeable = 1;

		this.timeoutFunction = this.name + ".changeItem(1)";

		this.changeItem(1);

		this.clearTimeout();

		this.timeoutIndex = setTimeout(this.timeoutFunction, 8000);
	}
	
	this.backClick = function()
	{
		this.isChangeable = 1;

		this.timeoutFunction = this.name + ".changeItem(-1)";

		this.changeItem(-1);

		this.clearTimeout();

		this.timeoutIndex = setTimeout(this.timeoutFunction, 8000);
	}
}

var prevToptopHeadlinePage = 1;
function topHeadlinePageNext(count)
{
	if(prevToptopHeadlinePage + 1 <= count)
		topHeadlinePage(prevToptopHeadlinePage + 1);

	return false;
}

function topHeadlinePage(page, category, location)
{
	if(prevToptopHeadlinePage == page)
		return false;

    var xmlHttpReq = false;
    var self = this;
    var strURL = 'x_top_headline_page.php?page=' + page + '&category=' + category;

    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-javascript; charset=iso-8859-9');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
        	if(prevToptopHeadlinePage != null)
        	{
        		document.getElementById('top_headline_page_' + prevToptopHeadlinePage).className = "item";
        	}
        	document.getElementById('top_headline_page_' + page).className = "item active";
        	prevToptopHeadlinePage = page;

            topHeadlinePageLoad(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send('');

    return false;
}

function topHeadlinePageLoad(str)
{
	eval(str);

	document.getElementById("top_headline_items").innerHTML = topHeadlineItems;
	document.getElementById("top_headline_images").innerHTML = topHeadlineImages;

	CM_headlineMain.data = top_news_data;
	CM_headlineMain.curIndex = 0;
	CM_headlineMain.prevItem = 0;
	CM_headlineMain.jumpTo(1);
}

function changeNewsDetailFlash(idx)
{
	eval('elm = news_data');
	if(typeof(window['elm']) == "undefined")
		return;
	
	document.getElementById("news_image").src = './images/news/' + elm[idx]['image'] + '.jpg';
	document.getElementById("news_spot").innerHTML = '<a href="' + elm[idx]['link'] + '">' + elm[idx]['short_content'] + '</a>';
	document.getElementById("news_link").href = elm[idx]['link'];
	getFlashMovie("headlineFlashTitle").sendAUtoFlash(elm[idx]['headline']);

	return false;
}

var prevHeadlinePage = 1;
function headlinePageNext(count)
{
	if(prevHeadlinePage + 1 <= count)
		headlinePage(prevHeadlinePage + 1);

	return false;
}

function headlinePage(page, category, location)
{
	if(prevHeadlinePage == page)
		return false;

    var xmlHttpReq = false;
    var self = this;
    var strURL = 'x_headline_page.php?page=' + page + '&category=' + category;

    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-javascript; charset=iso-8859-9');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
        	if(prevHeadlinePage != null)
        	{
        		document.getElementById('headline_page_' + prevHeadlinePage).className = "item";
        	}
        	document.getElementById('headline_page_' + page).className = "item active";
        	prevHeadlinePage = page;

            headlinePageLoad(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send('');

    return false;
}

function headlinePageLoad(str)
{
	eval(str);

	document.getElementById("headline_items").innerHTML = headlineItems;
	document.getElementById("headline_images").innerHTML = headlineImages;

	changeNewsDetailFlash(0);
}
