
/* alert("JS loaded"); */

/*
	visionaire news ticker
*/


var secs;
var timerID = null;
var timerRunning = false;
var delay = 300;
var listElements = 0;
var currentShow = 1;

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 13;
    initTickerList();
    StartTheTimer();
}

function StopTheClock()
{
    if (timerRunning) {
       clearTimeout(timerID);
    }
}

function StartTheTimer()
{
    if (secs == 0) {
        secs = 10;
        newsTicker();
    } else {
        secs = secs - 1;
    }
    timerRunning = true;
    timerID = self.setTimeout("StartTheTimer()", delay);
}

newsTicker = function() {
	count = 0;
	if (document.getElementById) {
		element = document.getElementById("newsticker");
		for (i=0; i<element.childNodes.length; i++) {
			if (element.childNodes[i].nodeName == "LI") {
			count++;
				if (count == (currentShow + 1)) {
					element.childNodes[i].className = "show";
					selectedItem = count;
				} else {
					element.childNodes[i].className = "";
				}
			}
		}
		if (selectedItem == listElements) {
			currentShow = 0;
		} else {
			currentShow = selectedItem;
		}
	}
}

initTickerList = function() {
	if (document.getElementById) {
		element = document.getElementById("newsticker");
		for (i=0; i<element.childNodes.length; i++) {
			if (element.childNodes[i].nodeName == "LI") {
				if (!listElements) {
					element.childNodes[i].className = "show";
				}
				listElements++;
			}
		}
		//alert(listElements);
	}
}

/*
	add bahaviours to drop-down nav list
	see: http://www.htmldog.com/articles/suckerfish/example/
*/

initMenuList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("mainnav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}





// popup function /////////////////

function openWin(name, nameWin ,h ,w) 
{
	var scw = screen.availWidth
	var sch = screen.availHeight
	aawindow = window.open(name, nameWin,"left="+((scw/2)-(w/2))+",top="+((sch/2)-(h/2))+",width="+w+",height="+h+",scrollbars=no");
}



// date function ////////////////

var dayNames = new Array( "Sun","Mon","Tue","Wed","Thu","Fri","Sat" );
var monthNames = new Array( "January", "February","March","April","May","June","July","August","September","October","November","December" );

function getToday()
{		
	var today = new Date();
	return dayNames[today.getDay()] + " "
	+ today.getDate() + " "
	+ monthNames[today.getMonth()] + " "
	+ today.getFullYear();
}
		

// close window ///////////////////	
	
function closeWindow()
{
	window.close();
}





// random image ///////////////////	

function random_img(path, num_images)
{
	//////////////////
	var numImages = num_images;
	//////////////////
	var mainPath = "../../img_content/img_random" + path + "/";
	var baseName = "image_";
	var extension = ".jpg";
	
	var i= Math.ceil(Math.random()*numImages);
	//alert ('<img src="'+mainPath+baseName+i+extension+'" border=0 width="130" height="130">');
	document.write('<img src="'+mainPath+baseName+i+extension+'" border=0 width="130" height="130" alt="A random aviation image" />');
}


/* initialise form */

function setFocus(form, field) {
	/* use names, not id's! */
	document[form][field].focus();
}


/* --------- initialise page ----------- */

window.onload = function() {
	
	if(document.getElementById("newsticker")) {
		InitializeTimer();
	}	
	
	initMenuList();
	
	if ('function' == typeof window.initLightbox) {
		initLightbox();
	}
			
}
