$(function() {
	if (document.getElementById('sshow') !== undefined) {
		$('#sshow').nivoSlider({
			controlNav : false,
			effect : 'fade'
		});
	}
	// IE <= 9 sucks. This is the placeholder attribute polyfiller
	if (navigator.userAgent.search('MSIE') !== -1) {

		// Create the function for emulating the HTML5 placeholder attribute
		_inputFocusHandler = function() {
			this.style.color = '#000';
			this.style.border = '1px solid #ACA535';
			if (this.value == this.getAttribute('placeholder')) {
				this.value = '';
			}
		};
		_inputBlurHandler = function(element) {

			if (this.nodeType === 1) {
				// This allows us to pass an element to set the placeholder data without blurring
				element = this;
			}

			if (element.value === '' || element.value === undefined) {
				element.style.color = '#999';
				element.value = element.getAttribute('placeholder');
			}

			element.style.border = '1px solid #ddd';
		};

		// Loop through each input and add the placeholder text for older browsers
		while (count < inputCollection.length) {
			input = inputCollection[count];

			// Run the blur/initial placeholder state
			_inputBlurHandler(input);

			// Assign the two placeholder functions on the element listeners
			input.onfocus = _inputFocusHandler;
			input.onblur = _inputBlurHandler;

			count++;
		}

	}
	if (document.getElementById('gallery-main') !== null) {
		var imgList = [],
		    selected = 0;

		// Create a list of images so we can use the back/forward button proper;y
		$(".thumbnails img").each(function(c,e){
			// Add the image to the list of images
			imgList.push(e);
		});

        $("#gallery-main").attr('src', imgList[0].getAttribute('src'));
        $("#caption").html(imgList[0].getAttribute('alt'));

		$(".thumbnails img").click(function() {
			selectImg(imgList.indexOf(this));
		});

		document.getElementById('galleryBack').onclick = function() {
			if (selected == 0)
				selectImg(imgList.length - 1);
			else
				selectImg(selected - 1);
		}

		document.getElementById('galleryForward').onclick = function() {
			if (selected == (imgList.length - 1))
				selectImg(0);
			else
				selectImg(selected + 1);
		}

		function selectImg(index) {
			selected = index;
			$("#gallery-main").attr('src', imgList[index].getAttribute('src'));
			$("#caption").html(imgList[index].getAttribute('alt'));
		}
	}
});
