/*Created by Igor Krasnyi GettyImages*/
/* PURPOSE: Gallery page navigation methods */
function doNothing()
{return;}

function rollNavImg(srcElement, rollImage)
{
	
	var srcID;
	if(srcElement == null || rollImage == null)
		return;
	var navigationStory = document.getElementById("navStory");
	var navigationImage = document.getElementById("navImage");

	srcID = srcElement.getAttribute("id");	

	if(!supportDOM)
	{
		if(srcID=="arrowSlPgLeft" || srcID=="arrowSlPgRight")
		{
			if(rollImage)
			{
				if(srcElement.src.indexOf("roll")==-1)
				{
					//srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/off/, "roll"));
					srcElement.src = srcElement.src.replace(/off/, "roll");	
				}				
				else
				{
					//srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/roll/, "off"));	
					srcElement.src = srcElement.src.replace(/roll/, "off");	
				}									
			}	
		}
		else
		{
			if(srcElement.src.indexOf("on")==-1 && rollImage)
			{
				//srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/off/, "on"));
				srcElement.src = srcElement.src.replace(/off/, "on");
				srcElement.style.cursor="hand";
				//srcElement.parentElement.style.cursor="hand";				
			}	
			else
			{
				//srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/on/, "off"));
				srcElement.src = srcElement.src.replace(/on/, "off");
				srcElement.style.cursor="default";
				//srcElement.parentElement.style.cursor="default";						
			}
		}
	}	
	else
	{
		if((srcID=="arrowSlLeft" && slideIndex>1) || (srcID=="arrowStLeft" && storyIndex>1) || (srcID=="arrowSlRight" && slideIndex<slideCount) || (srcID=="arrowStRight" && storyIndex<storyCount))
		{
			if(srcElement.getAttribute("src").indexOf("on")==-1)
				srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/off/, "on"));
			else
				srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/on/, "off"));
				
			srcElement.style.cursor="hand";
			//srcElement.parentElement.style.cursor="hand";				
		}
		else if((srcID=="arrowSlLeft" && slideIndex==1) || (srcID=="arrowSlRight" && slideIndex==slideCount) || (srcID=="arrowStLeft" && storyIndex==1) || (srcID=="arrowStRight" && storyIndex==storyCount))
		{
			srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/on/, "off"));
			srcElement.style.cursor="default";
			//srcElement.parentElement.style.cursor="default";	
		}
		else if((srcID=="arrowSlPgRight" && slideIndex>0 && slideIndex<6) || (srcID=="arrowSlPgLeft" && slideIndex>5 && slideIndex<=slideCount))
		{
			if(srcElement.getAttribute("src").indexOf("roll")==-1)
				srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/off/, "roll"));
			else
				srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/roll/, "off"));	
		}
		else if((srcID=="arrowSlPgLeft" && slideIndex>0 && slideIndex<6) || (srcID=="arrowSlPgRight" && slideIndex>5 && slideIndex<=slideCount))
			srcElement.setAttribute("src", srcElement.getAttribute("src").replace(/roll/, "on").replace(/off/, "on"));	
	}
	
	if(srcElement.src.indexOf("off")==-1)
	{
		if(srcID=="arrowSlLeft" || srcID=="arrowSlRight")
			navigationImage.src = navigationImage.src.replace(/image.gif/, "image_roll.gif");
		else if(srcID=="arrowStLeft" || srcID=="arrowStRight")
			navigationStory.src = navigationStory.src.replace(/story.gif/, "story_roll.gif");
	}
	else
	{			
		if(srcID=="arrowSlLeft" || srcID=="arrowSlRight")
			navigationImage.src = navigationImage.src.replace(/image_roll.gif/, "image.gif");
			//navigationImage.setAttribute("src", navigationImage.getAttribute("src").replace(/image_roll.gif/, "image.gif"));
		else if(srcID=="arrowStLeft" || srcID=="arrowStRight")
			navigationStory.src = navigationStory.src.replace(/story_roll.gif/, "story.gif");	
			//navigationStory.setAttribute("src", navigationStory.getAttribute("src").replace(/story_roll.gif/, "story.gif"));
	}

	return;
}

function rollImageThumb(imgID, activeImgID, sSrc)
{
	var objImg;
	if(document.images && imgID!=activeImgID){
		objImg = eval(document.images[imgID]);
		objImg.src = sSrc;
	}
	return;
}

if(supportDOM)
{
//Initialize the page variables
var slideStartIndex = 1;
var slideIndex = 1;
var storyIndex = 1;
var slideCount;
var storyCount;

var viewMoreIms = document.getElementById("viewMoreImages");
var arrowStLeft = document.getElementById("arrowStLeft");
var arrowStRight = document.getElementById("arrowStRight");
var arrowSlLeft = document.getElementById("arrowSlLeft");
var arrowSlRight = document.getElementById("arrowSlRight");
var arrowSlPgLeft = document.getElementById("arrowSlPgLeft");
var arrowSlPgRight = document.getElementById("arrowSlPgRight");
	        	        	        	        	        
var storyNav = document.getElementById("stNav");
var slideNav = document.getElementById("slNav");
var slideLink = document.getElementById("slLink");	   
var slideEvent = document.getElementById("slEvent");	        
var storyHeadline = document.getElementById("stHeadline");
var storyDescr = document.getElementById("stDescrp");	
var storySeeMore = document.getElementById("stSeeMore");	 	               
var slideImage = document.getElementById("slImage");	
var slideCredit = document.getElementById("slCredit");
var thumbsContainer = document.getElementById("thumbsContainer");

var oStories;
var oSlides;
var currentBrowser;
var oXmlDom;
var storyRoot;

try
{
	currentBrowser = new Browser();
	oXmlDom;
	storyRoot;

	var sectionQuery;

	//currentBrowser.isSF = true;
	//currentBrowser.isNS = false;
	//currentBrowser.isIE = false;


	if(document.location.search.indexOf("gallery=") != -1)
	{	
		var sectionQuery = document.location.search;
		var startIndex = sectionQuery.indexOf("gallery=")+8;

		sectionQuery = sectionQuery.substr(startIndex, 2)
		sectionQuery = sectionQuery.replace(/&/, "");
		storyIndex = parseInt(sectionQuery);
	}
	else
		storyIndex =1;

	if(!currentBrowser.isSF)
	{
		if(currentBrowser.isNS)
		{

			oXmlDom = document.implementation.createDocument("","",null);
			Element.prototype.selectNodes = function (sXPath) {
				var oEvaluator = new XPathEvaluator();
				var oResult = oEvaluator.evaluate(sXPath, oXmlDom.documentElement, null, 
													XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
			
				var aNodes = new Array;
			    
				if (oResult != null) {
					var oElement = oResult.iterateNext();
					while(oElement) {
						aNodes.push(oElement);
						oElement = oResult.iterateNext();
					}
				}
			    
				return aNodes;
			
			};	
			Element.prototype.selectSingleNode = function (sXPath) {
				var oEvaluator = new XPathEvaluator();
				var oResult = oEvaluator.evaluate(sXPath, oXmlDom.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

				if (oResult != null) {
					return oResult.singleNodeValue;
				} else {
					return null;
				}              
			};
		}
		else if(currentBrowser.isIE)
			oXmlDom = createXMLDOM(); 	    

		oXmlDom.async = false;
		oXmlDom.resolveExternals = false;
		oXmlDom.load(xmlFileFullPath); 

		storyRoot = oXmlDom.documentElement;
	}
	else if(currentBrowser.isSF)
	{
		var xmlElement = initXmlDoc(xmlFileFullPath);
		storyRoot = new XpathEvaluatorLight(xmlElement);
	} 

	oStories = storyRoot.selectNodes("//feature");
	storyCount = oStories.length;
	oSlides = storyRoot.selectNodes("//feature[@id='"+storyIndex+"']/slide");
	slideCount = oSlides.length; 
}
catch (oError)
{
	if(debugMode)
		alert("Initialisation error: " + oError.description);   
	else
		redirectOnError();
}
}



// Determine browser and version.
// Browser recognition class
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.isSF    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape/6";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i-1 + s.length));
    return;
  }
  
  s = "Netscape/7";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i-1 + s.length));
    return;
  }  
  
  s = "Firefox/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }  
  
  s = "Safari/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isSF = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }    
  
  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

// Returns a XML Document for ActiveX compotible browsers like IE
function createXMLDOM() {

    var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                            "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                            "Microsoft.XmlDom"];
                            
    for (var i=0; i < arrSignatures.length; i++) {
        try {
        
            var oXmlDom = new ActiveXObject(arrSignatures[i]);
            
            return oXmlDom;
        
        } catch (oError) {
            //ignore
        }
    }              
    
    throw new Error("MSXML not installed on your system.");           
}   
 

// Change a slide number. slideArrow sign points to navigation direction and slideArrow # assigns increment/decrement for each iteration 
function changeSlide(slideArrow) {
	try
	{    
		var maxSlideStartIndex = Math.floor(Math.abs((slideCount-1)/5))*5+1;
		slideStartIndex += (slideArrow*5);
		slideIndex += slideArrow;

		if(slideIndex < 1)
		{
			slideIndex = 1;
			refreshNavImg(slideStartIndex);	
			return;
		}
		else if(slideIndex > slideCount)
		{
			slideIndex = slideCount;
			refreshNavImg(slideStartIndex);		
			return;
		}
			
		if(slideStartIndex < 1)
			slideStartIndex = 1;
		else if(slideStartIndex > maxSlideStartIndex)
			slideStartIndex = maxSlideStartIndex;

		if((slideIndex - slideStartIndex) > 4)
			slideStartIndex = 6;
		else if((slideIndex - slideStartIndex) < 0)
			slideStartIndex = 1;	
					
		refreshNavImg(slideStartIndex);		
		populateSlideThumbs(slideStartIndex);
		populateSlide(slideIndex);
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Slide navigation error: " + oError.description);   
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the slide navigation.");           
}

// Change a slide page number. slideArrow sign points to navigation direction and slideArrow # assigns increment/decrement for each iteration 
function changeSlidePage(slideArrow) {

	try
	{    
		var maxSlideStartIndex = Math.floor(Math.abs((slideCount-1)/slideArrow))*5+1;
		slideStartIndex += slideArrow;
		if((slideIndex - slideStartIndex) < 0)
			slideIndex = 6;
		else if((slideIndex - slideStartIndex) > 4)
			slideIndex = 1;			
		if(slideStartIndex < 1)
		{
			slideStartIndex = 1;
			return;
		}
		else if(slideStartIndex > maxSlideStartIndex)
		{
			slideStartIndex = maxSlideStartIndex;
			return;
		}
		
		refreshNavImg(slideStartIndex);
	
		populateSlideThumbs(slideStartIndex);
		populateSlide(slideIndex);
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Slide page navigation error: " + oError.description);   
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the slide navigation.");           
}  

function refreshNavImg(slideStartIndex)
{
	try
	{ 	

		if(slideStartIndex == 1)
		{
			arrowSlPgLeft.setAttribute("src", "/YIF2006/source/images/gallery/ui/1-5_on.gif");
			arrowSlPgRight.setAttribute("src", "/YIF2006/source/images/gallery/ui/6-10_off.gif");		
			viewMoreIms.setAttribute("src", "/YIF2006/source/images/spacer.gif");
			viewMoreIms.setAttribute("height", "0");
			viewMoreIms.setAttribute("width", "0");						
		}
		else if(slideStartIndex == 6)
		{
			arrowSlPgLeft.setAttribute("src", "/YIF2006/source/images/gallery/ui/1-5_off.gif");
			arrowSlPgRight.setAttribute("src", "/YIF2006/source/images/gallery/ui/6-10_on.gif");
			viewMoreIms.setAttribute("src", imgLocGalleryRoot + "viewmore_off.gif");
			viewMoreIms.setAttribute("height", "20");
			viewMoreIms.setAttribute("width", "146");									
		}
	
		if(slideIndex == 1)
			arrowSlLeft.setAttribute("src", "/YIF2006/source/images/gallery/ui/arrow_thumb_lft_off.gif");
		else if(slideIndex == slideCount)
			arrowSlRight.setAttribute("src", "/YIF2006/source/images/gallery/ui/arrow_thumb_rt_off.gif");

		if(storyIndex == 1)
		{
			arrowStLeft.setAttribute("src", "/YIF2006/source/images/gallery/ui/arrow_lft_off.gif");
			arrowStLeft.setAttribute("alt", "");	
			arrowStRight.setAttribute("alt", (storyIndex+1) + "/" + storyCount);	
			arrowStLeft.setAttribute("title", "");	
			arrowStRight.setAttribute("title", (storyIndex+1) + "/" + storyCount);			
		}
		else if(storyIndex == storyCount)
		{
			arrowStRight.setAttribute("src", "/YIF2006/source/images/gallery/ui/arrow_rt_off.gif");
			arrowStLeft.setAttribute("alt", (storyIndex-1) + "/" + storyCount);	
			arrowStRight.setAttribute("alt", "");	
			arrowStLeft.setAttribute("title", (storyIndex-1) + "/" + storyCount);	
			arrowStRight.setAttribute("title", "");				
		}
		else
		{
			arrowStLeft.setAttribute("alt", (storyIndex-1) + "/" + storyCount);	
			arrowStRight.setAttribute("alt", (storyIndex+1) + "/" + storyCount);	
			arrowStLeft.setAttribute("title", (storyIndex-1) + "/" + storyCount);	
			arrowStRight.setAttribute("title", (storyIndex+1) + "/" + storyCount);		
		}
			
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Navigation images refresh error: " + oError.description);  
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the navigation images refresh.");    	
}     

// Populates slides' table with a story thumbs. slideStartIndex points to start index of thumbs' set
function populateSlideThumbs(slideStartIndex) {
	try
	{      
		// Declare variables and create the table.
		var oTable = document.createElement("TABLE");
		var oCellLink;
		var oCellImage;
		var oRow, oCell;
		var i;
		var oThumb;
		var oExt;
		var thumbFullPath;
		var oThumbs = storyRoot.selectNodes("//feature[@id='"+storyIndex+"']/slide");
		slideCount = oSlides.length; 
					
		//if(slideStartIndex > slideCount-5)
		//	return;
		// Set the table's attributes.
		oTable.setAttribute("border","0");
		oTable.setAttribute("cellSpacing","10");	
		oTable.setAttribute("cellPadding","0");			
		oTable.setAttribute("bgcolor","#112244");

		// Create and insert rows and cells into the second body.
		oRow = document.createElement("TR");
		oTable.appendChild(oRow);

		for (i=(slideStartIndex - 1); i < (slideStartIndex + 4); i++)
		{
			oCell = document.createElement("TD");

			if(i < slideCount)
			{
				oCellLink = document.createElement("A");			
				oCellImage = document.createElement("IMG");

				oThumb = storyRoot.selectSingleNode("//feature[@id='"+storyIndex+"']/slide[@id='"+(i+1)+"']/image");
				oExt = storyRoot.selectSingleNode("//feature[@id='"+storyIndex+"']/slide[@id='"+(i+1)+"']/image/@ext");
				
				if(oThumb != null)
				{
					if(currentBrowser.isIE)
					{
						if(slideIndex == (i+1))
							thumbFullPath = imgSrcSectionRoot + oThumb.text + "_on" + oExt.text;
						else
							thumbFullPath = imgSrcSectionRoot + oThumb.text + "_off" + oExt.text;						
					}
					else if(currentBrowser.isNS)	
					{
						if(slideIndex == (i+1))					
							thumbFullPath = imgSrcSectionRoot + oThumb.textContent + "_on" + oExt.textContent;
						else
							thumbFullPath = imgSrcSectionRoot + oThumb.textContent + "_off" + oExt.textContent;						
					}
					else if(currentBrowser.isSF)
					{
						//alert(imgSrcSectionRoot + oThumb.firstChild.nodeValue + "_on" + oExt);
						if(slideIndex == (i+1))
							thumbFullPath = imgSrcSectionRoot + oThumb.firstChild.nodeValue + "_on" + oExt;
						else
							thumbFullPath = imgSrcSectionRoot + oThumb.firstChild.nodeValue + "_off" + oExt;						
					}									
				}
				
				oCellImage.setAttribute("src",thumbFullPath);
				oCellImage.setAttribute("id","t" + (i+1));
				oCellImage.setAttribute("onmouseover", "javascript:rollImageThumb('"+oCellImage.getAttribute("id")+"', 't"+slideIndex+"', '"+thumbFullPath.replace(/off/, "on")+"')");
				oCellImage.setAttribute("onmouseout", "javascript:rollImageThumb('"+oCellImage.getAttribute("id")+"', 't"+slideIndex+"', '"+thumbFullPath.replace(/on/, "off")+"')");
						
				oCellImage.setAttribute("height","60");			
				oCellImage.setAttribute("width","67");		
				oCellImage.setAttribute("border","0");							
				oCellLink.setAttribute("href","javascript:populateSlide(" + (i+1) + ");");
				oCellLink.appendChild(oCellImage);
				oCell.appendChild(oCellLink);
			}
			//else
			//	oCell.appendChild(document.createTextNode(""));	
				
			oCell.setAttribute("height","60");			
			oCell.setAttribute("width","67");						

			oRow.appendChild(oCell);
		}

		// Insert the table into the document tree.
		if(currentBrowser.isNS || currentBrowser.isSF)
		{
			if(thumbsContainer.firstChild != null)
				thumbsContainer.replaceChild(oTable, thumbsContainer.firstChild);
			else
				thumbsContainer.appendChild(oTable);				
		}
		else if(currentBrowser.isIE)
			thumbsContainer.innerHTML = oTable.outerHTML;

		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Thumbs table population error:" + oError.description); 
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the thumbs population.");           
} 

function changeStory(storyArrow) {

	try
	{ 
		var oLinkStLeft;
		var oLinkStRight;		
		storyIndex += storyArrow;	
		slideStartIndex = 1;
	
		if(storyIndex < 1)
		{
			storyIndex = 1;
			slideIndex = 1;
			refreshNavImg(slideStartIndex)
			return;
		}
		else if(storyIndex > storyCount)
		{
			storyIndex = storyCount;
			slideIndex = 1;
			refreshNavImg(slideStartIndex)
			return;
		}

		
		populateStory(storyIndex);

		refreshNavImg(slideStartIndex);
			
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Story navigation error:" + oError.description);  
		else
			redirectOnError();
			//window.location.href="/YIF2006/source/gallery.aspx"+document.location.search.substring(1,document.location.search.indexOf("gallery=")-1)+"&gallery="+storyIndex+"&slide="+slideIndex+"&stslide="+slideStartIndex;
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the story navigation.");           
}  

function populateStory(currStoryIndex) {
	try
	{      
		var headlineContent;

		var oHeadline = storyRoot.selectSingleNode("//feature[@id='" + currStoryIndex + "']/headline");
		var oDescr =	storyRoot.selectSingleNode("//feature[@id='" + currStoryIndex + "']/descrp");
		var oEventLink = storyRoot.selectSingleNode("//features");//@imgdetlink//@exclusivelink");

		var oHeadlineImage;
		if(currStoryIndex == null)
			currStoryIndex = storyIndex; 
		else if(currStoryIndex == 0)
			currStoryIndex = 0		
		if(slideIndex == null || slideIndex == 0)
			slideIndex = 1; 
	
		if(currentBrowser.isIE)
		{
			headlineContent = oHeadline.text.toLowerCase();
			if(headlineContent.indexOf(".jpg") != -1 || headlineContent.indexOf(".gif") != -1)
				storyHeadline.innerHTML	= "<img border='0' src='" + imgLocStoriesRoot + headlineContent + "' width='215' />";	
			else
				storyHeadline.innerHTML	= oHeadline.text;	

			//storyDescr.innerHTML	= oDescr.xml;
			replaceXsltFormatTags(oDescr, storyDescr);				
		}
		else if(currentBrowser.isNS)	
		{	
			headlineContent = oHeadline.textContent.toLowerCase();
			if(headlineContent.indexOf(".jpg") != -1 || headlineContent.indexOf(".gif") != -1)
			{
				oHeadlineImage = document.createElement("IMG");
				oHeadlineImage.setAttribute("src",imgLocStoriesRoot + headlineContent);
				oHeadlineImage.setAttribute("width","215");		
				//oHeadlineImage.setAttribute("height","30");					
				oHeadlineImage.setAttribute("border","0");
				storyHeadline.textContent = "";
				if(storyHeadline.firstChild != null)							
					storyHeadline.replaceChild(oHeadlineImage, storyHeadline.firstChild);
				else
					storyHeadline.appendChild(oHeadlineImage);
			}
			else
				storyHeadline.textContent	= oHeadline.textContent;	
				
			replaceXsltFormatTags(oDescr, storyDescr);
					
		}
		else if(currentBrowser.isSF)	
		{	
			headlineContent = oHeadline.firstChild.nodeValue.toString().toLowerCase();
			if(headlineContent.indexOf(".jpg") != -1 || headlineContent.indexOf(".gif") != -1)
			{
				oHeadlineImage = document.createElement("IMG");
				oHeadlineImage.setAttribute("src",imgLocStoriesRoot + headlineContent);
				oHeadlineImage.setAttribute("width","215");		
				//oHeadlineImage.setAttribute("height","30");					
				oHeadlineImage.setAttribute("border","0");
				storyHeadline.firstChild.nodeValue = "";
				if(storyHeadline.firstChild != null)							
					storyHeadline.replaceChild(oHeadlineImage, storyHeadline.firstChild);
				else
					storyHeadline.appendChild(oHeadlineImage);
			}
			else
				storyHeadline.firstChild.nodeValue	= oHeadline.firstChild.nodeValue;	

			replaceXsltFormatTags(oDescr, storyDescr);
		}		
		
		if(oHeadline.getAttribute("parent") == 'true')
			storySeeMore.setAttribute("href", oEventLink.getAttribute("parenteventlink") + oHeadline.getAttribute("eventid"));	
		else if(oHeadline.getAttribute("parent") == 'false')
			storySeeMore.setAttribute("href", oEventLink.getAttribute("eventlink") + oHeadline.getAttribute("eventid"));	
		else
			storySeeMore.setAttribute("href", oEventLink.getAttribute("eventlink") + oHeadline.getAttribute("eventid"));	
							
		oSlides = storyRoot.selectNodes("//feature[@id='" + currStoryIndex + "']/slide");
        slideCount = oSlides.length;
        
		populateSlide(1);
		populateSlideThumbs(1);
		
		//sendTrackingCode();
		
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Story population error:" + oError.description);  
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the story navigation.");           
}    

function populateSlide(currSlideIndex) {
	try
	{      
		if(currSlideIndex == null)
			currSlideIndex = slideIndex; 
		else if(currSlideIndex == 0)
			currSlideIndex = 1;
		//else
		//	slideIndex = currSlideIndex;
			 			
		if(storyIndex == null || storyIndex == 0)
			storyIndex = 1; 

		var oImage = storyRoot.selectSingleNode("//feature[@id='" + storyIndex + "']/slide[@id='" + currSlideIndex + "']/image");
		var oExt = storyRoot.selectSingleNode("//feature[@id='"+storyIndex+"']/slide[@id='" + currSlideIndex + "']/image/@ext");
		var oCredit = storyRoot.selectSingleNode("//feature[@id='" + storyIndex + "']/slide[@id='" + currSlideIndex + "']/credit");
		var oEvent = storyRoot.selectSingleNode("//feature[@id='" + storyIndex + "']/slide[@id='" + currSlideIndex + "']");
		var oImgLink = storyRoot.selectSingleNode("//features");//@imgdetlink//@exclusivelink");

		replaceThumb(currSlideIndex);
	
		if(currentBrowser.isIE)
		{
			slideImage.setAttribute("src", imgSrcSectionRoot + oImage.text + oExt.text);			
			//slideCredit.innerHTML = oCredit.xml;	
			replaceXsltFormatTags(oCredit, slideCredit);
		}
		else if(currentBrowser.isNS)	
		{				
			slideImage.setAttribute("src", imgSrcSectionRoot + oImage.textContent + oExt.textContent);	
			replaceXsltFormatTags(oCredit, slideCredit);		
		}
		else if(currentBrowser.isSF)
		{
			//safari bug. Clear dimensions with new image src. 
			slideImage.src = "/YIF2006/source/images/spacer.gif";	
			slideImage.src = imgSrcSectionRoot + oImage.firstChild.nodeValue + oExt;	
			replaceXsltFormatTags(oCredit, slideCredit);				
		}
		if(oEvent.getAttribute("exclusive") == "0")	
		{		
			slideLink.setAttribute("href", (oImgLink.getAttribute("imgdetlink") + oEvent.getAttribute("eventid")));		
			slideEvent.setAttribute("href", (oImgLink.getAttribute("imgdetlink") + oEvent.getAttribute("eventid")));
		}
		else 
		{
			slideLink.setAttribute("href", oImgLink.getAttribute("exclusivelink"));
			slideEvent.setAttribute("href", oImgLink.getAttribute("exclusivelink"));
		}
		sendTrackingCode();
		
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Slide population error:" + oError.description); 
		else
			redirectOnError();
	}
    
    if(debugMode)
		throw new Error("Some errors were occured through the slide population.");           
}  

function replaceThumb(currSlideIndex) {
	try
	{  
		var thumbImage;

		slideIndex = currSlideIndex;

		for(i=1; i<=slideCount; i++)	
		{	
			thumbImage = document.getElementById("t" + i);	
			if(thumbImage != null)
			{
				if(currentBrowser.isNS || currentBrowser.isSF)
				{
					if(i == currSlideIndex)
						thumbImage.setAttribute("src", thumbImage.getAttribute("src").replace(/off/, "on"));
					else
						thumbImage.setAttribute("src", thumbImage.getAttribute("src").replace(/on/, "off"));
					thumbImage.setAttribute("onmouseover", "javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/off/, "on")+"');");
					thumbImage.setAttribute("onmouseout", "javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/on/, "off")+"');");
				}
				else if(currentBrowser.isIE)
				{
					if(i == currSlideIndex)				
						thumbImage.outerHTML = "<img border='0' height='60' width='67' id='"+thumbImage.getAttribute("id")+"' src='"+thumbImage.getAttribute("src").replace(/off/, "on")+"' onmouseover=\"javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/off/, "on")+"');\" onmouseout=\"javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/on/, "off")+"');\" />";
					else
						thumbImage.outerHTML = "<img border='0' height='60' width='67' id='"+thumbImage.getAttribute("id")+"' src='"+thumbImage.getAttribute("src").replace(/on/, "off")+"' onmouseover=\"javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/off/, "on")+"');\" onmouseout=\"javascript:rollImageThumb('"+thumbImage.getAttribute("id")+"', 't"+currSlideIndex+"', '"+thumbImage.getAttribute("src").replace(/on/, "off")+"');\" />";
				}
			}
		}

		//if(currentBrowser.isIE)
			//slideNav.innerText	= currSlideIndex + "/" + slideCount;	
		//else if(currentBrowser.isNS)	
			//slideNav.textContent	= currSlideIndex + "/" + slideCount;
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Replace thumb error:" + oError.description);  
		else
			redirectOnError();
	}
    if(debugMode)
		throw new Error("Some errors were occured through the thumb replacement.");           
}

function replaceXsltFormatTags(srcElement, targetElement)
{
	try
	{
		if(currentBrowser.isIE)
		{
			var replacedXML = srcElement.xml;
			replacedXML = replacedXML.replace(/italic>/g, "i>");
			replacedXML = replacedXML.replace(/bold>/g, "b>");
			replacedXML = replacedXML.replace(/underlive>/g, "u>");				
			targetElement.innerHTML = replacedXML;
		}
		else if(currentBrowser.isNS || currentBrowser.isSF)	
		{
			//clear all child nodes	
			while(targetElement.childNodes.length>0)
				targetElement.removeChild(targetElement.firstChild); 	
			
			var oNode;
			for(i=0; i<srcElement.childNodes.length; i++)
			{
				//alert(srcElement.childNodes[i].nodeName);
				if(srcElement.childNodes[i].nodeType==1)
				{
					if(srcElement.childNodes[i].nodeName=="italic")
						oNode=document.createElement("I");
					else if(srcElement.childNodes[i].nodeName.toLowerCase()=="bold")
						oNode=document.createElement("B");
					else if(srcElement.childNodes[i].nodeName.toLowerCase()=="underline")
						oNode=document.createElement("U");
					else 
						oNode = srcElement.childNodes[i].cloneNode(false);												
					oNode.appendChild(srcElement.childNodes[i].firstChild.cloneNode(true));
					targetElement.appendChild(oNode);
				}
				else if(srcElement.childNodes[i].nodeType==3)
					targetElement.appendChild(srcElement.childNodes[i].cloneNode(true));
			}
		}
		return;
	}
	catch (oError)
	{
		if(debugMode)
			alert("Replace XSLT format tags error:" + oError.description);  
		else
			redirectOnError();
	}
    if(debugMode)
		throw new Error("Some errors were occured through the XSLT tags replacement."); 	
}

function redirectOnError()
{
	var sectionQuery;
	if(document.location.search.indexOf("gallery=") != -1)
		sectionQuery = document.location.search.substring(1,document.location.search.indexOf("gallery=")-1);
	else
		sectionQuery = document.location.search;
		
	if(sectionQuery.indexOf("?")==-1)
		sectionQuery = "?"+sectionQuery;
	else
		sectionQuery = "?section=nws";	
		
	window.location.href="/YIF2006/source/gallery.aspx"+sectionQuery+"&gallery="+storyIndex+"&slide="+slideIndex+"&stslide="+slideStartIndex+"&err=true";
}			          


function sendTrackingCode()
{
	//s.channel="YIF2006";
	var trackingCode = "Gallery_";
	if(document.location.search.indexOf("section=") != -1)
	{	
		var currentSection = document.location.search;
		var startIndex = currentSection.indexOf("section=")+8;

		currentSection = currentSection.substr(startIndex, 3)
		currentSection = currentSection.replace(/&/, "");
	}
	else
		currentSection = "nws";

	trackingCode+=(currentSection+"_");

	if(storyIndex<10)
		trackingCode+=("0"+storyIndex+"_");
	else
		trackingCode+=(""+storyIndex+"_");
			
	if(slideIndex<10)
		trackingCode+=("0"+slideIndex+"_");
	else
		trackingCode+=(""+slideIndex+"_");

	if(curLang=="")
		curLang="en-us";
	trackingCode+=curLang;
	

	s.pageName=trackingCode;

	var s_code=s.t();
	if(s_code)
		document.write(s_code);
		
	return;
}
