﻿//============================================================================
// Primary javascript file for the web site www.wildhare.ca
//
// Copyright (c) Wild Hare Productions 2010. All rights reserved.
// Portions of this file are copyright their respective owners.
// Copyright notice for these portions is give as appropriate.
//============================================================================


//=============================================================================
// This function masks e-mail addresses so spam-bots can't farm them.
// Any, or all, of the variables can be left blank and this routine will
// set the default values.
//=============================================================================
function makemail(name,domain,subj)
{
	if (name == "") 	name = "BobEverson";
	if (domain == "")	domain = "WildHare.ca";
	if (subj == "")		subj = "Wild Hare Photography";
		
	document.location.href = "mail" + "to:" + name + "@" + domain + "?subject=" + subj; 
}


//============================================================================
//============================================================================
function initCorners() {

	var allround =	{ tl: { radius: 20 }, tr: { radius: 20 }, bl: { radius: 20 }, br: { radius: 20 }, antiAlias: true }
	var topround =	{ tl: { radius: 16 }, tr: { radius: 16 }, bl: { radius:  0 }, br: { radius:  0 }, antiAlias: true }
	var btmround =	{ tl: { radius:  0 }, tr: { radius:  0 }, bl: { radius: 16 }, br: { radius: 16 }, antiAlias: true }

 
	// CurvyCorners Usage:
	//	curvyCorners(settingsObj, selectorStr);
 	//	curvyCorners(settingsObj, Obj1[, Obj2[, Obj3[, . . . [, ObjN]]]]);
 	//	
 	//	selectorStr ::= complexSelector [, complexSelector]...
	//	complexSelector ::= singleSelector[ singleSelector]
	//	singleSelector ::= idType | classType
	//	idType ::= #id
	//	classType ::= [tagName].className
	//	tagName ::= div|p|form|blockquote|frameset // others may work
	//	className : .name
	//	selector examples:
	//	#mydiv p.rounded
	//	#mypara
	//	.rounded
    curvyCorners(allround, "#container");
    curvyCorners(topround, "#header");
    curvyCorners(btmround, "#footer");
    curvyCorners(allround, ".bluetext");
    curvyCorners(allround, ".greytext");
    curvyCorners(allround, ".redtext");
    curvyCorners(allround, ".whitetext");
    curvyCorners(allround, ".yellowtext");
  }



//============================================================================
//	The code in this next block supports the filmstrip slideshow.
//============================================================================

// The delay times used between shuttered frame updates
var FrameDelay =  6000;
var ShutterDelay = 800;

function CacheImage(ImageSource) {	// Turns a string into an image object
	var ImageObject = new Image();
	ImageObject.src = ImageSource;
	return ImageObject;
}


function ShowSlide(FrameNum) {
	if (SlideReady) {
		NextSlide = CurrentSlide + 1;
		if (NextSlide == Slides.length)
		{
			CurrentSlide = -1;
			NextSlide = 0;
		}

		document.images['frame'+FrameNum].src = Slides[NextSlide].src;
		CurrentSlide = NextSlide++;
		CacheNextSlide();
      return true;
   }
}


function Download() {
//   if (Slides[NextSlide].complete) {
//      SlideReady = true;
//   }
//   else setTimeout("Download()", 100); // CHECKS DOWNLOAD STATUS EVERY 100 MS
   return true;
}


function CacheNextSlide() {
	// ONLY CACHES THE IMAGES ONCE
	if ((NextSlide < Slides.length) && (typeof Slides[NextSlide] == 'string')) { 
//		SlideReady = false;
		Slides[NextSlide] = CacheImage('images/filmstrip/' + Slides[NextSlide]);
		Download();
	}
   return true;
}


function StartSlideShow() {
	CurrentSlide = -1;
	Slides[0] = CacheImage('images/filmstrip/' + Slides[0]);
	SlideReady = true;
	ShowSlide(1);
	ShowSlide(2);
	ShowSlide(3);

	setTimeout("ShowFrame(1)", 6000);
}


function ShowFrame(FrameNum) {
	// Starts the shutter animation, changes the slidshow image, and calls itself to start the process all over.
	document.images['shutter'+FrameNum].src = 'images/shutter'+FrameNum+'.gif';
	setTimeout("ShowSlide("+FrameNum+")", ShutterDelay);
	if (FrameNum == '1') setTimeout("ShowFrame(2)",  3000);
	if (FrameNum == '2') setTimeout("ShowFrame(3)",  3000);
	if (FrameNum == '3') setTimeout("ShowFrame(1)", 10000);
}


function ShowAllFrames() {
	//	Places three random images into the filmstrip area.
	var sld, frm;
	for (frm = 1; frm < 4; frm++ ) {
		do
			sld = Math.round(Math.random()* Slides.length);
		while (typeof Slides[sld] != 'string');
		Slides[sld] = CacheImage('images/filmstrip/' + Slides[sld]);
		document.images["frame" +frm].src = Slides[sld].src;
	}
}
