//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Description: This javaScript is to generate sequence/random picture & altTag.
//  Programmer: hat
// Function(s): getRandomNum();, genRotPic();, startFade(); & getRotPicEH().
//   Tested on: IE6.0, Netscape7.1
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* Sample calls
	<script src="../includes/scripts/genRotPic.js"></script>
	<script language="JavaScript" type="text/javascript">
		var maxPic = 1 + 16;	//start from ZERO, 1 plus last images number
		var maxTag = 1;	//1 or equal to total maxPic
		var imgPrefix = "images/main";
		var imgSuffix = "gif";
		var tagAttb = "";	//tag attribute, ex: align=right
		var objImg = "document.images.mainPhoto";
		var fadeType = "";	//default as sequence, r for random.
		//--DO NOT Change below line--------
		var altTag = new Array(maxTag);
		//--add more altTags here-----------
		altTag[0]="";
		//[more altTags here...]
		//genRotPic(maxPic, maxTag, imgPrefix, imgSuffix, tagAttb);
		startFade(maxPic, maxTag, imgPrefix, imgSuffix, objImg, fadeType);
	</script>
	<noscript>
		<img src="images/main.gif" border="0" alt="" align="right">
	</noscript>
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// config - global variables
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	var debug = false;
	var getPNum = 0;	//default picture number
	var getTNum = 0;	//default tag number
	var fadeSpeed = 60*60*2;
	var fadeDuration = 3;
	var timerID;
	var i = 0;
	var tobjImg, cobjImg;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call getRandomNum() function to generate random number by passing max picture number (for rotate)
// and max alt tag.
// Ex:  getRandomNum(maxPic, maxTag);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function getRandomNum(maxPic, maxTag) {
		window.onerror = getRotPicEH;
		var num;
//		var dateNow = new Date();
//		var num= Math.abs(Math.sin(dateNow.getTime()/1000));
		if( !(num = Math.random()) ) return 0;
		num = num * maxPic;
		if(num > maxPic){
			num = 0;	//reset
		}
		var tmp = ""+num;
		tmp = tmp.substr(0, tmp.indexOf('.'));
		getPNum = tmp;	//get picture number
		if(maxTag == maxPic){
			getTNum = getPNum;
		}
	}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call genRotPic() function to generate rotate picture image code by passing max picture
// number, max alt tag, image prefix, image suffix (extension), image attribute.
// Ex:  genRotPic(maxPic, maxTag, '../images/family', 'gif', 'aligh=right');
// Note: you would name your pictures as family0, family1, family2 and follow. (maxPic=1+2)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function genRotPic(maxPic, maxTag, imgP, imgS, tagAttb) {
		window.onerror = getRotPicEH;
		getRandomNum(maxPic, maxTag);
		document.write("<img " +"src='"+ imgP + getPNum +"."+ imgS +"' "+ tagAttb +" border=0 alt='"+ altTag[getTNum] +"'"+ ">");
	}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call startFade() function to generate fade pictures (transition) by passing max picture
// number, max alt tag, image prefix, image suffix (extension), image object, fade type
// (sequence or random).
// Ex:  <img id="mainPhoto" src="images/main.gif" border="0" alt="Photo: Children & Family">
//		startFade(maxPic, maxTag, 'images/main', 'gif', 'document.images.mainPhoto', fadeType)
// Note: you would name your pictures as main0, main1, main2..10. (maxPic=1+10)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function startFade(maxPic, maxTag, imgP, imgS, objImg, fadeType) {
		window.onerror = getRotPicEH;
		var tmpRun;
		var j = 0;
		tobjImg = objImg;
		cobjImg = eval(objImg);
		if(i >= maxPic){ i = 0; }
		if (document.all){
			cobjImg.style.filter="blendTrans(duration=2)";
			cobjImg.style.filter="blendTrans(duration="+fadeDuration+")";
			cobjImg.filters.blendTrans.Apply();
			cobjImg.src = ""+ imgP + i +"."+ imgS;
			cobjImg.alt = ""+ altTag[getTNum];
			cobjImg.filters.blendTrans.Play();
		}
		if(fadeType == "r"){
			getRandomNum(maxPic, maxTag);	//random number
			i = getPNum;
		} else {
			i++;	//sequence number
			if(maxTag == maxPic){
				getTNum = i;
			}
		}
		tmpRun = "startFade("+maxPic+", "+maxTag+", '"+imgP+"', '"+imgS+"', '"+tobjImg+"', '"+fadeType+"')";
		timerID = setTimeout(tmpRun, fadeSpeed);
	}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call getRotPicEH function for error handler
// Ex:  window.onerror = getRotPicEH;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function getRotPicEH() {
		if (debug) { alert("Error: genRotPic Javascript"); }
		return true;
	}