﻿//jQuery.noConflict();

jQuery(document).ready(function() {

	// Fields change colour when they're focused on
	jQuery(".forms input.field, .forms select.field").change(function() {
		jQuery(this).addClass("done");
	});

	// Selected state effect on radio button lists
	jQuery(".multiple-choice input[type=radio], .multiple-choice label").click(function() {
		var row = jQuery(this).parent().parent();
		row.siblings().removeClass("selected");
		row.addClass("selected");
	});
	jQuery(".multiple-choice input[type=radio]:checked").trigger('click');

	// Print button
	jQuery(".print img").click(function() {
		window.print();
	});

	// Image rollovers
	jQuery("a.rollover:not(:disabled)").hover(function() {
		jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace(".gif", "-hi.gif").replace(".jpg", "-hi.jpg"));
	}, function() {
		jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace("-hi.gif", ".gif").replace("-hi.jpg", ".jpg"));
	});

	jQuery("input.rollover:not(:disabled), img.rollover:not(:disabled)").hover(function() {
		jQuery(this).attr("src", jQuery(this).attr("src").replace(".gif", "-hi.gif").replace(".jpg", "-hi.jpg"));
	}, function() {
		jQuery(this).attr("src", jQuery(this).attr("src").replace("-hi.gif", ".gif").replace("-hi.jpg", ".jpg"));
	});

	// Help tip popups
	jQuery(".help-tip img").live("click", function() {
		jQuery(this).parent().find(".help-tip-popup").show();
	})
		.hover(function() {
			jQuery(this).attr("src", jQuery(this).attr("src").replace(".gif", "-hi.gif").replace(".jpg", "-hi.jpg"));
		}, function() {
			jQuery(this).attr("src", jQuery(this).attr("src").replace("-hi.gif", ".gif").replace("-hi.jpg", ".jpg"));
		});

	jQuery(".help-tip .close").live("click", function() {
		jQuery(this).parent().hide();
	});

	jQuery(".help-tip-popup").live("click", function() {
		jQuery(this).hide();
	});

	// Auto-jump for credit card number type fields
	jQuery(".auto-jump").live("keyup", function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		var key = String.fromCharCode(code);
		var regex = /[0-9A-Za-z]|\./;
		if (regex.test(key)) {
			if (jQuery(this).val().length >= 4) {
				if(!jQuery(this).hasClass("done"))
					jQuery(this).addClass("done");
				jQuery(this).next("input[type=text]:first").trigger("focus");
			}
		}
	});

	// Timetable {
	jQuery(".show-next a").live("click", function() {
		jQuery(".timetable tr.hide").show();
	});

});
