/* Script for www.alannaagency.com, written by Kevin Murphy
Images listed by filename, */

var JaS = {
	// Customization parameters
	imagePath : "http://www.alannaagency.com/JimmyCrystal/images/Collections/Sunglasses/",
	images : [
["GL313-ZB.jpg", "GL313-ZB", "GL313-ZB"],
["GL804-BK.jpg", "GL804-BK", "GL804-BK"],
["GL804-BW.jpg", "GL804-BW", "GL804-BW"],
["GL805-BLK.jpg", "GL805-BLK", "GL805-BLK"],
["GL805-BR.jpg", "GL805-BR", "GL805-BR"],
["GL806A-BK.jpg", "GL806A-BK", "GL806A-BK"],
["GL806A-BW.jpg", "GL806A-BW", "GL806A-BW"],
["GL806-BLK.jpg", "GL806-BLK", "GL806-BLK"],
["GL806-BW.jpg", "GL806-BW", "GL806-BW"],
["GL809-BLK.jpg", "GL809-BLK", "GL809-BLK"],
["GL809-BW.jpg", "GL809-BW", "GL809-BW"],
["GL809-CLR.jpg", "GL809-CLR", "GL809-CLR"],
["GL809-PK.jpg", "GL809-PK", "GL809-PK"],
["GL824-BK.jpg", "GL824-BK", "GL824-BK"],
["GL824-BW.jpg", "GL824-BW", "GL824-BW"],
["GL824-HONEY.jpg", "GL824-HONEY", "GL824-HONEY"],
["GL828.jpg", "GL828", "GL828"],
["GL828A.jpg", "GL828A", "GL828A"],
["GL828B.jpg", "GL828B", "GL828B"],
["GL828-BUTTERFLY.jpg", "GL828-BUTTERFLY", "GL828-BUTTERFLY"],
["GL828-BW.jpg", "GL828-BW", "GL828-BW"],
["GL828-Weavy.jpg", "GL828-Weavy", "GL828-Weavy"],
["GL838A-LEOP.jpg", "GL838A-LEOP", "GL838A-LEOP"],
["GL838-BLK.jpg", "GL838-BLK", "GL838-BLK"],
["GL838-BR.jpg", "GL838-BR", "GL838-BR"],
["GL838-ZEBRA.jpg", "GL838-ZEBRA", "GL838-ZEBRA"],
["GL840-BLUPT.jpg", "GL840-BLUPT", "GL840-BLUPT"],
["GL840-BWPT.jpg", "GL840-BWPT", "GL840-BWPT"],
["GL840-LEOP.jpg", "GL840-LEOP", "GL840-LEOP"],
["GL840-ZEBRA.jpg", "GL840-ZEBRA", "GL840-ZEBRA"],
["GL859.jpg", "GL859", "GL859"],
["GL860-BLK.jpg", "GL860-BLK", "GL860-BLK"],
["GL861-PK.jpg", "GL861-PK", "GL861-PK"],
["GL861-RED.jpg", "GL861-RED", "GL861-RED"],
["GL863.jpg", "GL863", "GL863"],
["GL864.jpg", "GL864", "GL864"],
["GL865-BLK.jpg", "GL865-BLK", "GL865-BLK"],
["GL867-BLK.jpg", "GL867-BLK", "GL867-BLK"],
["GL868.jpg", "GL868", "GL868"],
["GL869.jpg", "GL869", "GL869"],
["GL870.jpg", "GL870", "GL870"],
["GL875-BLK.jpg", "GL875-BLK", "GL875-BLK"],
["GL875-BW.jpg", "GL875-BW", "GL875-BW"],
["GL880B-BK.jpg", "GL880B-BK", "GL880B-BK"],
["GL880B-BR.jpg", "GL880B-BR", "GL880B-BR"],
["GL880-HONEY.jpg", "GL880-HONEY", "GL880-HONEY"],
["GL888A-BR.jpg", "GL888A-BR", "GL888A-BR"],
["GL888A-ZEBRA.jpg", "GL888A-ZEBRA", "GL888A-ZEBRA"],
["GL888-BK.jpg", "GL888-BK", "GL888-BK"],
["GL888-BR.jpg", "GL888-BR", "GL888-BR"],
["GL889-BLK.jpg", "GL889-BLK", "GL889-BLK"],
["GL889-BR.jpg", "GL889-BR", "GL889-BR"],
["GL890A-BR.jpg", "GL890A-BR", "GL890A-BR"],
["GL890-BK.jpg", "GL890-BK", "GL890-BK"],
["GL891-Drop.jpg", "GL891-Drop", "GL891-Drop"],
["GL898-BK.jpg", "GL898-BK", "GL898-BK"],
["GL898-BW.jpg", "GL898-BW", "GL898-BW"],
["GL899-BK.jpg", "GL899-BK", "GL899-BK"],
["GL899-BLU.jpg", "GL899-BLU", "GL899-BLU"],
["GL899-BW.jpg", "GL899-BW", "GL899-BW"],
["GL899-PK.jpg", "GL899-PK", "GL899-PK"],
["GL901-BK.jpg", "GL901-BK", "GL901-BK"],
["GL901-BLU.jpg", "GL901-BLU", "GL901-BLU"],
["GL901-BW.jpg", "GL901-BW", "GL901-BW"],
["GL901-PK.jpg", "GL901-PK", "GL901-PK"],
["GL903-Innergarden.jpg", "GL903-Innergarden", "GL903-Innergarden"],
["GL904-BK.jpg", "GL904-BK", "GL904-BK"],
["GL904-BW.jpg", "GL904-BW", "GL904-BW"],
["GL904-WHT.jpg", "GL904-WHT", "GL904-WHT"],
["GL905-BK.jpg", "GL905-BK", "GL905-BK"],
["GL905-BR.jpg", "GL905-BR", "GL905-BR"],
["GL907-BK.jpg", "GL907-BK", "GL907-BK"],
["GL907-BR.jpg", "GL907-BR", "GL907-BR"],
["GL908.jpg", "GL908", "GL908"],
["GL908-BR.jpg", "GL908-BR", "GL908-BR"],
["GL909-BK.jpg", "GL909-BK", "GL909-BK"],
["GL909-BR.jpg", "GL909-BR", "GL909-BR"],
["GL910-BK.jpg", "GL910-BK", "GL910-BK"],
["GL910-BR.jpg", "GL910-BR", "GL910-BR"],
["GL911-BK.jpg", "GL911-BK", "GL911-BK"],
["GL911-BR.jpg", "GL911-BR", "GL911-BR"],
["GL913-BW.jpg", "GL913-BW", "GL913-BW"],
["GL913-BW_2F49.jpg", "GL913-BW_2F49", "GL913-BW_2F49"],
["GL914-BLK.jpg", "GL914-BLK", "GL914-BLK"],
["GL914-BW.jpg", "GL914-BW", "GL914-BW"],
["GL915-BK.jpg", "GL915-BK", "GL915-BK"],
["GL915-BR.jpg", "GL915-BR", "GL915-BR"],
["GL916-BLK.jpg", "GL916-BLK", "GL916-BLK"],
["GL916-BW.jpg", "GL916-BW", "GL916-BW"],
["GL917-BLK.jpg", "GL917-BLK", "GL917-BLK"],
["GL917-BR.jpg", "GL917-BR", "GL917-BR"],
["GL918-BK.jpg", "GL918-BK", "GL918-BK"],
["GL918-BR.jpg", "GL918-BR", "GL918-BR"],
["GL919-BK.jpg", "GL919-BK", "GL919-BK"],
["GL919-BR.jpg", "GL919-BR", "GL919-BR"],
["GL920-BK.jpg", "GL920-BK", "GL920-BK"],
["GL920-BR.jpg", "GL920-BR", "GL920-BR"],
["GL925-BLK.jpg", "GL925-BLK", "GL925-BLK"],
["GL925-BW.jpg", "GL925-BW", "GL925-BW"],
["GL926-BLK.jpg", "GL926-BLK", "GL926-BLK"],
["GL926-BW.jpg", "GL926-BW", "GL926-BW"],
["GL937-BLK.jpg", "GL937-BLK", "GL937-BLK"],
["GL937-BW.jpg", "GL937-BW", "GL937-BW"],
["GL938-BK.jpg", "GL938-BK", "GL938-BK"],
["GL938-BR.jpg", "GL938-BR", "GL938-BR"],
["GL939-BLK.jpg", "GL939-BLK", "GL939-BLK"],
["GL939-BW.jpg", "GL939-BW", "GL939-BW"],
["GL940-BK.jpg", "GL940-BK", "GL940-BK"],
["GL940-BR.jpg", "GL940-BR", "GL940-BR"],
["GL941A-BK.jpg", "GL941A-BK", "GL941A-BK"],
["GL941A-BR.jpg", "GL941A-BR", "GL941A-BR"],
["GL941-BK.jpg", "GL941-BK", "GL941-BK"],
["GL941-BW.jpg", "GL941-BW", "GL941-BW"],
["GL941PT.jpg", "GL941PT", "GL941PT"],
["GL942-BLK.jpg", "GL942-BLK", "GL942-BLK"],
["GL942-BW.jpg", "GL942-BW", "GL942-BW"],
["GL943-BK.jpg", "GL943-BK", "GL943-BK"],
["GL943-BR.jpg", "GL943-BR", "GL943-BR"],
["GL943-Xmas.jpg", "GL943-Xmas", "GL943-Xmas"],
["GL944-BLK.jpg", "GL944-BLK", "GL944-BLK"],
["GL944-BR.jpg", "GL944-BR", "GL944-BR"],
["GL944-L-Siam.jpg", "GL944-L-Siam", "GL944-L-Siam"],
["GL945-BLK.jpg", "GL945-BLK", "GL945-BLK"],
["GL945-BW.jpg", "GL945-BW", "GL945-BW"],
["GL945-WHITE.jpg", "GL945-WHITE", "GL945-WHITE"],
["GL946_002.jpg", "GL946_002", "GL946_002"],
["GL946_005.jpg", "GL946_005", "GL946_005"],
["GL948-BR.jpg", "GL948-BR", "GL948-BR"],
["GL949-BLK.jpg", "GL949-BLK", "GL949-BLK"],
["GL949-BW.jpg", "GL949-BW", "GL949-BW"],
["GL954-BK.jpg", "GL954-BK", "GL954-BK"],
["GL954-BR.jpg", "GL954-BR", "GL954-BR"],
["GL955-BLK.jpg", "GL955-BLK", "GL955-BLK"],
["GL955-BW.jpg", "GL955-BW", "GL955-BW"],
["GL962-LEOP.jpg", "GL962-LEOP", "GL962-LEOP"],
["GL962-ZEBRA.jpg", "GL962-ZEBRA", "GL962-ZEBRA"],
["GL963-BR.jpg", "GL963-BR", "GL963-BR"],
["GL965-BR.jpg", "GL965-BR", "GL965-BR"],
["GL966-BW.jpg", "GL966-BW", "GL966-BW"],
["GL980-BK.jpg", "GL980-BK", "GL980-BK"],
["GL980-BW.jpg", "GL980-BW", "GL980-BW"],
["GL981-BK.jpg", "GL981-BK", "GL981-BK"],
["GL981-BW.jpg", "GL981-BW", "GL981-BW"]


	],
	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",
	thumbnailContainerId: "jas-thumbnails",
	tagsContainerId: "jas-tags",
	tagsSelectAllId: "jas-select-all-tags",
	useImageText : true,
	useThumbnails : true,
	useTags : false,
	useKeyboardShortcuts : true,
	useFadingIn : true,
	useFadingOut : true,
	useFadeWhenNotSlideshow : false,
	useFadeForSlideshow : true,
	useFadeAtInitialLoad : false,
	fadeIncrement : 0.1,
	fadeInterval : 100, // Milliseconds
	timeForSlideInSlideshow : 3500, // Milliseconds

	// JaS function parameters
	allImages : null,
	currentImages : null,
	fadeContainer : null,
	imageContainer : null,
	imageTextContainer : null,
	previousLink : null,
	nextLink : null,
	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 : "",
	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(document.getElementById){
			this.fadeContainer = document.getElementById(this.fadeContainerId);
			this.imageContainer = document.getElementById(this.imageContainerId);
			this.slideshowIsSupported = this.fadeContainer && this.imageContainer;
			if(this.slideshowIsSupported){
				this.allImages = this.images;
				this.currentImages = this.images;
				if(this.useImageText){
					this.imageTextContainer = document.getElementById(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 = document.getElementById(this.previousLinkId);
				this.previousLink.onclick = function(oEvent){
					var oEvent = (typeof oEvent != "undefined")? oEvent : event;
					JaS.preventDefaultEventBehavior(oEvent);
					JaS.previousImage();
				};
				this.nextLink = document.getElementById(this.nextLinkId);
				this.nextLink.onclick = function(oEvent){
					var oEvent = (typeof oEvent != "undefined")? oEvent : event;
					JaS.preventDefaultEventBehavior(oEvent);
					JaS.nextImage();
				};
				this.imageCounter = document.getElementById(this.imageCounterId);
				this.startSlideShowLink = document.getElementById(this.startSlideShowId);
				if(this.startSlideShowLink){
					this.startSlideShowLink.style.display = "inline";
				}
				this.startSlideShowLink.onclick = function(oEvent){
					var oEvent = (typeof oEvent != "undefined")? oEvent : event;
					JaS.preventDefaultEventBehavior(oEvent);
					JaS.startSlideshow();
				};
				this.stopSlideShowLink = document.getElementById(this.stopSlideShowId);
				if(this.stopSlideShowLink){

					this.stopSlideShowLink.style.display = "none";
				}
				this.stopSlideShowLink.onclick = function(oEvent){
					var oEvent = (typeof oEvent != "undefined")? oEvent : event;
					JaS.preventDefaultEventBehavior(oEvent);
					JaS.stopSlideshow();
				};

				if(this.useKeyboardShortcuts){
					document.onkeydown = function(oEvent){
						var oEvent = (typeof oEvent != "undefined")? oEvent : event;
						JaS.applyKeyboardNavigation(oEvent);
					};
				}

				this.thumbnailContainer = document.getElementById(this.thumbnailContainerId);
				if(this.useThumbnails && this.thumbnailContainer){
					this.createThumbnails();
				}

				this.tagsContainer = document.getElementById(this.tagsContainerId);
				if(this.useTags && this.tagsContainer){
					this.tagsSelectAll = document.getElementById(this.tagsSelectAllId);
					if(this.tagsSelectAll){
						this.tagsSelectAll.onclick = function (oEvent){
							JaS.tagsSelectAll = this.checked;
							JaS.markAllTags();
						};
						this.createTagList();
					}
				}

				this.isInitialLoad = true;
				this.setImage();
				this.isInitialLoad = false;
			}
		}
	},

	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];
			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));
				this.setImageText();
				this.previousLink.style.visibility = (this.imageIndex > 0)? "visible" : "hidden";
				this.nextLink.style.visibility = (this.imageIndex < (this.currentImages.length - 1))? "visible" : "hidden";
				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();
			this.imageIndex = 0;
			this.setImage();
		}
	},

	previousImage : function (){
		if(this.imageIndex > 0){
			--this.imageIndex;
			this.setImage();
		}
	},

	setImageText : function (){
		this.imageTextContainer.setAttribute("alt", this.imageText);
    	if(this.useImageText && typeof this.imageText == "string"){
			this.imageTextContainer.innerHTML = this.imageText;
		}
	},

	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);
		}
	},

	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);
		}
	},

	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));
		this.setImageText();
		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]));
			oThumbnail.setAttribute("alt", oCurrentImage[1]);
			oThumbnail.setAttribute("title", oCurrentImage[1]);
			oThumbnail.onclick = function (oEvent){
				JaS.imageIndex = parseInt(this.getAttribute("id").replace(/\D*(\d+)$/, "$1"), 10);
				JaS.setImage();
			};
			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();
		}
	},

	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.checked = true;
			oTagCheckbox.onclick = function (oEvent){
				JaS.applyTagFilter();
			};
			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.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[l].checked = true;
		}
	},

	applyTagFilter : function (){
		this.currentImages = [];
		var arrCurrentTags = [];
		var oCheckbox;
		for(var i=0; i<this.tagsCheckboxes.length; i++){
        	oCheckbox = this.tagsCheckboxes[i];
			if(oCheckbox.checked){
				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;
        }
		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:
				case 38:
					this.previousImage();
					this.preventDefaultEventBehavior(oEvent);
					break;
				case 39:
				case 40:
					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)
		}
	}
}
// ---
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}

