	/* special sfx styles */
var sfx = {
	
	slideshowDirectory 	: "",
	slideshowTarget		: "",
	slideshowImages 	: [],
	slideshowSlide 		: 0,
	slideshowFadeSpeed  : 500,
	slideshowDelay		: 4000,
	slideshowPaused		: true,
	
	fadeSpeed			: 500,
	
	expandFps           : 50,
	expanding			: false,
	
	timer				: 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;
	    }
	    //	ensure that object is visable to fade in
	    if( dom.cssStyle(obj, "display") == "none" || obj.style.display == "none"){
	    	sfx.setOpacity(obj, 0);
	    	obj.style.display = "block";
	    }
	    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)
	{
		//	was closed by expandClose.
		if( obj.style.display == "none" && obj.style.height.replace("px", "") == 0 ){
			obj.style.overflow = "hidden";
			obj.style.height   = "0px";
			obj.style.display  = "";	
		}else if(dom.hasClass(obj, "hide")){
			/*
			if( obj.style.display == "none" ){
				obj.style.height   = "0px";
				//obj.style.display  = "block";
				obj.style.overflow = "hidden";
			}
			*/
		}else if(dom.hasClass(obj, "noshow")){
			obj.style.overflow = "hidden";
			obj.style.height   = "0px";
			obj.style.display  = "";
			dom.swapClass([obj], "noshow", "");		
		}
		//	get basic inner height;
		if( !expandToHeight ){
			//	make sure not a text node
			if( obj.firstChild.nodeType == 3 ){
				obj.removeChild(obj.firstChild);
			}
			expandToHeight = parseInt(obj.firstChild.offsetHeight);
		}
		var h = parseInt(obj.style.height.replace("px", ""));
		
		if( h <= expandToHeight ){
		
			//var offset = obj.offsetHeight;
			var pixels = sfx.expandFps;
			sfx.expanding = true;
						
			if( (expandToHeight - h) < pixels ){
				//	deaccelerate
				pixels = Math.floor((expandToHeight - h) / 2);	
				//	ensure that overflow pixels aren't encountered
				if( pixels <= 1 ){
					obj.style.height = expandToHeight + 'px';
					sfx.expanding    = false;
					return false;
				}
			}
			obj.style.height = (h + pixels) + 'px';
			setTimeout(function(){ sfx.expandOpen(obj, expandToHeight); }, sfx.expandFps);
		}
		return true;
	},	
	
	expandClose : function(obj)
	{
		var h = obj.style.height.replace("px", "");
		if( h == "" ){
			h = obj.offsetHeight;
		}
		//dom.debug(h);
		if( parseInt(h) <= 0 ){
			obj.style.height  = "0px";
			obj.style.display = "none";
			sfx.expanding = false;
			return false;
		}else{
			sfx.expanding      = true;
			obj.style.overflow = "hidden";
			//	decelerate, if it needs too
			var pixels = (  h < sfx.expandFps ? h/2 : sfx.expandFps ); 
			obj.style.height   = parseInt((h - pixels))+"px";
			//dom.debug(pixels);
			setTimeout(function(){ sfx.expandClose(obj); }, sfx.expandFps);
		}
		return true;
	},
	
	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( !sfx.expanding ){
			if( dom.getHeight(obj) != 0 ){
				sfx.expanding  = true; 
				sfx.expandClose(obj);
			}else{
				sfx.expanding  = true; 
				sfx.expandOpen(obj, openTo);
			}
		}
	},
	
	flash : function(obj, expires, millisec)
	{
		if( !millisec ) millisec = 200;
		
		if( obj instanceof Object === false){
			obj = dom.byId(obj);
		}
		
		if( !expires || expires > 0 ){
			setTimeout(
				function(){ 
					sfx.fade(obj, 101, 30, millisec);
					setTimeout(
						function(){ 
							sfx.fade(obj, 30, 101, millisec);
							sfx.flash(obj, ( expires || expires !== false ? expires - (millisec*2) : false), millisec);
						}
					, millisec);
				}
			, millisec);
		}else{
			sfx.fade(obj, sfx.getOpacity(obj), 101, millisec);	
		
		}
		return;
	}
}
