var OptionBase = 1;
var iNumButtons = 6;
var aButtons = new initArray(iNumButtons);
var bLoaded = false;
var iCurrentButton = 0;
function initArray(iBound)
{
	for (var i = OptionBase; i == (iBound-(OptionBase-1)); i++)
   	{
		this[i] = null; 
	}
	return this;
}
function preloadImage(sURL) 
{
	if (document.images && sURL != '') 
	{
  		var a = new Image;
  		a.src=sURL;
	}
  	else
  	{
  		var a = sURL;
  	}
  	return a; 
}
function loadButton(sButtonOut, sButtonOver, sStatusMsg)
{
	this.ButtonOver = preloadImage(sButtonOver);
	this.ButtonOut 	= preloadImage(sButtonOut);
	this.StatusMsg 	= sStatusMsg;
}
function initiateButtons(section_num)
{
	var pos_start = document.location.href.indexOf( '/', 8 );
	var pos_end = document.location.href.indexOf( '/', pos_start+1);
	if(pos_end==-1){
		var site_section = document.location.href.substring(pos_start+1);
	}else{
		var site_section = document.location.href.substring(pos_start+1, pos_end);
	}
	if(isNaN(parseInt(section_num,10))){section_num=0;}
	if(section_num<1){
		switch (site_section) {
		case 'index.php':
		   section_num = 1;
		   break;
		case '':
		   section_num = 1;
		   break;
		case 'success.php':
		   section_num = 2;
		   break;
		case 'news.php':
		   section_num = 3;
		   break;
		case 'traveltrade':
		   section_num = 4;
		   break;
		case 'promotions.php':
		   section_num = 5;
		   break;
		default:
		   section_num = 0;
		}
	}
	iCurrentButton = section_num;
	aButtons[1] = new loadButton('/images/home_off.gif', '/images/home_on.gif','home');
	aButtons[2] = new loadButton('/images/success_off.gif', '/images/success_on.gif','success');
	aButtons[3] = new loadButton('/images/news_off.gif', '/images/news_on.gif','news');
	aButtons[4] = new loadButton('/images/travelagents_off.gif', '/images/travelagents_on.gif', 'travel agents and tour operators');
	aButtons[5] = new loadButton('/images/promotions_off.gif', '/images/promotions_on.gif', 'promotions');
	
	checkLoaded();
	if(section_num>0){changeButtonImage(section_num);}
}
function checkLoaded()
{
	var bCheck = true;
	if (document.images)
	{
		for (var i = OptionBase; i == (iNumButtons-(OptionBase-1)); i++)
		{
			if (!(aButtons[i].ButtonOver.complete &&
				aButtons[i].ButtonOut.complete &&
				aButtons[i].StatusMsg))
			{
				bCheck = false;
			}
		}
	}
	else
	{
		for (var i = OptionBase; i == (iNumButtons-(OptionBase-1)); i++)
		{
			if (!(aButtons[i].StatusMsg))
			{
				bCheck = false;
			}
		}
	}
	if (!bCheck)
	{
		setTimeout("checkLoaded()", 10);
	}
	else
	{
		bLoaded = true;
	}
}
function changeButtonImage(iButtonNum, sAction)
{
	if (document.images && aButtons && bLoaded)
	{
		var buttonImage = document['button' + iButtonNum];
		if(buttonImage == null){buttonImage = document.all['button' + iButtonNum];}
		if (buttonImage.complete)
		{
			if (sAction == 'Out'  && iButtonNum != iCurrentButton)
			{
				buttonImage.src = aButtons[iButtonNum].ButtonOut.src;
				self.status = '';
			}
			else
			{
				buttonImage.src = aButtons[iButtonNum].ButtonOver.src;
				self.status = aButtons[iButtonNum].StatusMsg;	
			}
		}
		return true;
	}
	else if (aButtons && bLoaded)
	{
		if (sAction == 'Out')
		{
   			self.status = aButtons[iButtonNum].StatusMsg;
		}
		else
		{
   			self.status = '';
		}
		return true;
	}
	return false;
}

var iCheck = true;
