function createXMLHttpRequest(cbFunc)
{
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}

function $(tagId)
{
	return document.getElementById(tagId);
}

function loadDataFile(fName)
{
	httpObj = createXMLHttpRequest(getData);
	if (httpObj)
	{
		httpObj.open("GET",fName,true);
		httpObj.send(null);
	}
}

function parseJSON(json)
{
	var data = eval("("+json+")");
	return data;
}

function getData()
{
	if ( httpObj )
	{
		httpObj.onreadystatechange = function()
		{
			if ( httpObj.readyState == 4 )
			{
				if( httpObj.status == 200 )
				{
					jsData = parseJSON(httpObj.responseText);
					displayData();
				}
				else
				{
					$("ticker_element").innerHTML = 'Load&nbsp;Error[' + httpObj.status + ']...';
				}

			}
			else
			{
				$("ticker_element").innerHTML = 'Now&nbsp;Loading...';
			}
		}
	}
	else
	{
		$("ticker_element").innerHTML = 'Load&nbsp;Error[undefined]...';
	}
}



function displayData()
{
	var iResult = jsData.item[0].Result; // 要素数
	if( iResult == 0 )
	{
$("ticker_element").innerHTML = '';
return;
		//DIV要素を隠す
		var obj = document.getElementById( "ticker" );
		obj.style.display = 'none';
		return;
	}
	else
	{
	
		 RotateElements();
    }
}



var x = 1;
var stop_delay = 2500;
var rotate_delay = 4500;
var alpha = ( rotate_delay - stop_delay ) / 16;//残り時間を16分割でフェードアウト
var mouseoverstatus = false;
var cnt = 0;
var ctID = '';
var rtID = '';
var atID = '';
function RotateElements()
{
	if ( mouseoverstatus )
	{
		;
	}
	else
	{
		$("ticker_element").innerHTML = '<span OnMouseOver="mouseover()">' + jsData.item[x].Title + '&nbsp;&nbsp;' + jsData.item[x].ShopName + '</span>';
		
		x++;
		if( x == jsData.item.length )
		{
			x = 1;
		}
		clearTimeout( rtID );
		
			NegAlphaElement();
			cnt = 0;
			clearTimeout( atID );
			atID = setTimeout( "AlphaElement('0123456789abcdef')", stop_delay );
		
		rtID = setTimeout( "RotateElements()", rotate_delay );
	}
}

function mouseover()
{
	var num = x - 1;
	if( num == 0 )
	{
		var num = jsData.item.length - 1;
	}
	mouseoverstatus = true;
	$("ticker_element").innerHTML = '<a href="' + jsData.item[num].Link + '" OnMouseOut="mouseout()">' + jsData.item[num].Title + '&nbsp;&nbsp;' + jsData.item[num].ShopName + '</a>';
}

function mouseout()
{
	var num = x - 1;
	if( num == 0 )
	{
		var num = jsData.item.length - 1;
	}
	mouseoverstatus = false;
	$("ticker_element").innerHTML = '<span OnMouseOver="mouseover()">' + jsData.item[num].Title + '&nbsp;&nbsp;' + jsData.item[num].ShopName + '</span>';
	cnt = 0;
	NegAlphaElement();
	clearTimeout( atID );
	atID = setTimeout( "AlphaElement('0123456789abcdef')", stop_delay );
	clearTimeout( rtID );
	rtID = setTimeout( "RotateElements()", rotate_delay );
}

function AlphaElement(str)
{
	if ( mouseoverstatus )
	{
		;
	}
	else
	{
		var num = x - 1;
		if( num == 0 )
		{
			var num = jsData.item.length - 1;
		}
		var obj = document.getElementById( "ticker_element" );
		c = str.charAt(cnt++);
		
		if( cnt < 7 )
		{
			obj.style.color = "#333333";
			ctID = setTimeout( "AlphaElement('" + str + "')", alpha );
		}
		else if( cnt < 10 )
		{
			//obj.style.color = "#"+c+c+c+c+c+c;
			obj.style.color = "#8b8c82";
			ctID = setTimeout( "AlphaElement('" + str + "')", alpha );
		}
		else
		{
			obj.style.color = "#f1f6c7";
			if( cnt == str.length )
			{
				cnt = 0;
			}
			else
			{
				ctID = setTimeout( "AlphaElement('" + str + "')", alpha );
			}
		}

	}
}

function NegAlphaElement()
{
	var obj = document.getElementById( "ticker_element" );
	obj.style.color = '';
}

