// JavaScript Document

// Set form validation error messages
$.extend($.validator.messages, {
		required: "Invalid",
		email: "Email Address Invalid"
});

$(function() {
					 
	// Set a corresponding class for the last child
	$('ul li:last-child').addClass('last');
	$('tr td:last-child').addClass('last-child');
	$('table tr:last-child').addClass('last-child');
	
	// Validate form when triggered by the corresponding class
	$("form.validate").each(function() {
		$(this).validate({
			errorElement: "strong",
			onfocusout: function(element) { $(element).valid(); },
			onclick: function(element) { $(element).valid(); },
			showErrors: function(errorMap, errorList) {
				for ( var i = 0; this.errorList[i]; i++ ) {
					var error = this.errorList[i];
					$(error.element).parent().find('em').hide();
				}
				this.defaultShowErrors();
			},
			unhighlight: function(element, errorClass, validClass) {
				$(element).removeClass(errorClass).addClass(validClass);
				$(element).parent().find('em').css('display', 'inline');
			}
		});
	});
	
	// Initialize drop down menu
	$('#site-nav').dropdown();
	
	// Initialise homepage carousel
	// $('.infinite-carousel').infiniteCarousel({ speed : 7500 });
	
	// Set default values for form elements
	$('#global-search-input').defaultvalue('Search keyword or item #');
	$('#email-subscribe-input').defaultvalue('Email address');
	
	// Submit links
	$('.submit-link').each(function () {
		$(this).click(function () {
			$(this).parents('form').submit();
			return false;
		});
	});
	
});

$.fn.filterInput = function (sFilteredValues) {
	return this.each(function () {
		var o = $(this)
		var s = o.val();
		var i;
		var sReturnString = "";
		for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
			var c = s.charAt(i);
			if (sFilteredValues.indexOf(c) == -1)
				sReturnString += c;
		}
		o.val(sReturnString);
	});
}

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
			return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}

