/* Author: 

*/
$(document).ready(function(){
	if ((screen.width<1024)&&(screen.width>480)) {
		// POTENTIAL 800 X 600 MONITOR
		$("#size-stylesheet").attr("href", "/css/style-800.min.css?v=6");
	}

	/*******************************************************************************
	CYCLE THE HEADER PHOTOS
	*******************************************************************************/
	$('#slideshow').cycle({
		//height:       '220px', // container height 
		after:   onAfter      // function to run
	});
	function onAfter() {
		$('#output').html("Current anchor: " + this.href);
	}

	/*******************************************************************************
	SCROLL TO TOP
	*******************************************************************************/
	var toTop=$("#toTop");
	if ($(window).scrollTop() == 0) {
		toTop.fadeOut(1000);
	}
	$(window).scroll(function() {
		if ($(this).scrollTop() != 0) {
			toTop.fadeIn();
		} else {
			toTop.fadeOut();
		}
	});
	toTop.click(function(event) {
		event.preventDefault();
		$("html,body").animate({scrollTop: 0},800);
	});
});

/*******************************************************************************
VALIDATE CONTACT FORM
*******************************************************************************/
$(function() { 
	$('#contact_form').validity(function() {
		$("#name")
			.require();
		$("#phone")
			.require()
			.match("phone");
		$("#email")
			.require()
			.match("email");
	});
});
// new output mode
(function(){
	$.validity.outputs.custom = {
		start:function(){ 
			$("input:text,tel,email")
			.css({border:'1px solid green'})
			.removeClass('fail');
		},
		end:function(results) { 
			if (!results.valid && $.validity.settings.scrollTo) {
				location.hash = $(".fail:eq(0)").attr('id')
			}
		},
		raise:function($obj, msg){
			alert(msg);
			$obj
			.css({borderColor:'red'})
			.addClass('fail');
		},
		// Our aggregate raise will just raise the error on the last input:
		raiseAggregate:function($obj, msg){ 
			this.raise($($obj.get($obj.length - 1)), msg); 
		}
	}
})();
$.validity.setup({ outputMode:'custom' });
