/*
	Javascript code written by PSLWeb.co.uk for Hayley Edwards (www.rovingchef.net)
	Copyright ©2009 PSLWeb.co.uk - All Rights Reserved.
*/
/*
	Function:    mphr
	Called From: All web pages
	Description: Create dynamic document content for 'mailto' email invocation.
	Inputs:      id - Integer: Switching value to invoke different XHTML renderings.
	Outputs:     Dynamically created XHTML.
*/
function mphr(id) {
	var rcUser = new Array(null, 'enqu' + 'iries', 'enqu' + 'iries', 'Mihra' + 'norg', 'rogerpi' + 'zey',
			'fe' + 'ast', 'in' + 'fo', 'in' + 'fo', 'robert' + 'giorgione');
	var rcDom = 'rovingch' + 'ef.net';
	var yahooDom = 'yaho' + 'o.com';
	var gooDom = 'google' + 'mail.com';
	var fofDom = 'feastoff' + 'riends.co.uk';
	var fbmDom = 'fresherby' + 'miles.com';
	var hlDom = 'helen' + 'looker.co.uk';
	var hmDom = 'hot' + 'mail.com';
	switch (id) {
		case 1:
			document.write("Email: <a href=\"mai" + "lto:" + rcUser[id] + "@" + rcDom + "?subject=Enquiry\" title=\"Email Roving Chef\">" + rcUser[id] + "&#64" + rcDom + "</a>");
			break;
		case 2:
			document.write(", Email: <a href=\"mai" + "lto:" + rcUser[id] + "@" + rcDom + "?subject=Enquiry\" title=\"Email Roving Chef\">" + rcUser[id] + "&#64" + rcDom + "</a>");
			break;
		case 3:
			document.write("<a href=\"mai" + "lto:" + rcUser[id] + "@" + yahooDom + "?subject=Enquiry\">Canonbury Butchers</a>");
			break;
		case 4:
			document.write("<a href=\"mai" + "lto:" + rcUser[id] + "@" + gooDom + "?subject=Enquiry\">Roger Pizey</a>");
			break;
		case 5:
			document.write(", Email: <a href=\"mai" + "lto:" + rcUser[id] + "@" + fofDom + "?subject=Enquiry\">" + rcUser[id] + "&#64" + fofDom + "</a>");
			break;
		case 6:
			document.write("<a href=\"mai" + "lto:" + rcUser[id] + "@" + fbmDom + "?subject=Enquiry\">George Beech for Fruit &amp; Vegetables</a>");
			break;
		case 7:
			document.write("<a href=\"mai" + "lto:" + rcUser[id] + "@" + hlDom + "?subject=Enquiry\"> or email Helen Looker</a>");
			break;
		case 8:
			document.write("E Mail: <a href=\"mai" + "lto:" + rcUser[id] + "@" + hmDom + "?subject=Enquiry\">Robert Giorgione</a><br />");
			break;
		case 9:
			document.write(" please email <a href=\"mai" + "lto:" + rcUser[1] + "@" + rcDom + "?subject=Enquiry\" title=\"Email Roving Chef\">" + rcUser[1] + "&#64" + rcDom + "</a>");
			break;
		default:
			break;
	}
}

/*
	Class:        Slideshow
	Called From:  init
	Description:  Controls a Slideshow on a set of images.
	Inputs:       frameRate - Integer: No. of animation frames per second.
				  numOfImgs - Integer: No. of images in the animation (named "fade" + n).
				  rateOfFade - Float: Time in seconds for the fade effect.
				  rateOfPause - Float: Time in seconds for the image to remain static (between fades).
	Outputs:      None.
	Side-effects: DIV IDs slideshow1 and slideshow2 and Image IDs imgA and imgB have attributes altered.
*/
function Slideshow(frameRate, numOfImgs, rateOfFade, rateOfPause) {
	this.frameRate = frameRate; // Number of animation frames per second
	this.numImgs = numOfImgs; // Number of images in animation
	this.nextImg = 3; // Next image to load (after first fade from image 1 to image 2
	this.imgSwitch = true; // Toggle images
	this.fadeCount = 0; // Incremental count of setInterval cycles
	this.fadeRate = frameRate * rateOfFade; // Number of setInterval cycles in this fade
	this.cycleRate = 1000 / frameRate; // Number of milliseconds between setInterval calls
	this.imgStatic = rateOfPause * 1000; // Number of milliseconds to pause in setTimeout
	this.imgList = new Array();
	for (i = 1; i <= this.numImgs; i++) { // Load all images (first two should already be cached)
		this.imgList[i] = new Image;
		this.imgList[i].ready = false; // Image has not loaded
		this.imgList[i].onload = imageLoaded; // Defined later
		this.imgList[i].src = 'images/photos/fade' + i + '.jpg';
	}
	function imageLoaded() { // Invoked by an image's onload event
		this.ready = true; // Set the image's flag to denote it's ready to use
	}
	var loop = this; // Closure functions need to refer to the Class object
	this.startFade = function() { // Called by setTimeout
		loop.timer = setInterval(loop.fadeImage, loop.cycleRate);
	}
	this.fadeImage = function() { // Called by setInterval
		if (loop.fadeCount <= loop.fadeRate) { // Whilst we are still fading in/out
			var ssA = (loop.imgSwitch) ? document.getElementById('slideshow1') : document.getElementById('slideshow2');
			ssA.style.opacity = 1 - (loop.fadeCount / loop.fadeRate);
			ssA.style.MozOpacity = 1 - (loop.fadeCount / loop.fadeRate);
			ssA.style.KhtmlOpacity = 1 - (loop.fadeCount / loop.fadeRate);
			ssA.style.filter = 'alpha(opacity=' + eval(100 - (100 * loop.fadeCount / loop.fadeRate)) + ')';
			var ssB = (loop.imgSwitch) ? document.getElementById('slideshow2') : document.getElementById('slideshow1');
			ssB.style.opacity = loop.fadeCount / loop.fadeRate;
			ssB.style.MozOpacity = loop.fadeCount / loop.fadeRate;
			ssB.style.KhtmlOpacity = loop.fadeCount / loop.fadeRate;
			ssB.style.filter = 'alpha(opacity=' + eval(100 * loop.fadeCount / loop.fadeRate) + ')';
			loop.fadeCount++; // Increment counter
		}
		else { // We've completed the fade in/out
			var thisImg = (loop.imgSwitch) ? document.getElementById('imgA') : document.getElementById('imgB');
			// Find the next available image (i.e. loaded)
			var imgCount = 0;
			// If next image has not loaded skip it. Exit loop if no images are loaded (avoid infinite loop)
			while ((!(loop.imgList[loop.nextImg].ready)) && (imgCount < loop.numImgs)) {
				loop.nextImg++;
				if (loop.nextImg > loop.numImgs) // Cycle back to first image?
					loop.nextImg = 1;
				imgCount++;
			}
			thisImg.src = loop.imgList[loop.nextImg++].src; // 'old' image points to next image to view
			if (loop.nextImg > loop.numImgs) // Cycle back to first image?
				loop.nextImg = 1;
			loop.imgSwitch = !(loop.imgSwitch); // Flip the toggle flag
			loop.fadeCount = 0; // Reset counter
			clearInterval(loop.timer); // Stop calling this function
			setTimeout(loop.startFade, loop.imgStatic); // Re-start calling this function after a pause
		}
	}
	setTimeout(this.startFade, this.imgStatic); // Start calling fadeImage after a pause
}