/* Simplifies onload, you will no longer have to add an onload event call just call addLoadEvent */
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function addLoadEvent(func,arg){

if (!arg){
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
}
}
  else{/*if the onload event has an argument/parameter cater for that*/
  if (arg){
  oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func(arg); 
	}
     window.onload = function() {
      oldonload();
      func(arg); 
    }
  }
}
}



/*Start homepage slideshow*/

var slides; //contain slide collection
var slideNumber = 0; //the index of the current slide
var slideElement; //the current image file
var slideTimer = null;
var slideDelay = 2000; // slideshow delay milliseconds

var clicks; //the following lines define image click through URLs;
//var clickNumber = 0; //can use slideNumber instead;
var clickElement;

window.onload = init;

function init(){
	slideElement = document.getElementById('slides');
	slides = [
			  'j8/j-8ii-pl-12-missile-china-small.jpg',
			  'j10b/j10b-31-s.jpg',
			  'fbc1/fbc1_s.jpg',
			  'j8/J-8F-china-fighter-PL-12-missile-line-draw-small.jpg',
			  'wz10/wz10-helicopter-china-thumbnail.jpg',
			  'fc1/fc-1-uk-small.jpg',
			  ]
	slideTimer = setInterval('nextSlide()', slideDelay); //This starts slideshow when page loaded.
														//The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).
	slideElement.onclick = startStopSlides;
	//startStopSlides();

	clickElement = document.getElementById('clicks'); //define click through URLs
	clicks = [
			  '/pla/J-8F-fighter-china-F-8F-J8F.htm',
			  '/pla/english/j-10b-F-10b-fighter-china.htm',
			  '/pla/fbc-1-jh-7-fighter-bomber-china.htm',
			  '/pla/j-8ii-j-8b-fighter-china.htm',
			  '/pla/wz10-helicopter-china.htm',
			  '/pla/fc-1-jf-17-thunder-fighter-china.htm',
			  ]	
}

function nextSlide() {
	slideElement.src = '/pla/gfx/'+slides[slideNumber]; 
	clickElement.href = clicks[slideNumber]; //assign url to image

	slideNumber++;
	slideNumber %= slides.length;
}

function startStopSlides() {
	if (!slideTimer) {
		slideTimer = setInterval('nextSlide()', slideDelay);
	}
	else{
		clearInterval (slideTimer);
		slideTimer = null;
	}
}

/*End homepage slideshow*/


function loadGAScript(){
	/*Check browser for Dom compatibility*/
if (!document.getElementsByTagName) return false;
/*Determines whether the page is using a secure or unsecure protocol*/
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
/*Writes in the script to the document head*/
var gaScript = document.createElement("script");
gaScript.setAttribute("src",gaJsHost +"google-analytics.com/ga.js");
gaScript.setAttribute("type","text/javascript");
var domHead = document.getElementsByTagName("head")[0]
domHead.appendChild(gaScript);
	}
	loadGAScript();

/*Calls the analytics function*/
function callGA(){	
var pageTracker = _gat._getTracker("UA-1010057-1");
pageTracker._initData();
pageTracker._trackPageview();
}

addLoadEvent(callGA);
