﻿var XmlMainStories;
var SectionsCount
var SectionsArticlesCount
var TextNodeDefine
var CurrentSectionId
var CurrentSelectedArticle=0
var CurrentSelectedArticleGuid=0
var TimerObj
var PausTimer=false;

try //Internet Explorer
  {
	TextNodeDefine='text'
	XmlMainStories = new ActiveXObject("MSXML.DOMDocument")	
  }
catch(e)
{
	try //Firefox, Mozilla, Opera, etc.
	{
	TextNodeDefine='textContent'
	XmlMainStories=document.implementation.createDocument("","",null);
	}
	catch(e) {alert(e.message)}
}
function LoadXmlDoc()
{
	try //Internet Explorer
	{
		XmlMainStories.loadXML(document.getElementById('hdnStudiesBibliographyMainStories').value);
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			parser=new DOMParser();
			XmlMainStories=parser.parseFromString(document.getElementById('hdnStudiesBibliographyMainStories').value,"text/xml");
		}
		catch(e) 
		{
			alert(e.message)
		}
	}
}
function replaceText(Text,OldText,NewText) 
{
	while(Text.indexOf(OldText)!=-1)
	{
		Text=Text.replace(OldText,NewText)
	}
	return Text
}
function InitialData()
{
	CurrentSelectedArticle=0
	CurrentSelectedArticleGuid=0
	PausTimer=false;
	window.clearTimeout(TimerObj)
	if (XmlMainStories.selectNodes("//Root/Items").length>0)
	{
		SectionsCount=XmlMainStories.selectNodes("//Root/Items").length
	
		var Str='';
		var SectionImageURL		
		Str+='<TABLE cellSpacing="0" cellPadding="0" width="83" border="0"><tr><td>'
		Str+='<div id="divBiblLeftMainStories" style="position:static; height:315px; overflow: hidden; margin: auto;">'
		Str+='<TABLE cellSpacing="0" cellPadding="0" id="tblBiblLeftMainStories" width="83" border="0">'
		for(I=0;I<SectionsCount;I++)
		{
			Str+='<TR>'
			Str+='<TD align="center">'
			Str+='<TABLE cellSpacing="0" cellPadding="0" border="0">'
			Str+='<tr><td class="imgBrd">'
			SectionImageURL=PAResourcesPath+replaceText(XmlMainStories.selectNodes("//Root/Items")[I].attributes.getNamedItem("SectionImage").value,'\\','/')
			Str+='<IMG height="68" style="cursor:pointer" id="imgSmallMainImage'+XmlMainStories.selectNodes("//Root/Items")[I].attributes.getNamedItem("SectionId").value+'" onclick="window.clearTimeout(TimerObj);CurrentSelectedArticle='+I+';RenderLeftMainStoriesArticles()" src="'+SectionImageURL+'" width="85" />'
			Str+='</td></tr></table>'
			Str+='</TD>'
			Str+='</TR>'
			Str+='<TR>'
			Str+='<TD height="9"></TD>'
			Str+='</TR>'
		}
		Str+='</td></tr></TABLE>'
		Str+='</div>'		
		Str+='<tr><TD height="12"></TD></tr>'
		Str+='<TR>'
		Str+='<TD class="smlArrowBg" align="center" height="30">'
		Str+='<TABLE cellSpacing="0" cellPadding="0" width="66" border="0">'
		Str+='<TR>'
		Str+='<TD align="left">'
		Str+='<IMG height="22" src="/Studies/images/smlDownArrow.jpg" id="imgLeftScrollingDown" onclick="ScrollingDownLeftMainStories(\'divBiblLeftMainStories\',this)" style="cursor:pointer" width="29" />'
		Str+='</TD>'
		Str+='<TD>'
		Str+='<IMG src="/Studies/images/pause_btn.jpg" onclick="CheckTimerPuase(this)" style="cursor:pointer" />'
		Str+='</TD>'
		Str+='<TD align="right">'
		Str+='<IMG height="22" src="/Studies/images/smlUparrow-D.jpg" id="imgLeftScrollingUp" onclick="ScrollingUpLeftMainStories(\'divBiblLeftMainStories\')" width="29" />'
		Str+='</TD>'
		Str+='</TR>'
		Str+='</TABLE>'
		Str+='</TD>'
		Str+='</TR>'
		Str+='</TABLE>'

		document.getElementById('tdLeftBibloMainStories').innerHTML=Str
		RenderLeftMainStoriesArticles()
	}
}
function CheckTimerPuase(Obj)
{
	if(PausTimer)
	{
		Obj.src='/Studies/images/pause_btn.jpg';
		PausTimer=false;
		ScrollingTimerSections()
	}
	else
	{
		Obj.src='/Studies/images/Play_bnt.jpg';
		PausTimer=true;
		window.clearTimeout(TimerObj)
	}
}
function ScrollingTimerSections()
{
	if (CurrentSelectedArticle<eval(SectionsCount-1))
	{
		CurrentSelectedArticle++
		RenderLeftMainStoriesArticles()
		ScrollingDownLeftMainStories('divBiblLeftMainStories')
	}
	else
	{
		CurrentSelectedArticle=0
		document.getElementById('divBiblLeftMainStories').scrollTop=0
		document.getElementById('imgLeftScrollingUp').src='/Studies/Images/smlUparrow-D.jpg';
		document.getElementById('imgLeftScrollingUp').style.cursor='default'
		document.getElementById('imgLeftScrollingDown').src='/Studies/Images/smlDownArrow.jpg';
		document.getElementById('imgLeftScrollingDown').style.cursor='pointer'
		RenderLeftMainStoriesArticles()
	}
	window.clearTimeout(TimerObj)
	if (!PausTimer && SectionsCount>1)
	{
		TimerObj=window.setTimeout("ScrollingTimerSections()",10000)
	}
}
function ScrollingDownLeftMainStories(Obj,Target)
{
	if (SectionsCount>4)
	{
		if (CurrentSelectedArticle>3 && Target==null)
		{
			ScrollingLeftDownTimer(Obj,eval(document.getElementById('tblBiblLeftMainStories').offsetHeight/SectionsCount)*Math.abs(eval(CurrentSelectedArticle-3)),document.getElementById(Obj).scrollTop)
		}
		else if (SectionsCount>4 && Target!=null)
		{
			ScrollingLeftDownTimer(Obj,eval(document.getElementById('tblBiblLeftMainStories').offsetHeight/SectionsCount)+document.getElementById(Obj).scrollTop,document.getElementById(Obj).scrollTop)
		}
	}
}
function ScrollingLeftDownTimer(Obj,YSize,StartSize)
{	
	if (StartSize<=YSize)
	{
		document.getElementById(Obj).scrollTop=StartSize
		window.setTimeout("ScrollingLeftDownTimer('"+Obj+"',"+YSize+","+eval(eval(StartSize)+eval(2))+")",1)
		document.getElementById('imgLeftScrollingUp').src='/Studies/Images/smlUparrow.jpg';
		document.getElementById('imgLeftScrollingUp').style.cursor='pointer'
	}
	else if(eval(document.getElementById(Obj).scrollHeight - document.getElementById(Obj).style.height.replace('px',''))<=document.getElementById(Obj).scrollTop)
	{
		document.getElementById('imgLeftScrollingDown').src='/Studies/Images/smlDownArrow-D.jpg'
		document.getElementById('imgLeftScrollingDown').style.cursor='default'
	}		
	
}
function ScrollingUpLeftMainStories(Obj)
{
	ScrollingLeftUpTimer(Obj,Math.abs(eval(Math.round(document.getElementById('tblBiblLeftMainStories').offsetHeight/SectionsCount))-document.getElementById(Obj).scrollTop),document.getElementById(Obj).scrollTop)
}
function ScrollingLeftUpTimer(Obj,YSize,StartSize)
{
	if (StartSize>=YSize)
	{
		document.getElementById(Obj).scrollTop=StartSize
		window.setTimeout("ScrollingLeftUpTimer('"+Obj+"',"+YSize+","+eval(eval(StartSize)-eval(2))+")",1)
		document.getElementById('imgLeftScrollingDown').src='/Studies/Images/smlDownArrow.jpg';
		document.getElementById('imgLeftScrollingDown').style.cursor='pointer'
	}
	else if (YSize-1>StartSize+1)
	{
		document.getElementById(Obj).scrollTop=0
		document.getElementById('imgLeftScrollingUp').src='/Studies/Images/smlUparrow-D.jpg';
		document.getElementById('imgLeftScrollingUp').style.cursor='default'
	}
}
function ScrollingDownRightMainStories(Obj)
{
	ScrollingRightDownTimer(Obj,eval(document.getElementById('tblBiblRightMainStories').offsetHeight/SectionsArticlesCount)+document.getElementById(Obj).scrollTop,document.getElementById(Obj).scrollTop)
}
function ScrollingRightDownTimer(Obj,YSize,StartSize)
{	
	if (StartSize<=YSize)
	{
		document.getElementById(Obj).scrollTop=StartSize
		window.setTimeout("ScrollingRightDownTimer('"+Obj+"',"+YSize+","+eval(eval(StartSize)+eval(2))+")",1)
		if (SectionsArticlesCount>4)
		{
			document.getElementById('imgRightScrollingUp').src='/Studies/Images/smlUparrow.jpg';
			document.getElementById('imgRightScrollingUp').style.cursor='pointer'
		}
	}
	else if(eval(document.getElementById(Obj).scrollHeight - document.getElementById(Obj).style.height.replace('px',''))<=document.getElementById(Obj).scrollTop+5)
	{
		document.getElementById(Obj).scrollTop=document.getElementById(Obj).scrollHeight
		document.getElementById('imgRightScrollingDown').src='/Studies/Images/smlDownArrow-D.jpg';
		document.getElementById('imgRightScrollingDown').style.cursor='default'
	}	
	
}
function ScrollingUpRightMainStories(Obj)
{
	ScrollingRightUpTimer(Obj,Math.abs(eval(Math.round(document.getElementById('tblBiblRightMainStories').offsetHeight/SectionsArticlesCount))-document.getElementById(Obj).scrollTop),document.getElementById(Obj).scrollTop)
}
function ScrollingRightUpTimer(Obj,YSize,StartSize)
{
	if (StartSize>=YSize)
	{
		document.getElementById(Obj).scrollTop=StartSize
		window.setTimeout("ScrollingRightUpTimer('"+Obj+"',"+YSize+","+eval(eval(StartSize)-eval(2))+")",1)
		document.getElementById('imgRightScrollingDown').src='/Studies/Images/smlDownArrow.jpg';
		document.getElementById('imgRightScrollingDown').style.cursor='pointer'
	}
	else if (StartSize<=1)
	{
		document.getElementById(Obj).scrollTop=0
		document.getElementById('imgRightScrollingUp').src='/Studies/Images/smlUparrow-D.jpg';
		document.getElementById('imgRightScrollingUp').style.cursor='default'
	}
}
function RenderLeftMainStoriesArticles()
{
	CurrentSectionId=XmlMainStories.selectNodes("//Root/Items")[CurrentSelectedArticle].attributes.getNamedItem("SectionId").value
	CurrentSelectedArticleGuid=XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item")[0].selectSingleNode("Guid")[TextNodeDefine]
	SectionsArticlesCount=XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item").length
	
	var Str='';
	Str+='<TABLE cellSpacing="0" cellPadding="0" width="83" border="0"><tr><td>'
	Str+='<div id="divBiblRightMainStories" style="position:static; height:315px; overflow: hidden; margin: auto;">'
	Str+='<TABLE cellSpacing="0" cellPadding="0" width="83" border="0" id="tblBiblRightMainStories">'
	for(I=0;I<SectionsArticlesCount;I++)
	{
		Str+='<TR>'
		Str+='<TD align="center" class="imgBrd">'
		if (XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='MainStory14']")[I]!=null)
		{
			if (I==0)
				Str+='<IMG id="imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'" style="filter:alpha(opacity=70);" onclick="CurrentSelectedArticleGuid=\''+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'\';ChangeSelectedRightArticles()" style="cursor:pointer;" src="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='SubStory1']")[0][TextNodeDefine]+'"/>'
			else
				Str+='<IMG id="imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'" onclick="CurrentSelectedArticleGuid=\''+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'\';ChangeSelectedRightArticles()" style="cursor:pointer;" src="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='SubStory1']")[0][TextNodeDefine]+'"/>'
		}	
		else if(XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='SubStory1']")[I]!=null)
		{
			if (I==0)
				Str+='<IMG id="imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'" style="filter:alpha(opacity=70);" onclick="CurrentSelectedArticleGuid=\''+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'\';ChangeSelectedRightArticles()" style="cursor:pointer;" src="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='SubStory1']")[I][TextNodeDefine]+'"/>'
			else
				Str+='<IMG id="imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'" onclick="CurrentSelectedArticleGuid=\''+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[I][TextNodeDefine]+'\';ChangeSelectedRightArticles()" style="cursor:pointer;" src="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/img[@Type='SubStory1']")[I][TextNodeDefine]+'"/>'
		}
			
		Str+='</TD>'
		Str+='</TR>'
		Str+='<TR>'
		Str+='<TD height="9"></TD>'
		Str+='</TR>'
	}
	Str+='</td></tr></TABLE>'
	Str+='</div>'	
	Str+='<tr><TD height="12"></TD></tr>'
	Str+='<TR>'
	Str+='<TD class="smlArrowBg" align="center" height="30">'
	Str+='<TABLE cellSpacing="0" cellPadding="0" width="66" border="0">'
	
	Str+='<tr>'
	Str+='<td align="left">'
	Str+='<IMG height="22" src="/Studies/images/smlDownArrow.jpg" id="imgRightScrollingDown" onclick="ScrollingDownRightMainStories(\'divBiblRightMainStories\')" style="cursor:pointer" width="29" />'
	Str+='</td>'
	Str+='<td align="right">'
	Str+='<IMG height="22" src="/Studies/images/smlUparrow-D.jpg" id="imgRightScrollingUp" onclick="ScrollingUpRightMainStories(\'divBiblRightMainStories\')" width="29" />'
	Str+='</td>'
	Str+='</tr>'
	Str+='</TABLE>'
	Str+='</TD>'
	Str+='</TR>'
	Str+='</TABLE>'
								
	document.getElementById('tdRightBibloMainStories').innerHTML=Str
	ChangeSelectedRightArticles()
	if (!PausTimer && SectionsCount>1)
	{
		window.clearTimeout(TimerObj)
		TimerObj=window.setTimeout("ScrollingTimerSections()",10000)
	}
	if (SectionsCount<=4)
	{
		document.getElementById('imgLeftScrollingDown').src='/Studies/Images/smlDownArrow-D.jpg'
		document.getElementById('imgLeftScrollingDown').style.cursor='default'
	}
	if (SectionsArticlesCount<=4)
	{
		document.getElementById('imgRightScrollingDown').src='/Studies/Images/smlDownArrow-D.jpg'
		document.getElementById('imgRightScrollingDown').style.cursor='default'
	}
}
function ChangeSelectedRightArticles()
{
	DisablehighLight()
	DisablehighLightArticles()
	DisappearMainImage('tblMainStoryArticleInfo',100)
}
function DisablehighLight()
{
	try
	{
		for(var iIndex=0; iIndex<=SectionsCount-1; iIndex++)
		{
			if (XmlMainStories.selectNodes("//Root/Items")[iIndex].attributes.getNamedItem("SectionId").value!=CurrentSectionId)
				document.getElementById('imgSmallMainImage'+XmlMainStories.selectNodes("//Root/Items")[iIndex].attributes.getNamedItem("SectionId").value).style.filter='Alpha(Opacity=100)'
			else
				document.getElementById('imgSmallMainImage'+XmlMainStories.selectNodes("//Root/Items")[iIndex].attributes.getNamedItem("SectionId").value).style.filter='Alpha(Opacity=70)'
		}
	}
	catch(err)
	{
		
	}
}
function DisablehighLightArticles()
{
	try
	{
		for(var iIndex=0; iIndex<=SectionsArticlesCount-1; iIndex++)
		{
			if (XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[iIndex][TextNodeDefine]!=CurrentSelectedArticleGuid)
				document.getElementById('imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[iIndex][TextNodeDefine]).style.filter='Alpha(Opacity=100)'
			else
				document.getElementById('imgSmallMainImageArticle'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item/Guid")[iIndex][TextNodeDefine]).style.filter='Alpha(Opacity=70)'
		}
	}
	catch(err)
	{
		
	}
}
function DisappearMainImage(Obj,Opacity)
{
	if (Opacity>=0)
	{
		document.getElementById(Obj).style.filter='Alpha(Opacity='+Opacity+')'
		window.setTimeout("DisappearMainImage('"+Obj+"',"+eval(eval(Opacity)-eval(15))+")",1)
	}
	else
	{
		FillMainImageAndSummary()
		ShowMainImage(Obj,1)
	}
}

function ShowMainImage(Obj,Opacity)
{
	if (Opacity<=100)
	{
		document.getElementById(Obj).style.filter='Alpha(Opacity='+Opacity+')'
		window.setTimeout("ShowMainImage('"+Obj+"',"+eval(eval(Opacity)+eval(15))+")",1)
	}
}
function FillMainImageAndSummary()
{
	document.getElementById('tdBibloMainStories').innerHTML='<a href="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item[Guid='"+CurrentSelectedArticleGuid+"']")[0].selectSingleNode("url")[TextNodeDefine]+'"><IMG height="248" border="0" src="'+XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item[Guid='"+CurrentSelectedArticleGuid+"']/img[@Type='JazeeraMainImg']")[0][TextNodeDefine]+'" id="" width="348" /></a>'
	document.getElementById('tdBibloSummaryText').innerHTML=XmlMainStories.selectNodes("//Root/Items[@SectionId='"+CurrentSectionId+"']/item[Guid='"+CurrentSelectedArticleGuid+"']")[0].selectSingleNode("body")[TextNodeDefine]
}
