// JavaScript Document
// Gus 01/2006
//----------------------------------------------------------------------------

// For backward compatability ("document.all" is depricated)
if(document.all && !document.getElementById) {
	alert ("Wow, you've got a REALLY old browser!");
	//document.getElementById = new function(id) {
	//	return document.all[id];
	//}
}

// Hide the Photo/Video Links until we need them
// document.write('<style type="text/css">#ExtrasLinks{visibility: hidden;}</style>');
var ObjectID=document.getElementById("ExtrasLinks");
if (ObjectID) { ObjectID.style.visibility = "hidden"; }

// Keep JavaScript from failing if the variable does not exist
try {
	if (myPix.length){ }
}
catch(err) {
	myPix = new Array("");
}

// Include the array of names on the page within <script> tags
// var myPix = new Array("/images/ministergeneral.png","PK1_39-e.jpg","PK1_52-e.jpg");

// A counter, and an array for pre-loading
var thisPic = 0;
var imgload = new Array;

// Get image dir based on page name (XXXXX.html = /horses/img/XXXXX/)
var myloc = window.location.href;
var locarray = myloc.split("/");
var pagename = locarray[(locarray.length-1)];
var base = basedir = "/horses/img/" + pagename.replace(".html","/");

// Start the automatic slideshow
IId=window.setInterval('chgSlide(0)', 2000);  //2000ms (2 secs)


function StartShow() {
	if (!document.images) { return; }
	clearInterval(IId);
	chgSlide(0);
	IId=window.setInterval('chgSlide(0)', 2000);  //2000ms (2 secs)
	return;
}

function chgSlide(direction) {
	if (!document.images) { return; }
	if (myPix.length>0) { clearInterval(IId); return; }
	if (direction==0) { direction=1; } else { clearInterval(IId); }
	thisPic = (thisPic + myPix.length + direction) % myPix.length;
	if (imgload[thisPic]) { document.myPicture.src = imgload[thisPic].src; }
	return;
}

function gotoslide(slidenum) {
	//  This will allow for direct access of any particular slide, i.e.:
	//   <a href="javascript:gotoslide(1)">image2</a>
	if (!document.images) { return; }
	clearInterval(IId);  // stop the slideshow
	if (imgload[slidenum]) { document.myPicture.src = imgload[slidenum].src; }
	return;
}

function preloadImages() {
	// Eliminate the Slideshow controls when there is only 1 slide
	var SlideCtrlText='';
	if (myPix.length>1) {
		SlideCtrlText += '<a href="javascript:chgSlide(-1)" style="text-decoration: none">&lt;Previous</a>';
		SlideCtrlText += '&nbsp;&nbsp;&nbsp; ';
		SlideCtrlText += '<a href="javascript:chgSlide(+1)" style="text-decoration: none">Next&gt;</a>';
		SlideCtrlText += document.getElementById("SlideControls").innerHTML;
	}
	if (SlideCtrlText) { document.getElementById("SlideControls").innerHTML = SlideCtrlText; }
	
	// Make the photo/video links visible if there are multiple slides
	var ObjectID=document.getElementById("ExtrasLinks");
	// if (ObjectID && myPix.length>1) { ObjectID.style.visibility = "visible"; }
	if (ObjectID && document.getElementById("ShowExtrasLinks")) { ObjectID.style.visibility = "visible"; }

	// Pre-load images
	if (!document.images) { return; }
	for(var i=0; i<myPix.length; i++) {
		if (/^\//.test(myPix[i])) { base=""; } else { base=basedir; }
		imgload[i] = new Image;
		imgload[i].src = base + myPix[i];
	}
}


function grey_void_links() {
	// to grey-out the unused links in ExtrasLinks
	if (!document.getElementsByTagName) return; 
	// if (!document.ExtrasLinks) return; 
	var anchors = document.getElementsByTagName("a"); 
	// alert(anchors.length);
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		var myHREF=anchor.getAttribute("href");
		if (myHREF && (myHREF=="" || myHREF=="javascript:void(null)")) {
			// alert ("bye");
			anchor.style.href = "javascript:void(null)"; 
			anchor.style.color = "#DDDDDD"; 
			// anchor.style.font-style = "italic"; 
			// anchor.style.text-decoration = "none"; 
		}
	} 
} 




function combined_onload() {
	// Pre-load the images
	preloadImages();
	// to grey-out the unused links in ExtrasLinks
	grey_void_links();
}

// window.onload = preloadImages;
window.onload = combined_onload;


