// ---
/*
	JaS is developed by Robert Nyman, http://www.robertnyman.com
	For more information, please see http://www.robertnyman.com/jas
*/
var JaS = {
	// Customization parameters
	imagePath : "../images/",
	images : [	
		/*[image path, image alt, Image category, width, height, Description */
		
		/* Telecom components images */
		/*["telecom/telcomp/bias_t", "Bias-T", "Telecom Components", "360", "509",""],
		["telecom/telcomp/dc_block", "DC Block", "Telecom Components", "360", "509",""],
		["telecom/telcomp/inline_meter", "Inline Test Kit", "Telecom Components", "360", "509",""],
		
		/* Telecom systems images */
		/*["telecom/telsyst/cleansite_7782", "Cleansite Antenna", "Telecom Systems", "360", "509","Cleansite antenna with uses the Powerwave 7782 antenna."],
		["telecom/telsyst/delphius_monopole", "Delphius Monopole Antenna", "Telecom Systems", "360", "509",""],
		["telecom/telsyst/compact_monopole_antenna", "Compact Monopole Antenna", "Telecom Systems", "360", "509",""],
		["telecom/telsyst/scissor_mast", "Scissor Mast", "Telecom Systems", "360", "509",""],
		
		/* Microwave components images */
		["industrial/mwcomp/90_e_bend_915mhz", "90deg E Bend (915MHz)", "MW Components", "360", "509", "Used to bend waveguide 90deg in the E-plane"],
		["industrial/mwcomp/90_h_bend_915mhz", "90deg H Bend (915MHz)", "MW Components", "360", "509", "Used to bend waveguide 90deg in the H-plane"],
		["industrial/mwcomp/180_bend_915mhz", "180deg Bend (915MHz)", "MW Components", "360", "509", "Used to bend waveguide 180deg"],
		["industrial/mwcomp/splitter_915mhz", "Splitter (915MHz)", "MW Components", "360", "509", "The splitter network is used to adjust the power between two ports of the splitter. By turning the tune screw in the middle, the balance between the two ports is adjusted. Motorised splitters are also available which can be controller by a computer or other device."],
		["industrial/mwcomp/t-splitter_915mhz", "T-Splitter (915MHz)", "MW Components", "360", "509", "The T-splitter is a combination of the splitter network and the stub tuner. The power can be split into the two legs by turing the tune screw in the middle of the unit. To minimise the reflected power, the stub tiner on each leg can be adjusted."],
		["industrial/mwcomp/stub_tuner_915mhz", "Stub Tuner (915MHz)", "MW Components", "360", "509", "Stub tuners are designed for impedance matching in high power microwave heating systems. The impedance matching is done to reduce the amount of reflected power from the load. This tuner operates at 915MHz."],
		["industrial/mwcomp/stub_tuner_2-45ghz", "Stub Tuner (2.45GHz)", "MW Components", "360", "509", "Stub tuners are designed for impedance matching in high power microwave heating systems. The impedance matching is done to reduce the amount of reflected power from the load. This tuner operates at 2.45GHz"],
		["industrial/mwcomp/waveguide_coax_915mhz", "Waveguide to Coax Adaptor (915MHz)", "MW Components", "360", "509", "These adaptors are used to convert the microwave energy from waveguide form to cable form and visa versa."],
		["industrial/mwcomp/waterload_915mhz", "Waterload (915MHz)", "MW Components", "360", "509", "Waterloads are used to sink any reflected power from the load to protect the generator."],
		["industrial/mwcomp/pressure_window_915mhz", "Waveguide Pressure Window (915MHz)", "MW Components", "509", "360", "Waveguide pressure windows are used as gas barriers in waveguide systems, or to prevent the ingress of moisture into the waveguide."],
		["industrial/mwcomp/dbl_w-guide_2-45ghz", "Double Magnetron Waveguide (2.45GHz)", "MW Components", "360", "509", "This waveguide is used to combine two generators into one waveguide. The one is in the E-plane, the other in the H-plane."],
		["industrial/mwcomp/mw_launch_2-45ghz", "Microwave Launch (2.45GHz)", "MW Components", "360", "509", "A Microwave Launch is used to connect a standard microwave oven magnetron to the waveguide."],
		
		/* Microwave systems images */
		["industrial/mwsyst/perspex_recycler", "Perspex Recycler (2.45GHz)", "MW Systems", "509", "360", "Delphius developed a 75kW microwave process for the recycling of Perspex. It is the only feasible alternative to the conventional process, employing molten lead."],
		["industrial/mwsyst/treatment_of_starch", "Treatment of Starch", "MW Systems", "509", "360", "This microwave oven is used to dry and treat starches using 6kW of microwave power. The applicator employs a fluidised bed of hot process air to provide mixing of the product and to move it through the vessel."],
		["industrial/mwsyst/ribbon_blender_1", "Ribbon Blender Power Supplies (2.45GHz)", "MW Systems", "360", "509", ""],
		["industrial/mwsyst/microwave_pasteuriser_2", "Microwave Pasteuriser 2 (2.45GHz)", "MW Systems", "509", "360", "This microwave equipment is used for the pasteurisation of shell eggs. Microwave and hot air ovens to heat the eggs to pasteurisation temperature and maintains the temperature to achieve pasteurization"],
		["industrial/mwsyst/microwave_pasteuriser_3", "Microwave Pasteuriser 3 (2.45GHz)", "MW Systems", "509", "360", "Eggs are moved through the oven on a conveyor which continuously turns the eggs for even pasteurisation"],
		["industrial/mwsyst/microwave_sintering_oven_1", "Microwave Sintering Oven 1 (915MHz)", "MW Systems", "509", "360", "Microwave sintering oven suitable for microwave power levels to 100kW at 915MHz."],
		["industrial/mwsyst/microwave_sintering_oven_2", "Microwave Sintering Oven 2 (915MHz)", "MW Systems", "509", "360", "Microwave sintering oven which also incorporates conventional heater elements."],
		
		/* RF components images */
		["industrial/rfcomp/2kw_rf_gen_13mhz", "2kW RF Generator (13.56MHz)", "RF Components", "509", "360", "2kW RF generator in 19&quot; sub rack 4U high. This generator is water cooled and can be controlled remotely. The LCD displays forward and reflected powers"],
		["industrial/rfcomp/attenuator_13mhz", "RF Attenuator (13.56MHz)", "RF Components", "360", "509", "Selectable attenuator. This attenuator can be set for either 1dB or 2dB attenuation."],
		["industrial/rfcomp/matching_network_13-56mhz_1", "Matching Network Top (13.56MHz)", "RF Components", "509", "360", "Automatic matching network custom designed to meet the material characteristics. Image shows two capacitors in an L topology. This network is designed to handle 300kW RF power at 13.56MHz."],
		["industrial/rfcomp/matching_network_13-56mhz_2", "Matching Network Side (13.56MHz)", "RF Components", "509", "360", "Automatic matching network custom designed to meet the material characteristics. Image shows the side where all controlling components are located. A controller measures the forward and reflected power and turns two stepper motors which tunes the network in order to ensure maximum power is delivered to the material."],
		
		/* RF systems images */
		["industrial/rfsyst/50kw_rf_gen_13mhz", "50kW RF Generator (13.56MHz)", "RF Systems", "360", "509", "This system was originally a free oscillating system but was upgraded by us to a fix frequency of 13.56MHz at 50kW RF power into a 50ohm load."],
		["industrial/rfsyst/50kw_rf_gen_supplies_13mhz", "50kW RF Generator Supplies (13.56MHz)", "RF Systems", "360", "509","Generator auxillary supplies where custom designed by us. The system is driven by our 1kW RF generator (top unit) which occilates at 13.56MHz."],
		["industrial/rfsyst/300kw_rf_gen_13mhz", "300kW RF Generator (13.56MHz)", "RF Systems", "360", "509", "Delphius designed and built this system to deliver 300kW of RF power at a fixed frequency of 13.56MHz into material in order to dry it in the shortest amount of time."],
		["industrial/rfsyst/300kw_rf_gen_out_13mhz", "300kW RF Generator Output Circuit (13.56MHz)", "RF Systems", "509", "360", "The output network consists of a PI topology which is tuned to 13.56MHz."],
		["industrial/rfsyst/300kw_rf_gen_supplies_13mhz", "300kW RF Generator Supplies (13.56MHz)", "RF Systems", "360", "509", "These auxilary supplies where designed by us. The system is driven by our 2kW RF generator (middle unit) which oscillates at 13.56MHz."],
		["industrial/rfsyst/300kw_rf_gen_status_13mhz", "300kW RF Generator Status Board (13.56MHz)", "RF Systems", "509", "360", "A PLC is used to control the RF generator. It displays any internal errors on a LED display for easy fault finding."],
		["industrial/rfsyst/rf_tunnel_13.56mhz", "RF Tunnel (13.56MHz)", "RF Systems", "509", "360", "The tunnel has a 500mm wide conveyor, with a 1.5m heating zone. Two, 10kW RF generators supply the RF power to the two electrode systems, each with its automatic impedance matching unit. This allows accurate moisture profiling to be done."],
		["industrial/rfsyst/rf_tunnel_13.56mhz_model", "RF Tunnel Model (13.56MHz)", "RF Systems", "509", "360", "Infrared sensors monitor the temperature of the product entering and exiting the tunnel."],
		
		/* Measurement systems images */
		["industrial/measure/furnace", "Furnace", "Measurement", "360", "509", "Microwave furnace to measure dielectric constant and dielectric loss factor or resistivity of materials at all the allocated RF and microwave heating frequencies."],		
		["industrial/measure/lab_microwave_1", "Lab Microwave 1 (2.45GHz)", "Measurement", "509", "360", "Microwave oven for measurements on larger samples."],
		["industrial/measure/lab_microwave_2", "Lab Microwave 2 (2.45GHz)", "Measurement", "509", "360", "The microwave oven has a scale which constanly measures the product mass. A heat gun can also be attached to test processes with conventional heating as well."],
		["industrial/measure/monomode_cavity_1_2-45ghz","Monomode Cavity 1", "Measurement", "360", "509", ""],
		["industrial/measure/monomode_cavity_2_2-45ghz","Monomode Cavity 2", "Measurement", "509", "360", ""],
		["industrial/measure/monomode_cavity_3_2-45ghz","Monomode Cavity 3", "Measurement", "360", "509", ""],
		["industrial/measure/heating_trail_example", "Heating Trail Example", "Measurement", "509", "360", "Typical data collected through measurements done by Delphius."],
					
		["industrial/measure/power_meter_2-45ghz", "Power Meter (2.45GHz)", "Measurement", "360", "509", "Microwave power meter which can be placed inline with existing systems. This unit measures forward and reflected power in either dBm or Watts."],
		["industrial/measure/vswr_meter_2-45ghz", "VSWR Meter (2.45GHz)", "Measurement", "360", "509", "Microwave VSWR meter which can be placed inline with existing systems. This unit measures magnitude and phase information."],
		
		["industrial/measure/handheld_leakage_detectors", "Handheld Leakage Detectors", "Measurement", "360", "509", "Handheld leakage detectors are used to measure microwave levels of new or modified installations to ensure operator safety."],
		["industrial/measure/fixed_mount_leakage_detectors", "Fixed Mount Leakage Detectors", "Measurement", "360", "509", "The image shows the antenna used for detecting microwave leakages. These antennas are permanently installed and connected to a controller."],
		["industrial/measure/leakage_detector_13-56mhz", "Leakage Detector (13.56MHz)", "Measurement", "509", "360", "Fixed mount leakage detectors are permanently positioned to ensure that in the event of any leakages, the system is automatically shut down."],
		["industrial/measure/leakage_controller_13-56mhz", "Leakage Controller (13.56MHz)", "Measurement", "509", "360", "A leakage controller measures the leakage levels and ensures the system is shut down in the event a any leakages."],
		["industrial/measure/leakage_levels", "Leakage Levels", "Measurement", "509", "360", "Graph displaying leakage levels and the risks involved."]
		
	],
	fadeContainerId : "jas-container",
	imageContainerId : "jas-image",
	imageTextContainerId : "jas-image-text",
	previousLinkId : "previous-image",
	nextLinkId : "next-image",
	imageCounterId : "image-counter",
	startSlideShowId : "start-slideshow",
	stopSlideShowId : "stop-slideshow",	
	dimBackgroundOverlayId : "jas-dim-overlay",
	dimBackgroundId : "dim-background",
	noDimBackgroundId : "no-dim-background",
	thumbnailContainerId: "jas-thumbnails",
	tagsContainerId: "jas-tags",
	tagsSelectAllId: "jas-select-all-tags",
	useImageText : true,
	useThumbnails : true,
	allowDimmedBackground : true,
	automaticallyDimBackgroundWhenSlideShow : true,
	useTags : true,
	useKeyboardShortcuts : true,	
	useFadingIn : true,
	useFadingOut : true,
	useFadeWhenNotSlideshow : false,
	useFadeForSlideshow : true,
	useFadeAtInitialLoad : false,
	fadeIncrement : 0.1,	
	fadeInterval : 50, // Milliseconds	
	timeForSlideInSlideshow : 1000, // Milliseconds	
	
	// JaS function parameters
	allImages : null,
	currentImages : null,
	fadeContainer : null,
	imageContainer : null,
	imageTextContainer : null,
	previousLink : null,
	nextLink : null,
	dimBackgroundOverlay : null,
	dimBackgroundLink : null,
	noDimBackgroundLink : null,
	dimmingActivated : false,
	imageCounter : null,
	startSlideShowLink : null,
	stopSlideShowLink : null,
	thumbnailContainer : null,
	thumbnailCollection : [],
	currentThumbnailSelected : null,
	tagsContainer : null,
	tagsSelectAll : null,
	tagsList : null,
	tags : [],
	tagsCheckboxes : [],
	selectAllTags : true,
	imageText : null,
	imageText : "",
	imageSource : "",
	
	imageWidth : "",	/*NS Barnes 20090531*/
	imageHeight : "",	/*NS Barnes 20090531*/
	imageDesc : "",		/*NS Barnes 20090620*/
	
	imageIndex : 0,
	fadingIn : true,
	fadeLevel : 0,
	fadeEndLevel : 1,
	fadeTimer : null,
	hasOpacitySupport : false,
	useMSFilter : false,
	useMSCurrentStyle : false,
	slideshowIsSupported : false,
	slideshowIsPlaying : false,
	functionAfterFade : null,
	isInitialLoad : false,
	
	init : function (){
    	if($){
			this.fadeContainer = $(this.fadeContainerId);
			this.imageContainer = $(this.imageContainerId);
			this.slideshowIsSupported = this.fadeContainer && this.imageContainer;
			if(this.slideshowIsSupported){
				this.allImages = this.images;
				this.currentImages = this.images;
				if(this.useImageText){
					this.imageTextContainer = $(this.imageTextContainerId);
					if(!this.imageTextContainer){
						this.useImageText = false;
					}
				}
				this.hasOpacitySupport = typeof this.fadeContainer.style.filter != "undefined" || typeof this.fadeContainer.style.opacity != "undefined";
				this.useMSFilter = typeof this.fadeContainer.style.filter != "undefined";
				this.useMSCurrentStyle = typeof this.fadeContainer.currentStyle != "undefined";
				
				this.previousLink = $(this.previousLinkId);
				this.previousLink.onclick = JaS.previousLinkClick;
				this.nextLink = $(this.nextLinkId);
				this.nextLink.onclick = JaS.nextLinkClick;
				this.imageCounter = $(this.imageCounterId);
				this.startSlideShowLink = $(this.startSlideShowId);
				if(this.startSlideShowLink){
					this.startSlideShowLink.style.display = "inline";
				}
				this.startSlideShowLink.onclick = JaS.startSlideShowClick;
				this.stopSlideShowLink = $(this.stopSlideShowId);
				if(this.stopSlideShowLink){
					this.stopSlideShowLink.style.display = "none";
				}
				this.stopSlideShowLink.onclick = JaS.stopSlideshowClick;
				
				if(this.allowDimmedBackground){
					this.dimBackgroundOverlay = $(this.dimBackgroundOverlayId);
					this.dimBackgroundLink = $(this.dimBackgroundId);
					this.noDimBackgroundLink = $(this.noDimBackgroundId);
					if(this.dimBackgroundOverlay && this.dimBackgroundLink && this.noDimBackgroundLink){
						this.dimBackgroundLink.onclick = JaS.dimBackgroundClick;
						this.noDimBackgroundLink.onclick = JaS.noDimackgroundClick;
						this.noDimBackgroundLink.style.display = "none";
						this.dimmingActivated = true;
					}
				}
				
				if(this.useKeyboardShortcuts){
					document.onkeydown = JaS.documentKeyDown;
				}
				
				this.thumbnailContainer = $(this.thumbnailContainerId);
				//if(this.useThumbnails && this.thumbnailContainer){	/*NS Barnes 20090618 - Laai al die thumbnails, wil nie meer so he nie*/
					//this.createThumbnails();
				//}
				
				
				this.tagsContainer = $(this.tagsContainerId);
				if(this.useTags && this.tagsContainer){
					this.tagsSelectAll = $(this.tagsSelectAllId);
					if(this.tagsSelectAll){
						this.tagsSelectAll.onclick = JaS.tagsSelectAllClick;
						this.createTagList();
						this.applyTagFilter(); 	/*NS Barnes 20090618 - Laai net eerste thumbnails*/
					}
				}
				
				this.isInitialLoad = true;
				this.setImage();
				this.isInitialLoad = false;
			}
		}
	},
	
	previousLinkClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.previousImage();
	},
	
	nextLinkClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.nextImage();
	},
	
	startSlideShowClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.startSlideshow();
	},
	
	stopSlideshowClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.stopSlideshow();
	},
	
	dimBackgroundClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.dimBackground();
	},
	
	documentKeyDown : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.applyKeyboardNavigation(oEvent);
	},
	
	tagsSelectAllClick : function (oEvent){
		JaS.tagsSelectAll = this.checked;
		JaS.markAllTags();
	},
	
	noDimackgroundClick : function(oEvent){
		var oEvent = (typeof oEvent != "undefined")? oEvent : event;
		JaS.preventDefaultEventBehavior(oEvent);
		JaS.noDimBackground();
	},
	
	setImage : function (){
		if(this.currentImages.length > 0){
			this.imageContainer.style.visibility = "visible";
			this.imageSource = this.currentImages[this.imageIndex][0];
			this.imageText = this.currentImages[this.imageIndex][1];
			
			this.imageWidth = this.currentImages[this.imageIndex][3]; /*NS Barnes 20090531 - Kan nou image width ook laai*/
			this.imageHeight = this.currentImages[this.imageIndex][4]; /*NS Barnes 20090531 - Kan nou image height ook laai*/
			this.imageDesc = this.currentImages[this.imageIndex][5]; /*NS Barnes 20090620 - Kan nou image description ook laai*/
			
			if(this.useFadingOut && (this.slideshowIsPlaying && this.useFadeForSlideshow) || (!this.slideshowIsPlaying && this.useFadeWhenNotSlideshow) && (this.useFadeAtInitialLoad && this.isInitialLoad || !this.isInitialLoad)){
				this.fadeOut();
			}
			else{
				this.displayImageCount();
				this.imageContainer.setAttribute("src", (this.imagePath + this.imageSource + ".jpg"));	/*NS Barnes 20090531 - Added ".jpg"*/
				
				this.imageContainer.setAttribute("alt", (this.imageText));		/*NS Barnes 20090531 - Wys image alternative*/
				this.imageContainer.setAttribute("title", (this.imageText));	/*NS Barnes 20090531 - Wys image title*/
				this.imageContainer.setAttribute("width", (this.imageWidth));	/*NS Barnes 20090531 - Kan nou image width ook laai*/
				this.imageContainer.setAttribute("height", (this.imageHeight));	/*NS Barnes 20090531 - Kan nou image height ook laai*/
				
				this.setImageText();		/*NS Barnes 20090531 - Wys dan nie image text onder nie*/
				//this.previousLink.style.visibility = (this.imageIndex > 0)? "visible" : "hidden";								/*NS Barnes 20090618 - Hou Previous button visible*/
				//this.nextLink.style.visibility = (this.imageIndex < (this.currentImages.length - 1))? "visible" : "hidden";	/*NS Barnes 20090618 - Hou Next button visible*/
				if((this.useFadeAtInitialLoad && this.isInitialLoad || !this.isInitialLoad) && ((this.slideshowIsPlaying && this.useFadeForSlideshow) || (!this.slideshowIsPlaying && this.useFadeWhenNotSlideshow))){
					this.fadeIn();
				}
			}
			if(this.useThumbnails){
				this.markCurrentThumbnail();
			}
		}
		else{
			this.imageSource = "";
			this.imageText = "";
			this.displayImageCount();
			this.imageContainer.style.visibility = "hidden";
			this.setImageText();
		}
	},
	
	displayImageCount : function (){
    	if(this.imageCounter){
			this.imageCounter.innerHTML = (((this.currentImages.length > 0)? this.imageIndex : -1) + 1) + " / " + this.currentImages.length;
		}
	},
	
	nextImage : function (){
		if(this.imageIndex < (this.currentImages.length - 1)){
			++this.imageIndex;
			this.setImage();
		}
		else if(this.slideshowIsPlaying){
			//this.stopSlideshow();			/*NS Barnes 20090618 - Slideshow hou aan, stop nie self nie*/
			this.imageIndex = 0;
			this.setImage();
		}
		else								/*NS Barnes 20090618 - As laaste image was, begin weer voor*/
		{
			this.imageIndex=0;				/*NS Barnes 20090618 - As laaste image was, begin weer voor*/
			this.setImage();				
		}
	},
	
	previousImage : function (){
		if(this.imageIndex > 0){
			--this.imageIndex;
			this.setImage();
		}
		else												/*NS Barnes 20090618 - As eerste image was, begin agter*/
		{
			this.imageIndex=this.currentImages.length-1;	/*NS Barnes 20090618 - As eerste image was, begin agter*/
			this.setImage();				
		}         
	},

	setImageText : function (){
		this.imageTextContainer.setAttribute("alt", this.imageDesc);
    	if(this.useImageText && typeof this.imageDesc == "string"){
			this.imageTextContainer.innerHTML = this.imageDesc;
		}
	},
	
	setDimBackgroundSize : function(){
         var oDimBackground = this.dimBackgroundOverlay.style;
         var intWidth = document.body.offsetWidth;
         var intXScroll = (typeof window.pageXOffset != "undefined")? window.pageXOffset : document.body.scrollLeft;
         var intHeight = (typeof window.innerHeight != "undefined")? window.innerHeight : (document.documentElement)? document.documentElement.clientHeight : document.body.clientHeight;
         var intYScroll = (typeof window.window.pageYOffset != "undefined")? window.window.pageYOffset : (document.documentElement)? document.documentElement.scrollTop : document.documentElement.scrollTop;
         oDimBackground.width = intWidth + intXScroll + "px";
         oDimBackground.height = intHeight + intYScroll + "px";
	},
	
	dimBackground : function (){
         this.setDimBackgroundSize();
         this.dimBackgroundOverlay.style.display = "block";
		 this.noDimBackgroundLink.style.display = "inline";		
	},
	
	noDimBackground : function (fromStopSlideshow){
		this.dimBackgroundOverlay.style.display = "none";
		this.noDimBackgroundLink.style.display = "none";
		if(!fromStopSlideshow){
			this.stopSlideshow();
		}
	},
		
	startSlideshow : function (){
		if(this.currentImages.length > 0){
			this.startSlideShowLink.style.display = "none";
			this.stopSlideShowLink.style.display = "inline";
			this.slideshowIsPlaying = true;
			this.fadeTimer = setTimeout("JaS.nextImage()", JaS.timeForSlideInSlideshow);
			if(this.dimmingActivated  && this.automaticallyDimBackgroundWhenSlideShow){
				this.dimBackground();
			}
		}
	},
	
	stopSlideshow : function (){
		if(this.currentImages.length > 0){
			this.startSlideShowLink.style.display = "inline";
			this.stopSlideShowLink.style.display = "none";
			this.slideshowIsPlaying = false;
			this.setFadeParams(false, 1, 0);
			this.setFade();
			clearTimeout(this.fadeTimer);
			if(this.dimmingActivated && this.automaticallyDimBackgroundWhenSlideShow){
				this.noDimBackground(true);
			}
		}
	},
	
	fadeIn : function (){
		this.setFadeParams(true, 0, 1);
		this.functionAfterFade = null;
		this.fade();
		if(this.slideshowIsPlaying){
			this.functionAfterFade = "this.startSlideshow()";
		}
	},
	
	fadeOut : function (){
		this.setFadeParams(false, 1, 0);
		this.functionAfterFade = "this.fadeOutDone()";
		this.fade();
	},
	
	fadeOutDone : function (){
        this.displayImageCount();
		this.imageContainer.setAttribute("src", (this.imagePath + this.imageSource + ".jpg"));	/*NS Barnes 20090531 - Added ".jpg"*/
		this.imageContainer.setAttribute("alt", (this.imageText));		/*NS Barnes 20090531 - Wys image alternative*/
		this.imageContainer.setAttribute("title", (this.imageText));	/*NS Barnes 20090531 - Wys image title*/
		this.imageContainer.setAttribute("width", (this.imageWidth));	/*NS Barnes 20090531 - Kan nou image width ook laai*/
		this.imageContainer.setAttribute("height", (this.imageHeight));	/*NS Barnes 20090531 - Kan nou image height ook laai*/
		
		this.setImageText();		/*NS Barnes 20090531 - Wys dan nie image text onder nie*/
		if(this.useFadingIn){
			this.fadeIn();
		}
		else{
			this.fadeLevel = 1;
			this.setFade();
		}
	},
	
	fade : function (){
		if((this.fadingIn && this.fadeLevel < this.fadeEndLevel) || !this.fadingIn && this.fadeLevel > this.fadeEndLevel){
			this.fadeLevel = (this.fadingIn)? this.fadeLevel + this.fadeIncrement : this.fadeLevel - this.fadeIncrement;
			// This line is b/c of a floating point bug in JavaScript
			this.fadeLevel = Math.round(this.fadeLevel * 10) / 10;
			this.setFade();
			this.fadeTimer = setTimeout("JaS.fade()", this.fadeInterval);
		}
		else{
			clearTimeout(this.fadeTimer);
			if(this.functionAfterFade){
				eval(this.functionAfterFade);
			}
		}
	},
	
	setFade : function (){
		if(this.useMSFilter){
			this.fadeContainer.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + (this.fadeLevel * 100) + ")";
		}
		else{
			this.fadeContainer.style.opacity = this.fadeLevel;
		}
	},
	
	setFadeParams : function (bFadingIn, intStartLevel, intEndLevel){
		this.fadingIn = bFadingIn;
		this.fadeLevel = intStartLevel;
		this.fadeEndLevel = intEndLevel;
	},
	
	createThumbnails : function (){
		this.thumbnailContainer.innerHTML = "";
		this.thumbnailCollection = [];
    	var oThumbnailsList = document.createElement("ul");
		var oListItem;
		var oThumbnail;
		var oCurrentImage;
		for(var i=0; i<this.currentImages.length; i++){
        	oCurrentImage = this.currentImages[i];
			oListItem = document.createElement("li");
			oThumbnail = document.createElement("img");
			oThumbnail.setAttribute("id", ("jas-thumbnail-" + i));
			oThumbnail.setAttribute("src", (this.imagePath + oCurrentImage[0] + "_t.jpg"));		//NS Barnes 20090531 - Added _t.jpg
			oThumbnail.setAttribute("alt", oCurrentImage[1]);
			oThumbnail.setAttribute("title", oCurrentImage[1]);
			oThumbnail.onclick = JaS.thumbnailClick;
			this.thumbnailCollection.push(oThumbnail);
			oListItem.appendChild(oThumbnail);
			oThumbnailsList.appendChild(oListItem);			
        }
		this.thumbnailContainer.appendChild(oThumbnailsList);
		if(this.thumbnailCollection.length > 0){
			this.markCurrentThumbnail();
		}
		if(this.slideshowIsPlaying){
			this.stopSlideshow();
		}
	},
	
	thumbnailClick : function (oEvent){
		JaS.imageIndex = parseInt(this.getAttribute("id").replace(/\D*(\d+)$/, "$1"), 10);
		JaS.setImage();
	},
	
	markCurrentThumbnail : function (){
		if(this.currentThumbnailSelected){
	        this.currentThumbnailSelected.className = "";
			// Sometimes, in IE, the image loses its reference to its parent
			if(this.currentThumbnailSelected.parentNode){
				this.currentThumbnailSelected.parentNode.className = "";
			}
		}
		this.currentThumbnailSelected = this.thumbnailCollection[this.imageIndex];
		this.currentThumbnailSelected.className = "selected";
		this.currentThumbnailSelected.parentNode.className = "selected-parent";
	},
	
	createTagList : function (){
		var strCurrentTag;
		var arrCurrentTag;
		var oRegExp;
		for(var i=0; i<this.images.length; i++){
			arrCurrentTag = this.images[i][2].replace(/\s*(,)\s*/,  "$1").split(",");
			for(var j=0; j<arrCurrentTag.length; j++){
            	strCurrentTag = arrCurrentTag[j];
				oRegExp = new RegExp(strCurrentTag, "i");
				if(this.tags.toString().search(oRegExp) == -1){
					this.tags.push(strCurrentTag);
				}
            }
        }
		this.tagsList = document.createElement("ul");	
		var oListItem;
		var oTagCheckbox;
		var oLabel;
		for(var k=0; k<this.tags.length; k++){
			oTag = this.tags[k];
			oListItem = document.createElement("li");	
			oTagCheckbox = document.createElement("input");
			oTagCheckbox.setAttribute("type", "checkbox");
			oTagCheckbox.setAttribute("id", ("jas-" + oTag));
			oTagCheckbox.setAttribute("value", oTag);
			oTagCheckbox.setAttribute("name", "Tags");	/*NS Barnes 20090618 - Added name sodat net een op n slag aan kan wees*/
			oTagCheckbox.tabindex = k;					/*NS Barnes 20090619 - Tag se index nommer*/		
			//oTagCheckbox.checked = true;				/*NS Barnes 20090618 - Merk nie alle tags nie*/
			oTagCheckbox.onclick = JaS.tagCheckboxClick;	
			oLabel = document.createElement("label");
			oLabel.setAttribute("for", ("jas-" + oTag));
			oLabel.innerHTML = oTag;
			this.tagsCheckboxes.push(oTagCheckbox);
			oListItem.appendChild(oTagCheckbox);
			oListItem.appendChild(oLabel);
			this.tagsList.appendChild(oListItem);
			this.tagsList.className = "selected";
		}
		this.tagsContainer.appendChild(this.tagsList);
		// This loop is necessary since IE can only mark checkboxes as checked after they've been added to the document
		for(var l=0; l<this.tagsCheckboxes.length; l++){
			this.tagsCheckboxes[0].checked = true;		/*NS Barnes 20090618 - Merk net eerste tag*/
		}
	},
	
	tagCheckboxClick : function (oEvent){
		if (JaS.tagsSelectAll==true)					/*NS Barnes 20090618 - As select al aan was, maak dit af*/	
		{	
			JaS.tagsSelectAll = false;					/*NS Barnes 20090618 - As select al aan was, maak dit af*/
			JaS.markAllTags();							/*NS Barnes 20090618 - As select al aan was, maak dit af*/
			JaS.tagsCheckboxes[0].checked = true;		/*NS Barnes 20090618 - Merk weer eerste tag*/
		}
		
		for(var k=0; k<JaS.tags.length; k++)			/*NS Barnes 20090619 - Hardloop deur al die tags om seker te maak net selected een is aan*/
		{
			if (this.tabindex==k)					
				JaS.tagsCheckboxes[k].checked = true;	/*NS Barnes 20090619 - Sit net selected tag aan*/
			else
				JaS.tagsCheckboxes[k].checked = false;	/*NS Barnes 20090619 - Sit al die ander tags af*/
		}
		
		JaS.imageIndex = 0;								/*NS Barnes 20090618 - Maak seker as tag geclick word eerste image vertoon word*/
		JaS.applyTagFilter();
	},
	
	applyTagFilter : function (){
		this.currentImages = [];
		var arrCurrentTags = [];
		var oCheckbox;
		for(var i=0; i<this.tagsCheckboxes.length; i++){
        	oCheckbox = this.tagsCheckboxes[i];
			if(oCheckbox.checked==true){
				arrCurrentTags.push(oCheckbox.value);
			}
        }
		var oRegExp;
		var oImage;
		for(var j=0; j<this.images.length; j++){
        	oImage = this.images[j];
			for(var k=0; k<arrCurrentTags.length; k++){
				oRegExp = new RegExp(arrCurrentTags[k], "i");
				if(oImage[2].search(oRegExp) != -1){
					this.currentImages.push(oImage);
					break;
				}
			}
        }
		
		if(this.useThumbnails){
			this.createThumbnails();
		}
		this.imageIndex = 0;
		this.setImage();
	},
	
	markAllTags : function (){
		for(var i=0; i<this.tagsCheckboxes.length; i++){
			this.tagsCheckboxes[i].checked = this.tagsSelectAll;
			oTag = this.tags[i];										/*NS Barnes 20090618 - Lees tag data*/
			if (JaS.tagsSelectAll==true)								/*NS Barnes 20090618 - Kyk of als select moet word*/
			{
				this.tagsCheckboxes[i].setAttribute("name", oTag);		/*NS Barnes 20090618 - Maak name weer verskillend sodat almal select word*/
			}
			else
			{
				this.tagsCheckboxes[i].setAttribute("name", "Tags");	/*NS Barnes 20090618 - Maak name weer selfde sodat slegs een select word*/
				JaS.tagsCheckboxes[0].checked = true;
			}
        }
		this.applyTagFilter();
	},
	
	closeSession : function (oEvent){
		JaS = null;
		delete JaS;
	},
	
	applyKeyboardNavigation : function (oEvent){
    	var intKeyCode = oEvent.keyCode;
    	if(!oEvent.altKey){
			switch(intKeyCode){
				case 32:
					this.slideshowIsPlaying = (this.slideshowIsPlaying)? false : true;
					if(this.slideshowIsPlaying){
						this.startSlideshow();
					}
					else{
						this.stopSlideshow();
					}
					this.preventDefaultEventBehavior(oEvent);
					break;
				case 37:				/*NS Barnes 20090622 - Links pyl*/
				//case 38:				/*NS Barnes 20090622 - Op pyl*/
					this.previousImage();
					this.preventDefaultEventBehavior(oEvent);
					break;
				case 39:				/*NS Barnes 20090622 - Regs pyl*/
				//case 40:				/*NS Barnes 20090622 - Af pyl*/
					this.nextImage();
					this.preventDefaultEventBehavior(oEvent);
					break;
			}
		}
	},
	
	preventDefaultEventBehavior : function (oEvent){
		if(oEvent){
			oEvent.returnValue = false;
			if(oEvent.preventDefault){
				oEvent.preventDefault();
			}
		}
	}
};
// ---
addEvent(window, "load", function(){JaS.init();}, false);
addEvent(window, "unload", function(){JaS.closeSession();}, false);
// ---
// Utility functions
function addEvent(oObject, strEvent, oFunction, bCapture){
	if(oObject){
		if(oObject.addEventListener){
			oObject.addEventListener(strEvent, oFunction, bCapture);
		}
		else if(window.attachEvent){
			oObject.attachEvent(("on" + strEvent), oFunction)
		}
	}
}
// ---
function $(strId){
	return document.getElementById(strId);
}
// ---
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
// ---