
// preload navigation images:

if (document.images) {
	// used to references images absolutely so that menu works in sub directories
	var url = 'http://www.montpelierchartered.com/';
	
	about_on = new Image();
			about_on.src = url + "images/about_on.gif";
            about_off = new Image();
			about_off.src = url + "images/about_off.gif";
            
            services_on = new Image();
	services_on.src = url + "images/services_on.gif";
	services_off = new Image();
            services_off.src = url + "images/services_off.gif";
            
            offices_on = new Image();
	offices_on.src = url + "images/offices_on.gif";
	offices_off = new Image();
            offices_off.src = url + "images/offices_off.gif";
            
            news_on = new Image();
	news_on.src = url + "images/news_on.gif";
	news_off = new Image();
            news_off.src = url + "images/news_off.gif";
            
	infobank_on = new Image();
	infobank_on.src = url + "images/infobank_on.gif";
	infobank_off = new Image();
	infobank_off.src = url + "images/infobank_off.gif";
	
	contact_on = new Image();
	contact_on.src = url + "images/contact_on.gif";
	contact_off = new Image();
	contact_off.src = url + "images/contact_off.gif";
		     
	tab1_on = new Image();
	tab1_on.src = url + "images/tab1_on.gif";
	tab1_off = new Image();
	tab1_off.src = url + "images/tab1_off.gif";
	tab1_bg = new Image();
	tab1_bg.src = url + "images/image1.jpg";

	tab2_on = new Image();
	tab2_on.src = url + "images/tab2_on.gif";
	tab2_off = new Image();
	tab2_off.src = url + "images/tab2_off.png";
	tab2_bg = new Image();
	tab2_bg.src = url + "images/image2.jpg";

	tab3_on = new Image();
	tab3_on.src = url + "images/tab3_on.gif";
	tab3_off = new Image();
	tab3_off.src = url + "images/tab3_off.png";
	tab3_bg = new Image();
	tab3_bg.src = url + "images/image3.jpg";              
}
                        
function hiLite(imgID,changeID) {
                        
        if (document.images) {
        showText(imgID,changeID);
		return true;
        }
		
}

//global variables for the timer
timerStop = 0;
timerCount = 0;
currentPanel = '';
loopArray = new Array('tab1','tab2','tab3');
//loopBGArray = new Array('image1.jpg','image2.jpg','image3.jpg');
loopTabArray = new Array('tab1','tab2','tab3');

function showText(srcElement,changeID){
	panel = document.getElementById(srcElement+'Text');
	panelBackground = document.getElementById('background');
	switch(srcElement){
		case 'tab1': panelBackground.style.backgroundImage = "url(images/image1.jpg)"; break;
		case 'tab2': panelBackground.style.backgroundImage = "url(images/image2.jpg)"; break;
		case 'tab3': panelBackground.style.backgroundImage = "url(images/image3.jpg)"; break;

		default: if(timerStop != 0) panelBackground.style.backgroundImage = "url(images/image0.jpg)"; break;
	}
	
	//console.debug(srcElement+'Text');
	if(panel!=null){
		
		if(panel.style.display=='block'){
			//IF THE TIMES RUNNING AND WE MOUSEOVER
			//THE PANEL THE TIMER SHOWED DON'T TURN IT OFF
			//JUST RESET THE TIMER
			if(timerStop == 0){
			timerStop = 1;
			}
			else{
			//turn the panel off and restart the timer
			panel.style.display = (panel.style.display=='block') ? 'none' : 'block';
			panelBackground.style.backgroundImage = (panel.style.display=='none') ? "url(images/image0.jpg)" : background.style.backgroundImage;
			document.images[srcElement].src = eval(changeID + ".src");
			timerStop = 0;
			timerCount = 0;
			}
		}
		else{
		//turn the panel on and stop the timer
		hideAllPanels();
        document.images[srcElement].src = eval(changeID + ".src");
		panel.style.display = 'block';
		timerStop = 1;
		}
	}
	else{
        document.images[srcElement].src = eval(changeID + ".src");
	}
}

function hideAllPanels(){
	for($i=0;$i<loopArray.length;$i++){
		nextPanel=document.getElementById(loopArray[$i]);
		nextPanel.style.display = 'none';
		document.images[loopTabArray[$i]].src = eval(loopTabArray[$i] + '_off' + ".src");
	}
}

function timeEvent(){
	//console.debug('timed event fired');
	//keep a track of the timer count - it gets reset by the the hiLite function
	realCount = timerCount;
	
	if(timerStop==0){
		/* turn off*/;
		lastCount = (timerCount==0) ? 2 : timerCount-1;
		//console.debug('time finished - '+realCount+' working with  - '+timerCount);

		imgID = loopTabArray[lastCount];
		changeID = loopTabArray[lastCount]+'_off';
		document.images[imgID].src = eval(changeID + ".src");
		
		hiLite(imgID,changeID);
		
		/* turn on*/
		imgID = loopTabArray[realCount];
		changeID = loopTabArray[realCount]+'_on';
		hiLite(imgID,changeID);
		
		timerCount = (realCount==2) ? 0 : realCount+1;
		//console.debug('time finished - '+timerCount+' stop - '+timerStop);
		timerStop = 0;
	}
//	console.debug('time finished - '+timerCount+' stop - '+timerStop);
	window.setTimeout('timeEvent()',5000);
}