// JavaScript Document
// window.onload = init;
//alert("tSize: "+ THUMB_W + " tHeight: " +THUMB_H+ " spacing:"+ " "+ THUMB_SPACE + " width: " +LAND_W + " height: "+ LAND_H+ " pHeight: " + POR_H + " pWidth: " + POR_W + " top:  " + TOP_Y + " left: "+ LEFT_X + " Total: " + TOTAL_IMAGES + " rows: " + THUMBS_PER_ROW);
//alert("page_type: ");

var d=document;
var zInterval=null;
var k=null;
var w=null;
var b=6;
var imageCoordinates = new Array(); 		// array to hold the x,y of each image
var imageObjects = new Array(); 		// object reference array to the images
var imageDimensions = new Array();		// array to hold the current width and height of the images
var oDim=new Array();
var oWid=new Array();
var oHeight=new Array();
var oHt=null;
var oWd=null;
var imageStart = new Array(); 		// the original x/y positions of each image
var imageCourse = new Array(); 		// the x/y coordinates the image must travel to get from point A to point B
var currentOpacity = new Array(); 		// current transparency of the image
var activeImage=-1; 			// index of the currently active image
var prevImage=-1; 			// index of the formerly active image
var animationIndex = new Array(); 		// keeps track of where we need to be in the imageCourse array for each animation loop
var movementSteps = new Array();		// the width and height increments required for each image to resize by while moving
var useOpacity=0; 				// boolean to denote use of opacity filters
var isAnimated=0;				// stops additional threads from running if one already is.
var myImage=null;
var CAP_TEXT="Loading....please wait";
var DEFAULT_CAPTION=CAP_TEXT
var index=null
var y=null;
var pid=null;
var picpath="";
var activecolor="#669966";
var basecolor="#999999";
var ver=null;
var msg="";
var fo=null;

//var Flash_ht=""
//var fo = new SWFObject("viewer.swf", "viewer", "100%", Flash_ht, "8", "#181818");  //width height

function SetActiveColour(a_col){
//	alert(a_col);
	if (a_col=="green"){
		activecolor="#669966";
	}
	if (a_col=="yellow"){
		activecolor="#FFBF00";
	}
	if (a_col=="dred"){
		activecolor="#990000";
	}
	if (a_col=="bred"){
		activecolor="#F03";
	}
}

function date_ddmmmyy(date){
		var d = date.getDate();
		var m = date.getMonth() + 1;
		var y = date.getYear();
		var h=date.getHours();
		var mins=date.getMinutes();
		var secs=date.getSeconds();
		if(y >= 2000){
			y -= 2000;
		}
		if(y >= 100){
			y -= 100;
		}
		var mmm = ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun': ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep': (10==m)?'Oct':(11==m)?'Nov':'Dec';
	  return "" +  (d<10?"0"+d:d) + " " +  mmm + " " +  (y<10?"200"+y:y) +" at " +  (h<10?"0"+h:h) +":"+mins + "."+secs;
}


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function load_script(){
loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file
}

function open_viewer_cb(){
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
//		alert(this.browser);
if(this.browser=="Firefox") var Flash_ht="100%";  //width height
if(this.browser=="Explorer")var Flash_ht="92.5%";  //width height
//alert(Flash_ht);
var fo = new SWFObject("viewer.swf", "viewer", "100%", Flash_ht, "8", viewer_back_col);  //width height
//alert(xml_0);
		fo.addVariable("xmlDataPath", xml_0);
		fo.write("flashcontent");	

	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


//alert(xml_0);
		// SIMPLEVIEWER CONFIGURATION OPTIONS
		// To use an option, uncomment it by removing the "//" at the start of the line
		// For a description of config options, go to: 
		// http://www.airtightinteractive.com/simpleviewer/options.html
		
		//fo.addVariable("xmlDataPath", xml_0);
		//fo.write("flashcontent");	

		//fo.addVariable("xmlDataPath", "images/country/gallery.xml");
		//fo.addVariable("firstImageIndex", "1");	
		//fo.addVariable("langOpenImage", "Open Image in New Window");
		//fo.addVariable("langAbout", "About");	
		//fo.addVariable("preloaderColor", "0xFFFFFF");
		
		//fo.write("flashcontent");	
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function checkVersion(viewer_back_col)
{
 msg = "You're not using Internet Explorer.";
 ver = getInternetExplorerVersion();
//alert( ver+" "+msg );
  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
	//	alert("cv"+" "+viewer_back_col);

	if(v_wid==100){
		if(ver==-1) fo = new SWFObject("viewer.swf", "viewer", "96%", "95%", "8", viewer_back_col);  //width height
		if (ver>-1) fo = new SWFObject("viewer.swf", "viewer", "96%", "90%", "8", viewer_back_col);  //width height
	}
	if(v_wid==50){
		if(ver==-1) fo = new SWFObject("viewer.swf", "viewer", "50%", "95%", "8", viewer_back_col);  //width height
		if (ver>-1) fo = new SWFObject("viewer.swf", "viewer", "50%", "90%", "8", viewer_back_col);  //width height
	}
 // alert(fo );
}

function checkVersionFullWidth()
{
//		alert(viewer_back_col);

//	alert("cvfw");
 msg = "You're not using Internet Explorer.";
 ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
 //alert( ver+" "+msg );
	if(ver==-1) fo = new SWFObject("viewer.swf", "viewer", "96%", "99%", "8", viewer_back_col);  //width height
	if (ver>-1) fo = new SWFObject("viewer.swf", "viewer", "95%", "90%", "8", viewer_back_col);  //width height
 // alert(fo );
}

function open_viewer(xml_0,change_col,viewer_back_col){
	
	if (viewer_back_col==null) viewer_back_col="#181818";
//		alert("ov: "+viewer_back_col);
	

	if (Full_Width) {
		checkVersionFullWidth(viewer_back_col);
	}else{
		checkVersion(viewer_back_col);
	}
//  alert("done" );

//alert(xml_0);
		// SIMPLEVIEWER CONFIGURATION OPTIONS
		// To use an option, uncomment it by removing the "//" at the start of the line
		// For a description of config options, go to: 
		// http://www.airtightinteractive.com/simpleviewer/options.html
		
		fo.addVariable("xmlDataPath", xml_0);

		//fo.addVariable("xmlDataPath", "images/country/gallery.xml");
		//fo.addVariable("firstImageIndex", "1");	
		//fo.addVariable("langOpenImage", "Open Image in New Window");
		//fo.addVariable("langAbout", "About");	
		//fo.addVariable("preloaderColor", "0xFFFFFF");
		
		fo.write("flashcontent");	
}

function loadSWF(url){
  swfobject.embedSWF(url, "flashcontent", "550", "400", "7");
}
	
function  change_pic(pid){
//    	alert("vis change_pic");
		fo.addVariable("firstImageIndex", pid);	
		fo.write("flashcontent");	
		}
		
function showDesc(){
//	alert(divid);
	
	if(document.getElementById('description'))
	{
	document.getElementById('description').style.visibilty="hidden";
	divshow=document.getElementById('description').style.visibilty
	}
//	alert(divshow);
}

function  change_xml(picpath,change_col,viewer_back_col){
			//alert(picpath+" "+change_col+" "+document.getElementById('one').firstChild.style.color);
		//	alert("ChangeXML :" +viewer_back_col);
	if (Full_Width) {
		checkVersionFullWidth(viewer_back_col);
	}else{
		checkVersion(viewer_back_col);
	}
			if (change_col!="no"){
			if(document.getElementById('one'))document.getElementById('one').firstChild.style.color=basecolor;
			if(document.getElementById('two'))document.getElementById('two').firstChild.style.color=basecolor;
			if(document.getElementById('three'))document.getElementById('three').firstChild.style.color=basecolor;
			if(document.getElementById('four'))document.getElementById('four').firstChild.style.color=basecolor;
			if(document.getElementById('five'))document.getElementById('five').firstChild.style.color=basecolor;
			if(document.getElementById('six'))document.getElementById('six').firstChild.style.color=basecolor;
			if(document.getElementById('seven'))document.getElementById('seven').firstChild.style.color=basecolor;
			if(document.getElementById('eight'))document.getElementById('eight').firstChild.style.color=basecolor;
			if(document.getElementById('nine'))document.getElementById('nine').firstChild.style.color=basecolor;
			}
		if (picpath==0) {
			//alert(change_col+" " +activecolor);
			fo.addVariable("xmlDataPath", xml_0);	
			if (change_col!="no") document.getElementById('one').firstChild.style.color=activecolor;
		}
		if (picpath==1) {
			fo.addVariable("xmlDataPath",xml_1);	
//			alert(xml_1+" "+change_col+" " +activecolor);
			if (change_col!="no") document.getElementById('two').firstChild.style.color=activecolor;
		}
		if (picpath==2){
//			alert(change_col+" " +activecolor);
			fo.addVariable("xmlDataPath", xml_2);	
			if (change_col!="no") document.getElementById('three').firstChild.style.color=activecolor;
		}
		if (picpath==3){
			fo.addVariable("xmlDataPath", xml_3);	
			if (change_col!="no") document.getElementById('four').firstChild.style.color=activecolor;
		}
		if (picpath==4) {
			fo.addVariable("xmlDataPath", xml_4);	
			if (change_col!="no") document.getElementById('five').firstChild.style.color=activecolor;
		}
		if (picpath==5) {
			fo.addVariable("xmlDataPath", xml_5);	
			if (change_col!="no") document.getElementById('six').firstChild.style.color=activecolor;
		}
		if (picpath==6) {
			fo.addVariable("xmlDataPath", xml_6);	
			if (change_col!="no") document.getElementById('seven').firstChild.style.color=activecolor;
		}
		if (picpath==7) {
			fo.addVariable("xmlDataPath", xml_7);	
			if (change_col!="no") document.getElementById('eight').firstChild.style.color=activecolor;
		}
		if (picpath==8) {
			fo.addVariable("xmlDataPath", xml_8);	
			if (change_col!="no") document.getElementById('nine').firstChild.style.color=activecolor;
		}
//		alert("writeflash");
	
		fo.write("flashcontent");	
		}
		
function  change_xml_nf(picpath,change_col){
//			alert(picpath+" "+change_col+" "+activecolor);
	if (Full_Width) {
		checkVersionFullWidth();
	}else{
		checkVersion();
	}
			if (change_col!="no"){
			if(document.getElementById('one'))document.getElementById('one').firstChild.style.color=basecolor;
			if(document.getElementById('two'))document.getElementById('two').firstChild.style.color=basecolor;
			if(document.getElementById('three'))document.getElementById('three').firstChild.style.color=basecolor;
			if(document.getElementById('four'))document.getElementById('four').firstChild.style.color=basecolor;
			if(document.getElementById('five'))document.getElementById('five').firstChild.style.color=basecolor;
			if(document.getElementById('six'))document.getElementById('six').firstChild.style.color=basecolor;
			if(document.getElementById('seven'))document.getElementById('seven').firstChild.style.color=basecolor;
			if(document.getElementById('eight'))document.getElementById('eight').firstChild.style.color=basecolor;
			if(document.getElementById('nine'))document.getElementById('nine').firstChild.style.color=basecolor;
			}
		if (picpath==0) {
//			alert(change_col+" " +activecolor);
			fo.addVariable("xmlDataPath", xml_0);	
			if (change_col!="no") document.getElementById('one').firstChild.style.color=activecolor;
		}
		if (picpath==1) {
			fo.addVariable("xmlDataPath",xml_1);	
//			alert(xml_1+" "+change_col+" " +activecolor);
			if (change_col!="no") document.getElementById('two').firstChild.style.color=activecolor;
		}
		if (picpath==2){
//			alert(change_col+" " +activecolor);
			fo.addVariable("xmlDataPath", xml_2);	
			if (change_col!="no") document.getElementById('three').firstChild.style.color=activecolor;
		}
		if (picpath==3){
			fo.addVariable("xmlDataPath", xml_3);	
			if (change_col!="no") document.getElementById('four').firstChild.style.color=activecolor;
		}
		if (picpath==4) {
			fo.addVariable("xmlDataPath", xml_4);	
			if (change_col!="no") document.getElementById('five').firstChild.style.color=activecolor;
		}
		if (picpath==5) {
			fo.addVariable("xmlDataPath", xml_5);	
			if (change_col!="no") document.getElementById('six').firstChild.style.color=activecolor;
		}
		if (picpath==6) {
			fo.addVariable("xmlDataPath", xml_6);	
			if (change_col!="no") document.getElementById('seven').firstChild.style.color=activecolor;
		}
		if (picpath==7) {
			fo.addVariable("xmlDataPath", xml_7);	
			if (change_col!="no") document.getElementById('eight').firstChild.style.color=activecolor;
		}
		if (picpath==8) {
			fo.addVariable("xmlDataPath", xml_8);	
			if (change_col!="no") document.getElementById('nine').firstChild.style.color=activecolor;
		}
}
function date_lastmodified(){
		var lmd = document.lastModified;
		var s   = "Unknown";
		var dl=null;
		if(0 != (d1=Date.parse(lmd))) {
			ld = " Modified on: " + date_ddmmmyy(new Date(d1));
		}
		return s;
}

function writit(){
		date_lastmodified();
		x = document.getElementById("footer2");
		x.innerHTML = '';
//		alert(ld);
		x.innerHTML = ld;
}	

function setFooter(w){
	date_lastmodified();
	if(!document.getElementById)return;	// bail out if this is an old browser
//alert("not bailed out yet");
	//	alert(TOTALIMG);
	if (w==480)	{
		if(d.getElementById("footer")){
			d.getElementById("footer").innerHTML = "Optimised for iPhone. Copyright D@edalus Design 2010" + ld;
		}else{
			d.getElementById("gfooter").innerHTML = "Optimised for " + w + " x " + h + " screen resolution. Copyright D@edalus Design 2010"+ld;
//			alert(d.getElementById("gfooter").innerHTML);
		}
//		d.getElementById("g_footer").innerHTML = "Optimised for iPhone. Copyright D@edalus Design 2010" + ld;
	}else{
		var w=1440;
		var h=900;
		if(d.getElementById("footer")){
//			alert("footer");
			d.getElementById("footer").innerHTML = "Optimised for " + w + " x " + h + " screen resolution. Copyright D@edalus Design 2010"+ld;
		}else{
			d.getElementById("gfooter").innerHTML = "Optimised for " + w + " x " + h + " screen resolution. Copyright D@edalus Design 2010"+ld;
//			alert(d.getElementById("gfooter").innerHTML);
		}
	}
	
	if(d.getElementById("footer1")){
			d.getElementById("footer1").innerHTML = "The Lucra Cars and LC470 heritage is the classic design of the high-performance racing Lister Jaguar and Lister Chevrolet.";
			d.getElementById("footer2").innerHTML = "To find out more about the LC470 range of high performance convertible or hard top sports racing supercars call +1 310 948 1489";
		}

}

function init() {
	if(!document.getElementById)return;	// bail out if this is an old browser
//alert("not bailed out yet");
	//	alert(TOTALIMG);
	
//	d.getElementById("footer").innerHTML = "Optimised for " + w + " x " + h + " screen resolution. Copyright D@edalus Design 2009";
	if (TOTALIMG>0) {
//		HideImg()
		initThumbnails();			// initialize the thumbnail images
//alert("Done Thumbnails");
		initCourse();			// initialize the x/y courses the images will need to travel
//alert("Done Course");
		initSteps();			// intialize the step increments for the width and height changes
//alert("Done Steps");
		disableOpacity(false);
	}
//alert("changing stylesheet " + doc_style);
//	changeStyle(doc_style);

}


function initThumbnails() {
	x=0; y=0; i=0; z=0;
	// set the default caption up
//		if (car_model=="470") {
	//		d.getElementById("img_caption_470").innerHTML = DEFAULT_CAPTION;
	//	}else{
	//		d.getElementById("caption").innerHTML = DEFAULT_CAPTION;
	//	}	
//progressBarInit();
//	d.getElementById("caption").innerHTML = DEFAULT_CAPTION;
	// loop over how many images we have to deal with
	while(i<TOTAL_IMAGES) {
	// create an object reference variable to the image
//		if (i>0)d.getElementById("img_caption_470").innerHTML ="Loading image " +(i+1) + "......please wait";
//	alert(d.getElementById("img_caption_470").innerHTML);
//		incrCount(10);
		myImage = document.getElementById("image"+i)
		oDim[i]=myImage.width;
		oWid[i]=myImage.width;
		oHeight[i]=myImage.height;
//		alert("width: " + oWid[i] + " height: " + oHeight[i])
		if (oWid[i]<100) {
				myImage.title="";
			}
		if(!imageObjects[i])imageObjects[i]=d.getElementById("image"+i);
//		alert("image1 width : " + myImage.width + "px\nimage1 height : " + myImage.height + "px")
		// set the top and left of the image
		imageObjects[i].style.left = x + "px";
		imageObjects[i].style.top = y + "px";
		// set up the bogus "xid" attribute to ID the images when they are clicked on
		imageObjects[i].xid=i;
		// set up the onclick event
//		imageObjects[i].onmouseover=function(){animate(this.xid)};
		if (page_type !=2) imageObjects[i].onclick=function(){animate(this.xid)};
		// set up the imageStart array for this image
		if(!imageStart[i])imageStart[i]=new Array(x,y);
		// increment the x coordinate for the next image
//		alert(oHeight[i] + " " + oWid[i]);
		if(oHeight[i]<oWid[i]) {
			x+=THUMB_W+THUMB_SPACE;
//			alert("L " + i);
		} else {
			x+=THUMB_W_P+THUMB_SPACE;
//			alert("P" + i);
		}
		// set up the coordinates for this image
		imageCoordinates[i]=new Array(x,y);
		// and its initial width

		if(oHeight[i]<oWid[i]) {
			imageDimensions[i] = new Array(THUMB_W,THUMB_H);
			imageObjects[i].style.width=THUMB_W;
			imageObjects[i].style.height=THUMB_H;
//			alert(imageObjects[i].style.width);
//			alert(imageObjects[i].style.height);
		} else {
			imageDimensions[i] = new Array(THUMB_W_P,THUMB_H_P);
			imageObjects[i].style.width=THUMB_W_P;
			imageObjects[i].style.height=THUMB_H_P;
//			alert(imageObjects[i].style.width);
//			alert(imageObjects[i].style.height);
		}

//		imageDimensions[i] = new Array(THUMB_W,THUMB_W);
//		alert(imageDimensions[i]);
		// and it initial opacity. MSIE takes 0-100 values for opacity. All others take floating points.
		currentOpacity[i]=document.all?100:.5;
		// set the animationIndex for this image to 0
		animationIndex[i]=0;
		// if we've got as many images in the row as we want, start the next row
//		imageObjects[i].id.visibility="visible";
//		var iid=imageObjects[i].id
//		alert(iid);
//		iid.visibility="visible";
//		FindRule()
	
//		imageObjects[i].style.visibilty="visible";


		z++;
		if(z>=THUMBS_PER_ROW) {
			x=0; z=0;
			y+=THUMB_H+THUMB_SPACE_V;
		}
//		if (myImage.width<100) {
//				i=TOTAL_IMAGES;
//				alert(i + " "+ TOTAL_IMAGES);
//				return;
//		}else{
		i++;
//		}	
		
	}
}

function initCourse() {
	// initialize the imageCourse array for each image
	for(i=0;i<imageStart.length;i++){
//		if (car_model=="470") {
//			if (i>0)d.getElementById("img_caption_470").innerHTML ="initCourse " + i + "......please wait";
//		}else{
//			if (i>0)d.getElementById("caption").innerHTML ="initCourse " + i + "......please wait";
//		}
		if(oHeight[i]<oWid[i]) {
//			alert(LEFT_X +" " +TOP_Y)
			imageCourse[i] = plotCourse(LEFT_X,TOP_Y,imageStart[i][0],imageStart[i][1]);
		}else{
//			alert(LEFT_Xp +" " +TOP_Yp)
			imageCourse[i] = plotCourse(LEFT_Xp,TOP_Yp,imageStart[i][0],imageStart[i][1]);
		}
			
	}
}

function initSteps() {
	// initialize the step increments for the width and height changes.
	for(i=0;i<imageCourse.length;i++) {
//		if (car_model=="470") {
//			if (i>0)d.getElementById("img_caption_470").innerHTML ="initSteps " + i + "......please wait";
//		}else{
//			if (i>0)d.getElementById("caption").innerHTML ="initSteps " + i + "......please wait";
//		}

		wStep = Math.round(imageCourse[i].length/iSpeed);
		wStep = Math.round(LAND_W/wStep);
		hStep = Math.round(imageCourse[i].length/iSpeed);
		hStep = Math.round(LAND_H/hStep);
		movementSteps[i]=new Array(wStep,hStep);
	}
}

function animate(index) {
//alert("animate " + zInterval + " " + doc_style);
//alert("animate " + index);
	// exit out of the function if there is already an animation thread running
//	for(a=0;a<10;a++) {
	if(zInterval) {
//		alert(zInterval);
		return;
	}
//alert("animate1 " + index);

	// no current active image. that means either a single image is returning (no overlap) or we're running for the first time
	// make prevImage -1 so we dont run any animation loops we dont need to.
	if(activeImage==-1)prevImage=-1;
	if(index==activeImage) {
		//alert("animate1 " + index + " " + activeimage);
		// the user has clicked on the enlarged image. set prevImage to activeImage and set activeImage to -1
		prevImage=activeImage;
		imageObjects[activeImage].style.zIndex=100;
		activeImage=-1;	
	} else {
		// set up the previous image so we know which to send back and where to send it.
		if(activeImage>-1)prevImage=activeImage;
		activeImage=index;
		imageObjects[activeImage].style.zIndex=100;
		if(prevImage>-1)imageObjects[prevImage].style.zIndex=1;
	}

	// begin the animation thread
	zInterval = setInterval("slideImage()",10);
//	alert(zInterval);
	
//	}
}

function setImagePosition(index) {
	// set the positions and width of the images. These can fall out of range, hence the try/catch statement
	try {
		imageObjects[index].style.top = imageCourse[index][animationIndex[index]][1]+"px";
		imageObjects[index].style.left = imageCourse[index][animationIndex[index]][0]+"px";
		imageObjects[index].style.width=imageDimensions[index][0]+"px";
		imageObjects[index].style.height=imageDimensions[index][1]+"px";
	} catch(err) { }
}

function setImageOpacity(index) {
	// set the opacity of the object. Once for Gecko, once for Safari and once for MSIE.
	if(!useOpacity)return;
	imageObjects[index].style.filter="alpha(opacity=" + currentOpacity[activeImage] + ")";
	imageObjects[index].style.MozOpacity=currentOpacity[activeImage];
	imageObjects[index].style.opacity=currentOpacity[activeImage];
}

function slideImage() {
	// if we have an active image, meaning the one that is being enlarged...
//	alert("SlideImage " + oWid[activeImage] + " " + oHeight[activeImage]);
	if(activeImage>-1) {
		// set up its width,height,top and left
		setImagePosition(activeImage);
		// set up its opacity
		currentOpacity[activeImage]+=d.all?5:.05;
		setImageOpacity(activeImage);
		// if its width is less than 400, increase it. likewise with its height
//		if (activeImage==3){
		if(oHeight[activeImage]<oWid[activeImage]) {
			if(imageDimensions[activeImage][0]<LAND_W)imageDimensions[activeImage][0]+= movementSteps[activeImage][0];
			if(imageDimensions[activeImage][1]<LAND_H)imageDimensions[activeImage][1]+= movementSteps[activeImage][1];
		} else {
			if(imageDimensions[activeImage][0]<POR_W)imageDimensions[activeImage][0]+= movementSteps[activeImage][0];
			if(imageDimensions[activeImage][1]<POR_H)imageDimensions[activeImage][1]+= movementSteps[activeImage][1];
		}
		animationIndex[activeImage]+=iSpeed;
	}

	// do the same as above for images returning to thumbnail size, only decrementing values this time
	if(prevImage>-1) {
		setImagePosition(prevImage);
		currentOpacity[prevImage]-=d.all?5:.05;
		setImageOpacity(prevImage);
		if(oHeight[prevImage]<oWid[prevImage]) {
			if(imageDimensions[prevImage][0]>THUMB_W)imageDimensions[prevImage][0]-=movementSteps[prevImage][0];
			if(imageDimensions[prevImage][1]>THUMB_H)imageDimensions[prevImage][1]-=movementSteps[prevImage][1];
		} else {
			if(imageDimensions[prevImage][0]>THUMB_W_P)imageDimensions[prevImage][0]-=movementSteps[prevImage][0];
			if(imageDimensions[prevImage][1]>THUMB_H_P)imageDimensions[prevImage][1]-=movementSteps[prevImage][1];
		}

//		if(imageDimensions[prevImage][0]>THUMB_W)imageDimensions[prevImage][0]-=movementSteps[prevImage][0];
//		if(imageDimensions[prevImage][1]>THUMB_H)imageDimensions[prevImage][1]-=movementSteps[prevImage][1];
		animationIndex[prevImage]-=iSpeed;
	}

	// has our animation finished?
	if(isFinished()) {
		// if activeImage is -1, we have no enlarged image. reset the animation index and put the default caption back in.
		if(activeImage==-1) {
			if (car_model=="470") {
			//alert(car_model);
				d.getElementById("img_caption_470").innerHTML ="Ready......";
			}else{
				d.getElementById("caption").innerHTML ="Ready......";
			}
			animationIndex[prevImage]=0;
		}
		// we've got an active image.
		if(activeImage>-1) {
			// set the animation index to the length of imageCourse so we can start at the end of that array 
			// for when this image becomes a thumbnail again
			animationIndex[activeImage] = imageCourse[activeImage].length;
			// set the final top,left,width and height of the image, just in case they're off
			if(oHeight[activeImage]<oWid[activeImage]) {
//				alert(oHeight[activeImage] + " " +oWid[activeImage]+ " " + LEFT_X +" " +TOP_Y)
				imageObjects[activeImage].style.top=TOP_Y+"px";
				imageObjects[activeImage].style.left=LEFT_X+"px";
			}else{
//				alert(oHeight[activeImage] + " " +oWid[activeImage]+ " " + LEFT_Xp +" " +TOP_Yp)
				imageObjects[activeImage].style.top=TOP_Yp+"px";
				imageObjects[activeImage].style.left=LEFT_Xp+"px";
			}
			
			if(oHeight[activeImage]<oWid[activeImage]) {
				imageObjects[activeImage].style.width=LAND_W+"px";
				imageObjects[activeImage].style.height=LAND_H +"px";
			} else {
				imageObjects[activeImage].style.width=POR_W+"px";
				imageObjects[activeImage].style.height=POR_H +"px";
			}
			if(useOpacity) {
				imageObjects[activeImage].style.MozOpacity=.99;
				imageObjects[activeImage].style.filter="alpha(opacity=100)";
				imageObjects[activeImage].style.opacity=1.0;
			}
			if (car_model=="470") {
//				var iname=imageObjects[activeImage].name;
				if(imageObjects[activeImage].title.length<1){
//					alert(imageObjects[activeImage].name.length);
					if(imageObjects[activeImage].name.length<1){
						d.getElementById("img_caption_470").innerHTML = "Missing caption";
					}else{
						d.getElementById("img_caption_470").innerHTML = imageObjects[activeImage].name;
					}
		 		}else{
				d.getElementById("img_caption_470").innerHTML = imageObjects[activeImage].title;
	 			}
				 
			}else{
				d.getElementById("caption").innerHTML = imageObjects[activeImage].title;
			}
		} 
		// do the same for the thumbnail image.
		if(prevImage>-1) {
			animationIndex[prevImage]=0;
			imageObjects[prevImage].style.top = imageStart[prevImage][1]+"px";
			imageObjects[prevImage].style.left = imageStart[prevImage][0]+"px";

		if(oHeight[prevImage]<oWid[prevImage]) {
			imageObjects[prevImage].style.width=THUMB_W +"px";
			imageObjects[prevImage].style.height=THUMB_H +"px";
		} else {
			imageObjects[prevImage].style.width=THUMB_W_P +"px";
			imageObjects[prevImage].style.height=THUMB_H_P +"px";
		}
//			imageObjects[prevImage].style.width=THUMB_W +"px";
//			imageObjects[prevImage].style.height=THUMB_H +"px";

			if(useOpacity) {
				imageObjects[prevImage].style.MozOpacity=.5;
				imageObjects[prevImage].style.filter="alpha(opacity=50)";
				imageObjects[prevImage].style.opacity=.5;
			}
		}
		// stop the animation thread
		clearInterval(zInterval);
		zInterval=null;
	}
}

// checks to see if the thumbnail and enlarged image are at their final positions
// by checking the animationIndex value against the length of the images imageCourse array.
function isFinished() {
	if(activeImage>-1 && prevImage>-1)if(animationIndex[activeImage]>=imageCourse[activeImage].length && animationIndex[prevImage]<=0) return true;
	if(activeImage>-1 && prevImage==-1) if(animationIndex[activeImage]>=imageCourse[activeImage].length)return true;
	if(activeImage==-1 && prevImage>-1) if(animationIndex[prevImage]<=0)return true;
	return false;
}

// this function simply resets the opacity of the objects when the check box is clicked.
function disableOpacity(bool) {
//	if(bool) {
		useOpacity=0;
		for(i=0;i<imageObjects.length;i++) {
			imageObjects[i].style.MozOpacity=1.0;
			imageObjects[i].style.opacity=1.0;
			imageObjects[i].style.filter="alpha(opacity=100)";
		}
//	} else {
	//	location.reload();
//	}
}

// this function calculates the required coordinates to go from point A to point B and returns them as an array.
// originally written by Dean Taylor for Web Paint's line functions (slayeroffice.com/tools/web_paint)
// also used in Missile Command (slayeroffice.com/arcade/missile_command)

function plotCourse(fX,fY,oX,oY) {

	dx = Math.abs(fX-oX);
	dy = Math.abs(fY-oY);
	max = dx > dy ? dx : dy;
	x_inc = dx / max;
	y_inc = dy / max;

	Xp = oX
	Yp = oY;

	path = new Array();
	pathCount = 0;

	if(fX>oX && fY > oY) {
		if(oX<fX && oY<fY) {
			while (Xp < fX) {
				nextX = Math.round(Xp);
				nextY = Math.round(Yp);
				path[pathCount] = new Array(nextX,nextY);
				pathCount++;
				Xp += x_inc;
				Yp += y_inc;
			}
		} else {
			while (Xp > fX) {
				nextX = Math.round(Xp);
				nextY = Math.round(Yp);
				path[pathCount] = new Array(nextX,nextY);
				pathCount++;
				Xp -= x_inc;
				Yp += y_inc;
			}		
		}	
	} else {
		if(oX<fX && oY>fY) {
			while (Xp < fX) {
				nextX = Math.round(Xp);
				nextY = Math.round(Yp);
				path[pathCount] = new Array(nextX,nextY);
				pathCount++;
				Xp += x_inc;
				Yp -= y_inc;
			}
		} else {
			while (Xp > fX) {
				nextX = Math.round(Xp);
				nextY = Math.round(Yp);
				path[pathCount] = new Array(nextX,nextY);
				pathCount++;
				Xp -= x_inc;
				Yp -= y_inc;
			}
		}
	}
	return path;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
function getAllSheets() {
//	alert("getAllSheets");
  if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
  if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
  } else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
    var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
    if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
  } for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}

function changeStyle() {
//	alert("changeStyle " + doc_style);
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    if( ss[x].title ) { ss[x].disabled = true; }
    for( var y = 0; y < arguments.length; y++ ) {
//		alert (ss[x].title);
     if( ss[x].title == arguments[y] ) { ss[x].disabled = false; }
} }
//	alert("changeStyle " + doc_style);

}
//-->
