var iMaxTS=10,iMaxTBS=10;
var iReadStep=0;
var sLoDID=',';
var iDelay=150;
var iDisplayCateNo=0;
var iTSTimer=0;
var iTSCount,iTSCur,iTSFading,iTSPrev=0,iTSNext=0,iTSFastMove=0;
var iFadeDelay=30;
var iBoxCount=0;

function getNodeValue(o){
	try	{
		return o.item(0).firstChild.nodeValue;
	}
	catch(err) {
		return '';
	}
}

function displayid(id,add){
	if (typeof(add)=='undefined') add=true;
	if (sLoDID.indexOf(id)<=0){
		if (add) sLoDID=sLoDID.concat(id).concat(',');
		//sLoDID=sLoDID.concat(id).concat(',');
		return true;
	}
	else{
		return false;
	}
}

function showtopstoryitem(arItemTS){
	iTSCount = arItemTS.length-1;
	var sHTML='';
	sHTML=sHTML.concat('<div style="position:relative;width:460px;height:265px;">');
	sHTML=sHTML.concat('	<div style="left:0px;top:0px;width:460px;height:3px;" class="HomeTopStoryBorder"></div>');
	sHTML=sHTML.concat('	<div style="left:0px;top:262px;width:460px;height:3px;" class="HomeTopStoryBorder"></div>');
	sHTML=sHTML.concat('	<div style="left:0px;top:3px;width:3px;height:259px;" class="HomeTopStoryBorder"></div>');
	sHTML=sHTML.concat('	<div style="left:457;top:3px;width:3px;height:259px;" class="HomeTopStoryBorder"></div>');
	for (var i=0;i<=iTSCount;i++){
		sHTML=sHTML.concat('	<div id="divTopStory').concat(i).concat('" onmousemove="cleartopstorycounter();" style="overflow:hidden;position:absolute;').concat(iif(i==0,'left:0px','left:-1000px')).concat(';top:0px;width:460px;height:265px;">');
		sHTML=sHTML.concat('		<a target="_blank" href="').concat(arItemTS[i][1]).concat('"><img border="0" src="').concat(arItemTS[i][4]).concat('" width="460" height="265"></a>');
		sHTML=sHTML.concat('	</div>');
		sHTML=sHTML.concat('	<div id="divTopStoryLayer').concat(i).concat('" onmousemove="cleartopstorycounter();" style="').concat(iif(i==0,'left:0px','left:-1000px')).concat(';top:200px;width:460px;height:65px;" class="HomeTopStoryColorLayer"></div>');
		sHTML=sHTML.concat('	<div id="divTopStoryTitle').concat(i).concat('" onmousemove="cleartopstorycounter();" style="').concat(iif(i==0,'left:0px','left:-1000px')).concat(';top:200px;width:460px;height:65px;" class="HomeTopStoryColorLayerContent">');
//		sHTML=sHTML.concat('		<div style="left:7px;top:4px;width:455px;height:18px;" class="HomeTopStoryTitle" onclick="window.location=\'').concat(arItemTS[i][1]).concat('\'">').concat(arItemTS[i][2]).concat('</div>');
		sHTML=sHTML.concat('		<div style="left:7px;top:4px;width:455px;height:18px;" class="HomeTopStoryTitle">');
		sHTML=sHTML.concat('			<a target="_blank" href="').concat(arItemTS[i][1]).concat('">').concat(arItemTS[i][2]).concat('</a>');
		sHTML=sHTML.concat('		</div>');
		sHTML=sHTML.concat('		<div style="left:8px;top:5px;width:455px;height:18px;" class="HomeTopStoryTitleShadow">').concat(arItemTS[i][2]).concat('</div>');
		sHTML=sHTML.concat('		<div style="left:8px;top:28px;width:440px;height:18px;" class="HomeTopStoryLead">').concat(arItemTS[i][3]).concat('</div>');
		sHTML=sHTML.concat('	</div>');
	}
	sHTML=sHTML.concat('<div style="left:432px;top:244px;width:40px;height:32px;" class="HomeTopStoryColorLayerSubImage">');
	sHTML=sHTML.concat('<img id="imgTSPrev" src="arrow/Prev2.gif" hspace="2" vspace="0" onmouseover="iTSPrev=1;this.src=\'arrow/Prev.gif\'" onmouseout="iTSPrev=0;this.src=\'arrow/Prev2.gif\'" style="cursor:pointer" onclick="changetopstory(-1,false);">');
	sHTML=sHTML.concat('<img id="imgTSNext" src="arrow/Next2.gif" hspace="2" vspace="0" onmouseover="iTSNext=1;this.src=\'arrow/Next.gif\'" onmouseout="iTSNext=0;if (!iTSFading) this.src=\'arrow/Next2.gif\'" style="cursor:pointer" onclick="changetopstory(1,false);">');
	sHTML=sHTML.concat('</div>');
	sHTML=sHTML.concat('</div>');
	gmobj('tdTS').innerHTML=sHTML;
	iTSCur=0;
	setInterval(function(){topstorycounter();},100)
}

function changetopstory(direction,fade){
	var iTop, iBot;
	var oTop, oBot, oTopLayer, oBotLayer, oTopTitle, oBotTitle;
	
	iTop=iTSCur;
	iBot=iTop+direction;
	if (iBot<0) iBot=iTSCount;
	if (iBot>iTSCount) iBot=0;
	oTop = 'divTopStory'+iTop;
	oBot = 'divTopStory'+iBot;
	oTopLayer = 'divTopStoryLayer'+iTop;
	oBotLayer = 'divTopStoryLayer'+iBot;
	oTopTitle = 'divTopStoryTitle'+iTop;
	oBotTitle = 'divTopStoryTitle'+iBot;
	if (iTSFading==1){
		gmobj('divTopStory'+(iTop+1)).style.left='-1000px';
		gmobj('divTopStoryLayer'+(iTop+1)).style.left='-1000px';
		gmobj('divTopStoryTitle'+(iTop+1)).style.left='-1000px';
		outdirectionimage();
		iTSFading=0;
	}

	iTSTimer=0;
	if (!fade){
		iTSFastMove=1;
		changeOpac(100,oBot);
		changeOpac(40,oBotLayer);
		changeOpac(100,oBotTitle);
		gmobj(oTop).style.zIndex=1;
		gmobj(oBot).style.zIndex=2;
		gmobj(oBot).style.left='0px';
		gmobj(oTop).style.left='-1000px';
		gmobj(oBotLayer).style.left='0px';
		gmobj(oTopLayer).style.left='-1000px';
		gmobj(oBotTitle).style.left='0px';
		gmobj(oTopTitle).style.left='-1000px';
		iTSFading=0;
		iTSCur=iBot;
	}
	else{
		iTSFastMove=0;
		changeOpac(100,oBot);
		changeOpac(0,oBotLayer);
		changeOpac(0,oBotTitle);
		gmobj(oTop).style.zIndex=2;
		gmobj(oBot).style.zIndex=1;
		gmobj(oBot).style.left='0px';
		gmobj(oBotLayer).style.left='0px';
		gmobj(oBotTitle).style.left='0px';
		iTSFading=1;
		changingdirectionimage(direction);
		changingtopstory(iTop,iBot,0,100);
	}
}

function changingtopstory(iTop,iBot,iStep,iCurOpac){
	var oTop, oBot, oTopLayer, oBotLayer, oTopTitle, oBotTitle;
	oTop = 'divTopStory'+iTop;
	oBot = 'divTopStory'+iBot;
	oTopLayer = 'divTopStoryLayer'+iTop;
	oBotLayer = 'divTopStoryLayer'+iBot;
	oTopTitle = 'divTopStoryTitle'+iTop;
	oBotTitle = 'divTopStoryTitle'+iBot;
	if (iTSFading==1){
		if (iStep==0){
			if (iCurOpac>=0){
				changeOpac(iCurOpac,oTopTitle);
				changeOpac(iCurOpac*40/100,oTopLayer);
				iCurOpac-=5;
				setTimeout(function(){changingtopstory(iTop,iBot,0,iCurOpac)},iFadeDelay);
			}
			else{
				setTimeout(function(){changingtopstory(iTop,iBot,1,100)},2000);
			}
		}
		else if (iStep==1){
			if (iCurOpac>=0){
				changeOpac(iCurOpac,oTop);
				iCurOpac-=5;
				setTimeout(function(){changingtopstory(iTop,iBot,1,iCurOpac)},iFadeDelay);
			}
			else{
				iTSCur=iBot;
				gmobj(oTop).style.left='-1000px';
				gmobj(oTopLayer).style.left='-1000px';
				gmobj(oTopTitle).style.left='-1000px';
				setTimeout(function(){changingtopstory(iTop,iBot,2,0)},100);
			}
		}
		else if (iStep==2){
			if (iCurOpac<=100){
				changeOpac(iCurOpac,oBotTitle);
				changeOpac(iCurOpac*40/100,oBotLayer);
				iCurOpac+=5;
				setTimeout(function(){changingtopstory(iTop,iBot,2,iCurOpac)},iFadeDelay);
			}
			else{
				outdirectionimage();
				iTSFading=0;
				iTSTimer=0;
			}
		}
	}
	else if (iStep<2 && iTSFastMove==0) {
		gmobj(oBot).style.left='-1000px';
		gmobj(oBotLayer).style.left='-1000px';
		gmobj(oBotTitle).style.left='-1000px';
		outdirectionimage();
		iTSFading=0;
		iTSTimer=0;
	}
}

function changingdirectionimage(direction){
	if (direction>0) gmobj('imgTSNext').src="arrow/Next.gif"
	else gmobj('imgTSPrev').src="arrow/Prev.gif"
}

function outdirectionimage(){
	if (iTSNext==0) gmobj('imgTSNext').src="arrow/Next2.gif"
	if (iTSPrev==0) gmobj('imgTSPrev').src="arrow/Prev2.gif"
}

function topstorycounter(){
	iTSTimer++;
	if (iTSTimer>70) {
		iTSTimer=0;
		changetopstory(1,true);
	}
}

function cleartopstorycounter(){
	changeOpac(100,'divTopStory'+iTSCur);
	changeOpac(40,'divTopStoryLayer'+iTSCur);
	changeOpac(100,'divTopStoryTitle'+iTSCur);
	iTSFading=0;
	iTSTimer=0;
}

function changeOpac(opacity, id) {
	gmobj(id).style.opacity = (opacity / 100);
	gmobj(id).style.MozOpacity = (opacity / 100);
	gmobj(id).style.KhtmlOpacity = (opacity / 100);
	gmobj(id).style.filter = "alpha(opacity=" + opacity + ")";
}

function AddBreak (vHeight)
{
	return '<table border=0 cellpadding=0 cellspacing=0><tr><td height='+vHeight+'></td></tr></table>'
}

/*--- Common functions ----------------------------------------------------------------------------------------------------------------*/

function gmobj(o){
	if(document.getElementById){
		m=document.getElementById(o);
	}
	else if(document.all){
		m=document.all[o];
	}else if(document.layers){
		m=document[o];
	}
	return m;
}

function iif(iEx1,r1,r2){
	if(iEx1)return r1;
	else return r2;
}

function toUpper(sInput){
	sInput=sInput.toUpperCase()
	var sOutput='',sTemp;
	var i=0, j=0;
	for (var i=0;i<sInput.length;i++){
		if (sInput.charAt(i)+sInput.charAt(i+1)=='&#'){
			sTemp=sInput.substring(i+2,sInput.length);
			j=sTemp.indexOf(';');
			if (j>4){
				sOutput+=sInput.charAt(i);					
			}
			else{
				sTemp=sTemp.substring(0,j)
				switch(sTemp){
					case '225': {sOutput+='&#193;';break;}		//a'
					case '224': {sOutput+='&#192;';break;}		//a`
					case '7843': {sOutput+='&#7842;';break;}	//a?
					case '227': {sOutput+='&#195;';break;}		//a~
					case '7841': {sOutput+='&#7840;';break;}	//a.
					case '226': {sOutput+='&#194;';break;}		//a^
					case '7845': {sOutput+='&#7844;';break;}	//a^'
					case '7847': {sOutput+='&#7846;';break;}	//a^`
					case '7849': {sOutput+='&#7848;';break;}	//a^?
					case '7851': {sOutput+='&#7850;';break;}	//a^~
					case '7853': {sOutput+='&#7852;';break;}	//a^.
					case '259': {sOutput+='&#258;';break;}		//a(
					case '7855': {sOutput+='&#7854;';break;}	//a('
					case '7857': {sOutput+='&#7856;';break;}	//a(`
					case '7859': {sOutput+='&#7858;';break;}	//a(?
					case '7861': {sOutput+='&#7860;';break;}	//a(~
					case '7863': {sOutput+='&#7862;';break;}	//a(.
					case '273': {sOutput+='&#272;';break;}		//dd
					case '233': {sOutput+='&#201;';break;}		//e'
					case '232': {sOutput+='&#200;';break;}		//e`
					case '7867': {sOutput+='&#7866;';break;}	//e?
					case '7869': {sOutput+='&#7868;';break;}	//e~
					case '7865': {sOutput+='&#7864;';break;}	//e.
					case '234': {sOutput+='&#202;';break;}		//e^
					case '7871': {sOutput+='&#7870;';break;}	//e^'
					case '7873': {sOutput+='&#7872;';break;}	//e^`
					case '7875': {sOutput+='&#7874;';break;}	//e^?
					case '7877': {sOutput+='&#7876;';break;}	//e^~
					case '7879': {sOutput+='&#7878;';break;}	//e^.
					case '237': {sOutput+='&#205;';break;}		//i'
					case '236': {sOutput+='&#204;';break;}		//i`
					case '7881': {sOutput+='&#7880;';break;}	//i?
					case '297': {sOutput+='&#296;';break;}		//i~
					case '7883': {sOutput+='&#7882;';break;}	//i.
					case '243': {sOutput+='&#211;';break;}		//o'
					case '242': {sOutput+='&#210;';break;}		//i`
					case '7887': {sOutput+='&#7886;';break;}	//o?
					case '245': {sOutput+='&#213;';break;}		//o~
					case '7885': {sOutput+='&#7884;';break;}	//o.
					case '244': {sOutput+='&#212;';break;}		//o^
					case '7889': {sOutput+='&#7888;';break;}	//o^'
					case '7891': {sOutput+='&#7890;';break;}	//o^`
					case '7893': {sOutput+='&#7892;';break;}	//o^?
					case '7895': {sOutput+='&#7894;';break;}	//o^~
					case '7897': {sOutput+='&#7896;';break;}	//o^.
					case '417': {sOutput+='&#416;';break;}		//o*
					case '7899': {sOutput+='&#7898;';break;}	//o*'
					case '7901': {sOutput+='&#7900;';break;}	//o*`
					case '7903': {sOutput+='&#7902;';break;}	//o*?
					case '7905': {sOutput+='&#7904;';break;}	//o*~
					case '7907': {sOutput+='&#7906;';break;}	//o*.
					case '250': {sOutput+='&#218;';break;}		//u'
					case '249': {sOutput+='&#217;';break;}		//u`
					case '7911': {sOutput+='&#7910;';break;}	//u?
					case '361': {sOutput+='&#360;';break;}		//u~
					case '7909': {sOutput+='&#7908;';break;}	//u.
					case '432': {sOutput+='&#431;';break;}		//u*
					case '7913': {sOutput+='&#7912;';break;}	//u*'
					case '7915': {sOutput+='&#7914;';break;}	//u*`
					case '7917': {sOutput+='&#7916;';break;}	//u*?
					case '7919': {sOutput+='&#7918;';break;}	//u*~
					case '7921': {sOutput+='&#7920;';break;}	//u*.
					case '253': {sOutput+='&#221;';break;}		//y'
					case '7923': {sOutput+='&#7922;';break;}	//y`
					case '7927': {sOutput+='&#7926;';break;}	//y?
					case '7929': {sOutput+='&#7928;';break;}	//y~
					case '7925': {sOutput+='&#7924;';break;}	//y.
					default: {sOutput+='&#'+sTemp+';';break;}
				}
				i+=j+2;
			}
		}
		else{
			sOutput+=sInput.charAt(i);
		}
	}
	return sOutput;
}