// facts rotator for about page

function facts_rotator(step)
{
	// added conditional statment to prevent errors on non about pages /KN
	if (facts_text = document.getElementById('facts_content')) {
		switch(step)
		{
		   case 1 :
			  facts_text.innerHTML = 'Sea kittens talk to each other through squeaks, squeals, and other low-frequency sounds that humans can only hear through special instruments. Most ichthyologists&mdash;scientists who specialize in sea kitten biology&mdash;agree that this is just about the cutest thing ever.';
			  setTimeout("facts_rotator(2)",10000);
			  break;
		   case 2 :
			  facts_text.innerHTML = '<span style="color:#c054c0;">Like their surface-dwelling cousins, the land kittens, sea kittens enjoy being petted. Their lack of arms makes it difficult for them to pet back, but they often gently rub against each other as a sign of affection.</span>';
			  setTimeout("facts_rotator(3)",10000);
			  break;
		   case 3 :
			  facts_text.innerHTML = 'Some sea kittens tend well-kept gardens. They encourage the growth of tasty algae and weed out the types that they don\'t like. It is particularly tragic when people eat these sea kittens, as their precious little gardens become wild and overgrown in their absence.';
			  setTimeout("facts_rotator(4)",10000);
			  break;
		   case 4 :
			  facts_text.innerHTML = '<span style="color:#7a54c0;">Contrary to popular belief, the technical term for sea kitten offspring is "baby sea kitties," not "caviar." Many sea kittens build nests where they can raise their baby sea kitties, and others collect small rocks off the sea floor to make widdle hiding pwaces where they can rest.</span> ';
			  setTimeout("facts_rotator(5)",10000);
			  break;
			case 5 :
			  facts_text.innerHTML = '<span style="color:#c054c0;">Many male sea kittens woo potential partners by singing to them. While this is not particularly easy to do underwater coherently, female sea kittens don\'t generally seem to mind.</span>';
			  setTimeout("facts_rotator(6)",10000);
			  break;
			case 6 :
			  facts_text.innerHTML = '<span style="color:#7a54c0;">A University of Edinburgh study found that sea kittens can retain information that they learned up to 11 months earlier.</span>';
			  setTimeout("facts_rotator(1)",10000);
			  break;
		}
	}
}


// initialises functionality for the social networking links
function initSN() {
	el = document.getElementById('sn');
	if (el) {
		snImages = el.getElementsByTagName('IMG');
		for(i=0;i<snImages.length;i++) {
			snImg = snImages[i];
			snImg.onmouseover = function() {
				el = document.getElementById('snInfo');
				el.innerHTML = this.getAttribute('ALT');
			}
			snImg.onmouseout = function() {
				el = document.getElementById('snInfo');
				el.innerHTML = '';
			}
		}
	}
}


///////////// PRELOAD IMAGES ////////////////

preloadArray = new Array();
function addPreload(imgSrc) { preloadArray[preloadArray.length] = imgSrc; }
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		for (i=0; i<preloadArray.length; i++) eval("preloadImage"+i+" = newImage('"+preloadArray[i]+"');");
		preloadFlag = true;
	}
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}



// image swap function
// swaps src on mouseover for images using the "imageSwap" CSS class
function initImageSwap() {
	imgs = document.getElementsByTagName('IMG');
	for(i=0;i<imgs.length;i++) {
		el = imgs[i];
		if (el.className=='imageSwap') {
			el.ext = el.src.substr(el.src.length-3,3);
			addPreload(el.src.replace('1.'+el.ext,'2.'+el.ext));
			addPreload(el.src);
			if (targetId = el.getAttribute('swapTarget')) {
				// attach events to target element instead of this image
				if (!el.id) el.id = "swapTargetSrc"+Math.random();
				targetEl = document.getElementById(targetId);
				targetEl.setAttribute('swapTargetSrc',el.id);
				// is the target a form?
				targetIsForm = false;
				for(f=0;f<document.forms.length;f++) {
					if (document.forms[f]==targetEl) {
						targetIsForm = true;
						break;
					}
				}
				if (targetIsForm) {
					targetEl.onfocus = function() {
						srcImg = document.getElementById(this.getAttribute('swapTargetSrc'));
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						if (srcImg.src.indexOf('2.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('1.'+srcImg.ext,'2.'+srcImg.ext);
						this.mactive = true;
					}
					targetEl.onblur = function() {
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						setTimeout("if (!document.getElementById('"+this.id+"').mactive) { srcImg = document.getElementById(document.getElementById('"+this.id+"').getAttribute('swapTargetSrc')); if (srcImg.src.indexOf('1.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('2.'+srcImg.ext,'1.'+srcImg.ext)+r; }" ,250);
						this.mactive = false;
					}
				} else {
					targetEl.onmouseover = function() {
						// force animated GIFs to reload in IE
						srcImg = document.getElementById(this.getAttribute('swapTargetSrc'));
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						if (srcImg.src.indexOf('2.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('1.'+srcImg.ext,'2.'+srcImg.ext) + r;
						this.mactive = true;
					}
					targetEl.onmouseout = function() {
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						setTimeout("if (!document.getElementById('"+this.id+"').mactive) { srcImg = document.getElementById(document.getElementById('"+this.id+"').getAttribute('swapTargetSrc')); if (srcImg.src.indexOf('1.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('2.'+srcImg.ext,'1.'+srcImg.ext)+r; }" ,250);
						this.mactive = false;
					}
				}
			} else {
				el.onmouseover = el.onmouseup = function() {
					// force animated GIFs to reload in IE
					r = (this.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
					this.src = this.src.replace('1.'+this.ext,'2.'+this.ext)+r;
				}
				el.onmouseout = el.onmousedown = function() {
					// force animated GIFs to reload in IE
					r = (this.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
					this.src = this.src.replace('2.'+this.ext,'1.'+this.ext)+r;
				}
			}
		}
	}
}


// extends the width of the footer bg shadow if appropriate:
/*function formatForWidescreen() {
	// what is the window width?
	if (document.all) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	} else {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	}
	if (winW < 1030) {
		document.getElementById('shadowContainer').style.width = "980px";
		document.getElementById('shadowContainer2').style.width = "980px";
		document.getElementById('footer').style.width = "980px";
		document.getElementById('footerBg2').style.width = "980px";
		document.getElementById('footerBg2').style.marginLeft = "-24px";
	}
	onresize = formatForWidescreen;
}*/


//////////////// ONLOAD SEQUENCE //////////////

pageLoaded = false;
onload = function() {
	pageLoaded = true;
	initSN();
	initImageSwap();
	preloadImages();
	facts_rotator(1);
	//formatForWidescreen();
}



