	/* special sfx styles */
var sfx = {
	
	slideshowDirectory 	: "",
	slideshowTarget		: "",
	slideshowImages 	: [],
	slideshowSlide 		: 0,
	slideshowFadeSpeed  : 500,
	slideshowDelay		: 4000,
	slideshowPaused		: true,
	
	fadeSpeed			: 500,
	expandFps           : 15,
	expanding			: false,
	
	
	preloadSlideshow : function(images)
	{
		for(var i = 0; i < images.length; i++){
			//	preload the images		
			var img = new Image();
			img.src = sfx.slideshowDirectory + images[i];
			//	add to stored image array
			sfx.slideshowImages.push(img);
		}
		for(var t = 0; t < sfx.slideshowImages.length; t++){
			//dom.debug(sfx.slideshowImages[t].src);
		}
	},	
	
	/*
	IF the gallery has thumbnails in which one must select to view larger image, setup the on click event for the onclick event
	thumbArea(obj or id) = is the div/container where the A tags for the thumb nails sit.
	*/
	setupThumbControl : function(thumbArea, classOn)
	{
		//dom.debug(sfx.slideshowImages[0].src);
		if( typeof(thumbArea) == "string" ){
			thumbArea = document.getElementById(thumbArea);
		}
		var thumbs = thumbArea.getElementsByTagName("A");
		for(var t = 0; t < thumbs.length; t++){
			thumbs[t].onclick = function(e){
				var a = dom.getEventElement(e);
				if( (classOn && a.className != classOn) || !classOn ){
					
					for(var i = 0; i < thumbs.length; i++){
						//	reset class on
						if( classOn ) thumbs[i].className = "";
						//	find the key for the larger slideshowImages array
						if( thumbs[i] == a ){ 
							//alert(sfx.slideshowImages[i].src);
							//dom.debug("- key:"+ i +" image:"+sfx.slideshowImages[0].src);
							var key = i;
							if( classOn ) a.className = classOn;
						}
					}
					//	show clicked larger image
					sfx.gotoSlideshow(key);
				}
				dom.cancel(e);
			}
		}
	},
	
	//	controls = 
	slideshow : function()
	{
		//	is slide show paused
		if( sfx.slideshowPaused ) {return false;}
		
		sfx.slideshowSlide++;
		if( sfx.slideshowSlide == sfx.slideshowImages.length  ){
			sfx.slideshowSlide = 0;
		}
		setTimeout(
			function(){ 
				//	is slide show paused
				if( sfx.slideshowPaused ) {return false;}
		
				sfx.fade( dom.byId(sfx.slideshowTarget), 101, 0, sfx.slideshowFadeSpeed );
				setTimeout(
					function(){ 
						dom.byId(sfx.slideshowTarget).src = sfx.slideshowImages[sfx.slideshowSlide].src;
						sfx.fade( dom.byId(sfx.slideshowTarget), 0, 101, sfx.slideshowFadeSpeed );
						sfx.slideshow();
					}, sfx.slideshowFadeSpeed);
					/*	check this works.... */
					return true; 
			}, sfx.slideshowDelay);
		return true;
	},
	
	
	//	select the image by its array key. and go to it.
	gotoSlideshow : function(key)
	{
		//dom.debug(sfx.slideshowImages[key].src);	
		sfx.fade( dom.byId(sfx.slideshowTarget), 101, 0, sfx.slideshowFadeSpeed );
		sfx.slideshowSlide = key;
		setTimeout(
			function(){
				dom.byId(sfx.slideshowTarget).src = sfx.slideshowImages[sfx.slideshowSlide].src;
				sfx.fade( dom.byId(sfx.slideshowTarget), 0, 101, sfx.slideshowFadeSpeed );
			}, sfx.slideshowFadeSpeed
		);
	},
	
	
	pauseSlideshow : function()
	{	
		sfx.slideshowPaused = true;
	},
	
	
	playSlideshow : function()
	{
		if( sfx.slideshowPaused ){
			sfx.slideshowPaused = false;
			sfx.slideshow();
		}
	},
	
	//	this is for when a single button controls both pause and play
	autoSlideshow : function()
	{
		if( sfx.slideshowPaused ){
			sfx.playSlideshow();
		}else{
			sfx.pauseSlideshow();
		}	
	},
	
	
	
	/* *********************************************
	set opacity of oject via inline style
	********************************************* */
	setOpacity : function( obj, value )
	{
		if( obj ){
			obj.style.opacity 	   = (value/101).toFixed(2);  
			obj.style.MozOpacity   = (value/101).toFixed(2);
			obj.style.KhtmlOpacity = (value/100).toFixed(2);
			obj.style.filter = "alpha(opacity=" + value + ")"; 
		}
	},
	
	
	/* *********************************************
	gets opacity of object, inline stlye or by class
	********************************************* */
	getOpacity : function(obj)
	{
		//	ensure that a number is returned
		var opac = parseFloat(obj.style.opacity);
		//	if opacity is not set
		if( isNaN(opac) ){
			sfx.setOpacity(obj, 100);
			return sfx.getOpacity(obj);
		}else{
			var str = String(opac);
			if( str.indexOf(".") != -1){
				opac = str.substring(str.indexOf(".")+1, str.length);
			} 	
		}
		return opac;
	},

	
	fade : function(obj, start, end, millisec)
	{
		var speed = Math.round(millisec/100);
		var timer = 0;	    sfx.getOpacity(obj);
		if( start > end ){
	    	for(var i = start; i >= end; i--){
	        	setTimeout(function(){ sfx.setOpacity(obj, start--); }, (timer*speed));
	        	timer++;
	        }
	    }else if(start < end){
	    	for(var i = start; i <= end; i++){	            setTimeout(function(){ sfx.setOpacity(obj, start++); }, (timer*speed));
	            timer++	        }
	    }
	},
	
	
	fadeIn : function(obj, millisec)
	{
		if( !millisec ){
	    	millisec = sfx.fadeSpeed;
	    }
	    sfx.fade(obj, 0, 101, millisec);
	}, 
	
	fadeOut : function(obj, destroy, millisec)
	{
		if( !millisec ){
	    	millisec = sfx.fadeSpeed;
	    }
	    sfx.fade(obj, 101, 0, sfx.fadeSpeed);
	    //	remove item from display
	    if( destroy ){
	    	setTimeout(function(){ obj.style.display = "none"; }, millisec);
	    }
	}, 
	
	
	expandOpen : function(obj, expandToHeight)
	{
		var offset = obj.offsetHeight;
		var pixels = sfx.expandFps;
		sfx.expanding     = true;
		
		if( obj.style.display == "none" ){
			obj.style.height   = "0px";
			obj.style.display  = "block";
		}
		
		if( (expandToHeight - offset) < pixels ){
			//	deaccelerate
			pixels = Math.floor((expandToHeight - offset) / 2);	
			//	ensure that overflow pixels aren't encountered
			if( pixels <= 1 ){
				obj.style.height = expandToHeight + 'px';
				sfx.expanding    = false;
				return;
			}
		}
		obj.style.height = (obj.offsetHeight + pixels) + 'px';
		var t = setTimeout(function(){ sfx.expandOpen(obj, expandToHeight); }, sfx.expandFps);
		 
	},
	
	
	expandClose : function(obj)
	{
		var offset = obj.offsetHeight;
		var pixels = sfx.expandFps;
		sfx.expanding     = true;
		
		pixels = Math.floor((offset - pixels)/2) ;
			if( pixels <= 0 ){
				obj.style.height  = "0px";
				obj.style.display = "none";
				sfx.expanding = false;
				return;
			}
		obj.style.height = (obj.offsetHeight - pixels ) + 'px';
		setTimeout(function(){ sfx.expandClose(obj); }, sfx.expandFps);
	},
	
	
	expandPanesSwitch : function(closeObj, openObj, openTo)
	{
		if( closeObj != openObj && !sfx.expanding ){
			sfx.expanding     = true;
			sfx.expandClose(closeObj);
			sfx.expandOpen(openObj, openTo);
		}
	},
	
	expandPane : function(obj, openTo)
	{
		if( dom.getHeight(obj) != 0 ){
			sfx.expanding  = true; 
			sfx.expandClose(obj);
		}else{
			sfx.expanding  = true; 
			sfx.expandOpen(obj, openTo);
		}
	}
}
