var gClientId = 45452;
var gYdlCTCNumbers = {
	'loc:1275491003':'518-290-1493', // Schenectady
	'loc:1340124173':'908-312-2661', // Columbia
	'loc:1341061362':'518-290-1890', // Delmar
	'loc:1341062940':'518-293-0340', // Glens Falls
	'loc:1341063347':'845-459-3199', // Hopewell Junction
	'loc:1341063581':'845-459-3201', // Middletown
	'loc:1341063819':'607-215-4526', // Vestal
	'loc:1341063836':'607-216-9390', // Vestal Sheetmetal
	'loc:1341242980':'845-232-0407' // Poughkeepsie
	};

$(document).ready(function(){
	//setInterval( function() {rotateImage('.slideshow', 'img');}, 7000 );
	initMenu();
})

function initMenu() {
	$('.dropdown').each(function(){
		var t = null;
		var $li = $(this);
		$li.hover( function(){
			t = setTimeout(function(){
					$li.find('ul').slideDown(150);
					t = null;
				}, 200);
		}, function(){
			if (t) {
				clearTimeout(t);
				t=null;
			} else {
				$li.find('ul').slideUp(150);
			}
		});	
	});
}

function rotateImage( slideshowSelector, slideSelector ) {
    var $active = $( slideshowSelector + ' '+slideSelector+'.active');

    if ( $active.length == 0 ) $active = $(slideshowSelector + ' '+slideSelector+':last');

    var $next =  $active.next().length ? $active.next()
        : $(slideshowSelector + ' '+slideSelector+':first');

    $active.addClass('last-active').removeClass('active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function validateForm() {
	var msg = '';

	msg += validateField( 'Name', 'Please fill in a name<br/>', validateHasValue );
	msg += validateField( 'Phone', 'Please fill in a phone number<br />', validateHasValue );
	msg += validateField( 'Email', 'Please fill in an email address<br />', validateIsEmail );
	
	if ( msg == '' ) {
		return true;
	} else {
		$('.required-msg').addClass( 'form-error' );
		return false;
	}

}

function validateField( fieldName, failMessage, testFunction ) {
	var field = document.getElementById( fieldName );
	var value = field.value;
	if ( testFunction( value ) ) {
		field.className = '';
		return ''; 
	} else {
		field.className = 'form-error';
		return failMessage;
		valid = false;
	}
}

function validateHasValue( value ) {
	return value != '';
}

function validateIsEmail( value ) {
	return value.indexOf('@') > -1;
}
