
// pic Gallery colours
var currentPicColor = '#0099ff';
var unselectedColor = '#77338d';
var deadLinkColor = '#fff';

//   ---------------------------------
function Navselect(navtype){/* navtype defines which nav this refers to */

	this.navtype=navtype;

	this.highlightCurrentTab();	

	this.findTabOnPage();

	this.makeChangesToTab();

}



Navselect.prototype.highlightCurrentTab = function() {

	this.ULs=document.getElementsByTagName("ul");

	this.pageurl = document.location.href.split("?")[0]; /* remove any query string or # on url */

	if(this.pageurl.charAt(this.pageurl.length-1)=="#")this.pageurl = document.location.href.split("#")[0];

}



Navselect.prototype.findTabOnPage = function() {

	var UL, LIs, LI, i=j= -1;

	this.linksInList=[];

	while( UL=this.ULs[++i] ){/* Loop stops when ULs[n]--> null */

		if(UL.id==this.navtype){

			this.navUL=UL;

			j = -1;

			LIs=UL.getElementsByTagName("li");

			while( LI=LIs[++j] ){/* loop through hrefs in li to see which tab matches this url */

				this.linksInList[j]=LI.childNodes.item(0);/* make array of all the links on the list */

				if(LI.childNodes.item(0)==this.pageurl){

					this.tabToHighlight=LI;/* selected LI that matches page location */

					this.onThisPage=j;/* numerical value for this list item */

				}

			}

			this.totalNumberOfLinks=j;

		}

	} 

}



Navselect.prototype.makeChangesToTab=function(){/*  Defferent changes to LI depending on navtype */ 

	if(this.navtype=="tabnav"){// TABNAV

		this.tabToHighlight.style.background="url(/sol/shared/img/v3/tabs/tab_bg104o.gif) #eee";

		var thisTagTxt=this.tabToHighlight.firstChild.firstChild.data;/* Remove Link and replace with text */

		var myTextNode=document.createTextNode(thisTagTxt);

		this.tabToHighlight.removeChild(this.tabToHighlight.firstChild);

		this.tabToHighlight.appendChild(myTextNode);

	}else if(this.navtype=="galnav"){// GALNAV

		this.tabToHighlight.style.background="#990000";

		var thisTagTxt=this.tabToHighlight.firstChild.firstChild.data;/* Remove Link and replace with text */

		var myTextNode=document.createTextNode(thisTagTxt);

		this.tabToHighlight.removeChild(this.tabToHighlight.firstChild);

		this.tabToHighlight.appendChild(myTextNode);

		this.reSizeGalNav();

		this.backNext();

	}

}

			

Navselect.prototype.reSizeGalNav = function(){

	if(this.totalNumberOfLinks<18) {

		var numsWidth=(this.totalNumberOfLinks*24);

		this.navUL.style.width=numsWidth;

	}

}



Navselect.prototype.backNext = function(){

	//alert(this.onThisPage+" :::::::::::: "+this.totalNumberOfLinks);//

	if(this.onThisPage==0){

		var bakString="<b>Back</b>";

	}else{

		var bakString='<a href="'+this.linksInList[(this.onThisPage-1)]+'">Back</a>';

	}

	if(this.onThisPage==(this.totalNumberOfLinks-1)){

		var nxtString="<b>Next</b>";

	}else{

		var nxtString='<a href="'+this.linksInList[(this.onThisPage+1)]+'">Next</a>';

	}

	var bakTD=document.getElementById("bak");

	var nxtTD=document.getElementById("nxt");	

	

	bakTD.innerHTML=bakString;

	nxtTD.innerHTML=nxtString;

}



Navselect.prototype.ColorOver=function(o) {

    o.parentNode.style.backgroundColor="#cc0000";

}



Navselect.prototype.ColorOut=function(o) {

    o.parentNode.style.backgroundColor="#0000cc";

}
function whichTab() {
        var ULs, UL, LIs, LI, i=j= -1, pageurl = document.location.href.split("?")[0];
        ULs = document.getElementsByTagName("ul"); 
        while( UL=ULs[++i] ){/* Loop stops when ULs[n]--> null */
                if(UL.id=="tabnav"){
                j = -1;
                LIs=UL.getElementsByTagName("li");
                while( LI=LIs[++j] ){//loop through hrefs in li to see which tab matches this url
                        if(LI.childNodes.item(0)==pageurl){// Change <li> background
                                LI.style.background="url(http://newsimg.bbc.co.uk/sol/shared/img/v3/tabs/tab_bg104o.gif) #eee";
                                // Remove Link and replace with text
                                var thisTagTxt=LI.firstChild.firstChild.data;
                                var myTextNode=document.createTextNode(thisTagTxt);
                                LI.removeChild(LI.firstChild);
                                LI.appendChild(myTextNode);
                        }
                }
                }
        } 
}

