

$(document).ready(function(){

	inputs = $('#InquiryAddForm input:text');
	inputs.push($('textarea'));

	if(inputs.length) {
		jQuery.each(inputs, function(index, value){
			$(value).val($(value).attr('title'));
		});

		jQuery.each(inputs, function(index, value){
			$(value).bind('focus', function(e){
				if($(value).val() == $(value).attr('title')){
					$(value).val("");
				}
			});
		});

		jQuery.each(inputs, function(index, value){
			$(value).bind('blur', function(e){
				if(jQuery.trim($(value).val()).length < 1 ){
					$(value).val($(value).attr('title'));
				}
			});
		});
	}

	function slide(){
		pos = $('#slides').css('left');
		num_slides = $('#slides img').length;
		pos = parseInt(pos.replace('px', '')) - 950;
		pos = (pos == num_slides * -950) ?  0 : pos;

		$('#slides').animate({
			left: pos
		}, 1000 );
	}

	if($('#slides').length){
		//setInterval(function() { slide() }, 5000);
		$('#slides').cycle({fx:'fade', timeout:7000, speed:2000});
	}



	if($('#register').length){
		var submitter = $('input[type=submit]');
		submitter.bind('click', function(e){
			e.preventDefault();
			if($('#cancel_and_liable').attr('checked') != true){
				alert('Please check the box indicating you have read the cancellation policy and waiver of liability.')
			} else {
				//alert('All systems go...')
				if($('#register').valid()){
						submitter.css('display', 'none');
						$('#ajax').css('display', 'block');
						$('#register').submit();
				} else {
					alert('Please correct highlighted errors.');
				}

			}
		});

		$('#register').validate({
			rules: {
				'data[Student][credit_card_number]': {
					required: true,
					creditcard: true
				},
				'data[Student][email2]': {
					equalTo: '#StudentEmail'
				},
				'data[Student][ccv2_number]': {
					required: true,
					minlength: 3
				}
			}
		});
	}

	
	if($('#coupon').length){
		/*
		$('#coup').click(function(){
			$("#coupon_desc").load("/coupons/view/" + $('#coupon').val());
			return false;
		});
		*/
		$('#coupon').blur(function(){
			var val = $.trim($('#coupon').val());
			if(val.length){
				$("#coupon_desc").load("/coupons/view/" + val);
				return false;
			}
		});
	}

})