	
	
	/* MINDING YOUR MIND - CSS JAVASCRIPT (script-css.js) - 
	   this file contains JavaScript for modifying CSS properties such as hiding/revealing images, changing borders, etc., 
	   and is included on all pages. */

	/* $(document).ready(function() {
		// NOTE: this will execute once document is ready on ALL pages!!!
		
	});	*/	
	
	function beginModalFadeOn(doneOpacity, objShowWhenDone, focusWhenDone, fadeInWhenDone) {
		// fade out entire page in preparation for showing modal dialog on top. below ID (objID) is the page cover div.
		/* params:
		 * 		doneOpacity = percentage of opacity to make modal dialog background (entire page)
		 * 		objShowWhenDone = container to display over modal background once done loading (optional)
		 * 		focusWhenDone = object to receive focus once process complete (optional)
		 * 		fadeInWhenDone = object to fade on (should start w/ 0 opacity) when complete (optional)
		 */
				
		var objID = "pageFader";
		if (document.getElementById) {
			// at this point, forget browsers that don't know this. 
			var obj = document.getElementById(objID);
			/* init opacity of cover to fully transparent before unhiding - BREAKS IE - for whatever
			 * reason, making this call causes the first fade on to not work in IE. however the cover,
			 * while transparent, will be visible and block the interface, but with no modal dialog.
			   not good!  */ 
			//setElementOpacity(obj, 0);
			
			// make cover div visible (note this function takes CSS ID, not the underlying browser object)
			//setElementVisibility(objID, 'v');
			setElementDisplay(objID, 'inline');
			
			// finally begin the fade on (also takes the CSS ID)
			fadeElement(objID, 0, 90, false);
			
			// have modal dialog appear and name field receive focus once modal background faded on
			waitToShowModal(doneOpacity, objShowWhenDone, focusWhenDone, fadeInWhenDone);
		}
	}
	
	function waitToShowModal(doneOpacity, objShowWhenDone, focusWhenDone, fadeInWhenDone) {
		// run interval check on opacity of modal background. once fade on is complete, show requested modal dialog. 
		/* params:
		 * 		doneOpacity = percentage of opacity to make modal dialog background (entire page)
		 * 		objShowWhenDone = container to display over modal background once done loading (optional)
		 * 		focusWhenDone = object to receive focus once process complete (optional)
		 * 		fadeInWhenDone = object to fade on (should start w/ 0 opacity) when complete (optional)
		 */
		
		// set up interval with direct function reference (supposedly more efficient than passing string)
		var myInterval = window.setInterval(function () {
			// this function will be created when interval is initiated and then re-used/re-called until interval is canceled
			if (document.getElementById) {
				// get object reference to background
				var obj = document.getElementById('pageFader');
				// check its current opacity
				var opacity = getElementOpacity(obj)*100;
				//setElementText('devdebug', 'opacity now is: ' + opacity.toString() + ', doneOpacity = ' + doneOpacity.toString());
				
				if (opacity >= doneOpacity) {
					// background is faded on, show modal dialog now
					
					// note: this hack will fix cursor bug for FF, but of course it makes for crazy positioning
					/* if ($.browser.mozilla) {
					     //alert("Firefox " + $.browser.version + " Sucks");
						 $('#visform :input').css('position', 'fixed');
					} */
					
					if (objShowWhenDone.length > 1)
						setElementDisplay(objShowWhenDone, 'block');
						
					if (fadeInWhenDone.length >1) {
						$('#'+fadeInWhenDone).fadeIn(1500, function () {

						});						
					}

					clearInterval(myInterval);
					
					// if requested object to receive focus, do it
					if (focusWhenDone.length > 1)
						document.getElementById(focusWhenDone).focus();
				}
			}
		},25);
			
		// set timer to clear this recursive function call in case somehow it was never completed above
		window.setTimeout(function() {clearInterval(myInterval);},6000);
	}
	
	function removeModal() {
		// remove modal dialog
		//setElementVisibility('modalDialogShell', 'h');
		setElementDisplay('modalDialogShell', 'none');
		// fade out background and remove once fade is complete
		fadeElement('pageFader', 90, 0, true);
		// pass normal dialog content to put back in once fade complete (avoid flash while hiding dialog)
		waitToHideModal(modalNormStr);
	}
	
	function waitToHideModal(defaultstr) {
		// run interval check on opacity of modal background. once fade OFF is complete, hide object. 
		
		// set up interval with direct function reference (supposedly more efficient than passing string)
		var myInterval = window.setInterval(function () {
			// this function will be created when interval is initiated and then re-used/re-called until interval is canceled
			if (document.getElementById) {
				// get object reference to background
				var obj = document.getElementById('pageFader');
				// check its current opacity
				var opacity = getElementOpacity(obj);

				if (opacity == 0) {
					// background is faded OFF, remove modal background now
					//setElementVisibility('pageFader', 'h');
					setElementDisplay('pageFader', 'none');
					// once hidden, return modal dialog to default content
					document.getElementById("modalDialogInner").innerHTML = defaultstr;
					clearInterval(myInterval);
				}
			}
		},25);
			
		// set timer to clear this recursive function call in case somehow it was never completed above
		window.setTimeout(function() {clearInterval(myInterval);},6000);
	}	
	
	function fadeElement(objID, startOpacity, doneOpacity, fadeOut) {
		// will fade requested element on or off. 
		// set startOpacity to initial value (usually 0) and doneOpacity to end value (usually 100)
		
		if (document.getElementById) {
			// get object reference to element to be faded
			var obj = document.getElementById(objID);
			// set initial opacity level
			setElementOpacity(obj, startOpacity);
			
			// set up interval with direct function reference (supposedly more efficient than passing string)
			var myInterval = window.setInterval(function () {
				// this function will be created when interval is initiated and then re-used/re-called until interval is canceled
	
				// check its current opacity
				var opacity = getElementOpacity(obj)*100;
				//setElementText('devdebug', 'opacity now is: ' + opacity.toString() + ', doneOpacity = ' + doneOpacity.toString());
				
				var fadeDone = false;
				if (fadeOut) {
					if (opacity > doneOpacity) 
						opacity -= 10;
					else
						fadeDone = true;
				} else {
						if (opacity < doneOpacity) 
						opacity += 10;
					else
						fadeDone = true;				
				}
				if (!fadeDone) {
					// not there yet, increment opacity
					setElementOpacity(obj, opacity);
				} else {
					// done, clear interval
					//setElementVisibility('pageFader', 'h');
					clearInterval(myInterval);
				}
				
			},25);	
			
			// set timer to clear this recursive function call in case somehow it was never completed above
			window.setTimeout(function() {clearInterval(myInterval);},6000);				
			
		}			
	}
	
	function fadeElementInOLD(objID, opacity, maxOpacity) {
		// OLD version of above, with string reference instead of direct function and recursive call on entire function. 
		// more compact, but I like above better
		
		// will fade requested element on. set opacity to initial value (usually 0) and maxOpacity to end value (usually 100)
		if (document.getElementById) {
			// at this point, forget browsers that don't know this. 
			var obj = document.getElementById(objID);
			if (opacity <= maxOpacity) {
				setElementOpacity(obj, opacity);
				opacity += 10;
				window.setTimeout("fadeElementIn('"+objID+"',"+opacity+","+maxOpacity+")", 25);
			}
		}
	}


	function setElementOpacity(obj, opacity) {
		// update opacity of element as requested. probably really only need the first and last versions,
		// but keeping the middle two in just to help some older browsers. 
		
		opacity = (opacity == 100)?99.999:opacity;
		  
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		  
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		  
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		 
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}
	
	function getElementOpacity(obj) {
		// try to retrive current opacity value of this object. if undefined, probably has not been set, so 
		// just return 1 (100%) which is effectively the value.

		var opacity = null;
		if (obj.filters) {
			opacity = obj.style.opacity;
		}
		else if (obj.style) {
			opacity = obj.style.opacity;
		} 
		if (opacity == null)
			opacity = 1;
		
		//alert('opacity = ' + opacity.toString());
		return opacity;
	}	
	
	function setElementDisplay (obj, mode) {
		// update display of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.display = mode;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.display = mode;
			}	
		}		
	}	
	
	function setElementVisibility (obj, mode) {
		// update visibility of element requested
		if (mode == "h")
			var setstyl = "hidden";
		else
			var setstyl = "visible";
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = setstyl;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = setstyl;
			}	
		}		
	}	
	
	function setElementText (obj, str) {
		// update HTML of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).innerHTML = str;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).innerHTML = str;	
			}	
		}		
	}	
	
	function getElementText (obj) {
		// get HTML of element requested
		var str;
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			str = document.getElementById(obj).innerHTML;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				str = document.all(obj).innerHTML;	
			}	
		}	
		return str;
	}	
	
	function setElementBkgdColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.backgroundColor = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.backgroundColor = clr;	
			}	
		}		
	}	
	
	function setElementColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.color = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.color = clr;	
			}	
		}		
	}
	
			  
	function hideOrShowItem (obj, stat) {
		var vis;
		if (stat == 1) {
			vis = "visible";
			lastVisDiv = obj;
		} else {
			vis = "hidden";
			lastVisDiv = "";
		}
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = vis;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = vis;	
			}	
		}
	}
	
	function toggleFldMode(obj, basenm) {
		var stat = null;
		var setstyl = null;
		var fldid;
		
		fldid = obj + '_id';
		//toggle mode from whatever it is now, so need to check current status
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			stat = document.getElementById(obj).style.visibility;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				stat = document.all(obj).style.visibility;	
			}	
		}
				
		//set to opposite of current status
		if (stat == 'visible')
			setstyl = 'hidden';
		else
			setstyl = 'visible';
					
		//now set mode of object	
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = setstyl;
			//disable the field if hidden, so only one field passed
			if (setstyl == 'hidden')
				document.getElementById(fldid).disabled = true;
			else
				document.getElementById(fldid).disabled = false;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = setstyl;
				//disable the field if hidden, so only one field passed
				if (setstyl == 'hidden')
					document.all(fldid).disabled = true;
				else
					document.all(fldid).disabled = false;	
			}
		}
		return setstyl;	
	}	
	
	function updateText(obj, str) {
		// update text of element requested - this is for debugging popup script above
		var str;
		str = str + "<br>" + getElementText(obj);
		setElementText (obj, str);
	}
	
	
	function toggleDivBorder(obj, idx, stat) {
		// roll off and on red border (in this case, default gray border blends into bkgd to avoid 1px image move)
		// this global page variable [currThumbIdx] must be defined on the calling page
		var bstr;
		var doit = 0;
		if (stat == 1) {
			bstr = "1px solid #FF0000";
			doit = 1;
		} else if (stat == 0 && idx != currThumbIdx) {
			bstr = "1px solid #E1E1E1";
			//bstr = "none";
			doit = 1;
		}
		
		if (doit) {
			if (document.getElementsByTagName && document.getElementById) {
				//Netscape 6+ model (also works in IE 6)
				document.getElementById(obj).style.border = bstr;
			} else {
				if (document.all) {
					//IE model (at least, versions prior to 6)
					document.all(obj).style.border = bstr;	
				}	
			}	
		}
	}
	
	/* SZT 01/12/09: added the following functions to generate postcard slideshow */
	
	// preload images in slideshow
	jQuery.preloadImages = function()
	{
	 // loop through and preload images
	  for(var i = 0; i<arguments.length; i++)
	  {
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	// set up and reveal the slideshow
	$(function(slideShowImages) {
		// on page load, set up the slideshow's image switch interval
		// uncomment line below to get slideshow playing automatically (instead of when button is clicked)
		// var playSlideshow = setInterval( "slideSwitch()", 4000 );	
		
		// preload images - hopefully it does
		$.preloadImages(slideShowImages);
				
		// let's make the pause button inactive to start - you can't pause what hasn't started yet
		$("#slideshowPause").addClass('inactive');
		
		// give a status message
		$("#slideshowStatus").html("(click start to play)");
		
		$("#slideshowStart").click(function() 
		{					
			// toggle display - and slidedown/slideup effect - of slideshow; div style is set with "display:none"
			if ($("#slideshowContainer").is(":hidden")) 
			{
				slideStartIt();
				$("#slideshowContainer").slideDown("slow");	
				$("#slideshowStart").html("click to hide postcard slideshow");
			} else {
				slidePauseIt();
				$("#slideshowContainer").slideUp('slow');					
				$("#slideshowStart").html("click to view postcard slideshow");
			}								
		});			
		
		$("#slideshowRestart").click(function()
		{
			// if restart button is clicked, run function to restart slideshow (from where it left off)
			slideStartIt();
		});
		
		$("#slideshowPause").click(function() 
		{
			// if pause button is clicked, run function stop slideshow
			slidePauseIt();
		});		
	});
		
	// helper function to switch visible image in slidshow
	function slideSwitch() {
		// switch to new visible image
        var $active = $('#slideshow IMG.active');
    
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    
        var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
    
        $active.addClass('last-active');
    
        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
        });		
    }
	
	// helper function to stop slideshow
	function slidePauseIt() 
	{
		// clear out switch interval to stop slidshow
		playSlideshow = clearInterval(playSlideshow);
		
		// once pause button is clicked, make it inactive and toggle the other
		$("#slideshowPause").addClass('inactive');
		$("#slideshowRestart").removeClass('inactive');
		
		// update status message
		$("#slideshowStatus").html("(paused: click start to play)");
	}	
	
	// helper function to start/restart slideshow
	function slideStartIt()
	{
		// reset switch interval to start slideshow
		playSlideshow = setInterval( "slideSwitch()", 4000 );
		
		// once start button (or slideshow is opened) is clicked, make it inactive and toggle the other
		$("#slideshowRestart").addClass('inactive');
		$("#slideshowPause").removeClass('inactive');	
		
		// update status message
		$("#slideshowStatus").html("(playing)");
	}