// JavaScript Document

function initRotateMerch() {
	merchRotator = setInterval(rotateMerch,8000);
}
mId = 0;
function rotateMerch() {
	mId++;
	if (mId >= merchIds.length) mId = 0;
	merchId = merchIds[mId];
	merchName = merchNames[mId];
	merchPrice = merchPrices[mId];
	newMerchLink = "/support/merchandise.php?item="+merchId;
	newMerchCode = "<img src='/resources/merchthumb.php?g="+merchId+"&s=150' alt=\""+merchName+"\" />A "+merchName+" <strong class='bright'>$"+merchPrice+"</strong>";
	fadeOut('','switchMerch()',document.getElementById('merchLink'));
}

function switchMerch() {
	document.getElementById('merchLink').href = newMerchLink;
	document.getElementById('merchLink').innerHTML = newMerchCode;
	fadeIn('','',document.getElementById('merchLink'));
}

function toggleVideoEmbedCode() {
	el = document.getElementById('videoCode');
	el.style.display = (el.style.display=='block') ? 'none' : 'block';
	matchColumns();
}

function initRecipeHints() {
	linkEls = document.getElementsByTagName('A');
	for(i=0;i<linkEls.length;i++) {
		linkEl = linkEls[i];
		if (imgCode = linkEl.getAttribute('imgCode')) {
			addPreload('http://www.animalsaustralia.org/resources/resample.php?x=80&y=80&i=/documents/recipes/'+imgCode);
			linkEl.onmouseover = function() {
				document.getElementById(this.getAttribute('imgId')).src = 'http://www.animalsaustralia.org/resources/resample.php?x=80&y=80&i=/documents/recipes/'+this.getAttribute('imgCode');
				document.getElementById('link_'+this.getAttribute('imgId')).href = this.href;
			}
		}
	}
}




///////////////// SHARE NETWORK ///////////////
function initSN() {
	// look for SN spans
	spanEls = document.getElementsByTagName('SPAN');
	snId = 0;
	for(s=0;s<spanEls.length;s++) {
		sEl = spanEls[s];
		if (sEl.className=='sn') {
			// found one
			snId++;
			// find the info span
			ispanEls = sEl.getElementsByTagName('SPAN');
			for(is=0;is<ispanEls.length;is++) {
				isEl = ispanEls[is];
				if (isEl.className=='snInfo') {
					// found
					isEl.id = 'snInfo'+snId;
					break;
				}
			}
			// find links
			imgEls = sEl.getElementsByTagName('IMG');
			for(is=0;is<imgEls.length;is++) {
				imgEl = imgEls[is];
				imgEl.setAttribute('snTarget','snInfo'+snId);
				// set mouseover function
				imgEl.onmouseover = function() {
					document.getElementById(this.getAttribute('snTarget')).innerHTML = this.alt;
				}
				imgEl.onmouseout = function() {
					document.getElementById(this.getAttribute('snTarget')).innerHTML = '';
				}
			}
		}
	}
}
loadMeUp += "initSN();";



