$(document).ready(function() {	

	// Pretty Photo
	$("a[rel^='lightbox']").prettyPhoto({
		show_title: false,
		theme: 'pp_default',
		autoplay: true,
		opacity: 0.6,
		social_tools: false
	});

	// Image Slider  	
	$('#home-slider ul').cycle({ 
		fx:      'fade',
        timeout:  7000,
		pause:    1,
        prev:    'a.slider-left',
        next:    'a.slider-right'
	});
	
	// Display/ Hide arrows
	$('#home-slider').hover(
		function () {
			$("a.slider-left, a.slider-right").fadeIn('slow');
		}, 
		function () {
			$("a.slider-left, a.slider-right").fadeOut('slow');
		}
	);
	
	
	// Features hover select
	$(".features .col").not("#special").hover(
		function () {
			$(".features .col").removeClass("red");
			$(this).addClass('red');
		}, 
		function () {
			$(".features .col").removeClass("red");
		}
	);
	
	
	// Match container height
	equalHeight($(".equalheight"));

	
	
	// Textbox focus/ blur
	$('input.textbox, textarea').each(function() {
		var default_value = $(this).attr('title');
		if(default_value){
			$(this).focus(function() {
				if(this.value == default_value) {
					this.value = '';
				}
			});
			$(this).blur(function() {
				if(this.value == '') {
					this.value = default_value;
				}
			});
		}
	});	
	
	// Only allow alpha numeric chars
	$(".alpha").bind("paste", function(e){removeAlphaChars(this, e);});
	$(".alpha").bind("keyup", function(e){removeAlphaChars(this, e);});
	
	// Only allow numeric chars
	$(".numeric").bind("paste", function(e){allowNumbers(this, e);});
	$(".numeric").bind("keyup", function(e){allowNumbers(this, e);});
	
});

function removeAlphaChars(txt, e) {
	setTimeout(function() {
		var initVal = $(txt).val();

		outputVal = initVal.replace(/[^A-z0-9]/g,"");

		if (initVal != outputVal)
			$(txt).val(outputVal);
	},1);
}
function allowNumbers(txt, e) {
	setTimeout(function() {
		var initVal = $(txt).val();

		outputVal = initVal.replace(/[^0-9]/g,"");

		if (initVal != outputVal)
			$(txt).val(outputVal);
	},1);
}
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
