$(document).ready(function () {
	// Opens links in new window on a anchor with an attribute of rel="openwin"
	$('a[rel=openwin]').click(function(){
		window.open(this.href);
		return false;
	});
	
	// Bind a click event to anchor with rel="submit" and submits form its contained within
	$("a[rel=submit]").click( function(){
		$(this).parents("form").submit();
	});
	
	// Validate all forms
	$("form").validate();

});
		
		if ($('ul#productCarousel')) {
			jQuery('ul#productCarousel').jcarousel({
				scroll : 3
			});
		}


$(document).ready(function() {
	//For OO JS Goodness
	var that = this;
	// Configuration area
	this.searchform = 'form#emailaddform'
	this.searchElement = 'input#emailaddressinput';
	this.searchValue = 'Enter your email here';
	this.searchDefaultTextError = 'Please enter a valid email in the text box';
	this.apop = 'a.external';
	// End configuration area
	
	
	if ($(that.searchElement).length > 0) {
		// Search remove and reapply text
		$(that.searchElement).val(that.searchValue);
		$(that.searchElement).focus(function () {
			if ($(this).val() == that.searchValue) {
				$(this).val('');
			}
		});
		$(that.searchElement).blur(function () {
			if ($(this).val() == '') {
				$(this).val(that.searchValue);
			}
		});
		// Fail if search default text present
		$(that.searchform).submit(function () {
			if ($(that.searchElement).val() == that.searchValue || $(that.searchElement).val() == '') {
				alert(that.searchDefaultTextError);
				return false;
			}
		});
	}
	// External link open in new window
	$(that.apop).click(function(){
		window.open(this.href);
		return false;
	});
	
		//Product
	if ($('div.products').length > 0) {
		//image zoom and change
		var options = {
			zoomWidth: 400,
			zoomHeight: 350,
			lens: true,
			xOffset: 10,
			yOffset: 0,
			position: "right"
		};
		$('a.productImage').jqzoom(options);
		$('div.additional a').click(function () {
			$('a.productImage').attr('href', $(this).attr('href'));
			$('a.productImage img').attr('src', $(this).attr('rel'));
			return false;
		});
	}
	
	// Form validation
	if ($('form.validation').length > 0) {
		$('form.validation').submit(function() {
			var error = 'Please fill in the following required fields\n';
			var errorsExist = false;
			$(this).find('input.req').each(function() {
				if ($(this).val() < 1) {
					strip = this.id.replace(/_/, " ");
					error += strip + '\n';
					errorsExist = true;
				}
			});
			if (errorsExist) {
				alert(error);
				return false;
			}
		});
	}
	if ($('form#quicklinks').length > 0) {
		$('form#quicklinks').change(function () {
			var optionval = $('form#quicklinks select option:selected').val();
			if (optionval != 'null') {
				window.location = optionval;
				return false;
			}
		});
	}
});