var capterra_vkey = 0;
var capterra_vid = 0;
var capterra_prefix  = 0;

jQuery.noConflict();

jQuery(document).ready(function(){
	jQuery('.popupImage').fancybox({
	});
	jQuery('.popupButton').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Popup', 'Image', location.href]);
	});
	
	jQuery('.popupButton').fancybox({
		'padding'           : 0,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'height'			: 300,
		'width'				: 530
	});
	jQuery('.popupButton').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Form', 'MultiContactButtonPopup', location.href]);
	});
	
	jQuery('.emr4video').fancybox({
		'padding'           : 0,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'autoDimensions' 	: true,
		'height'			: 375,
		'width'				: 655
	});
	jQuery('.emr4video').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Video', 'Play: '+self.attr('href'), location.href]);
	});
   
   jQuery(".playvideo_hover").fancybox({
	    'padding'           : 0,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'autoDimensions' 	: true,
		'height'			: 410,
		'width'				: 655
	});
	jQuery('.playvideo_hover').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Video', 'Play: '+self.attr('href'), location.href]);
	});
	
	jQuery(".playvideo_hover_tall").fancybox({
	    'padding'           : 0,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'autoDimensions' 	: true,
		'height'			: 530,
		'width'				: 655
	});
	jQuery('.playvideo_hover_tall').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Video', 'Play: '+self.attr('href'), location.href]);
	});
	
	jQuery(".playvideo_hover_640").fancybox({
	    'padding'           : 0,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'autoDimensions' 	: true,
		'height'			: 495,
		'width'				: 655
	});
	jQuery('.playvideo_hover_640').click(function() {
		var self = jQuery(this);
		_gaq.push(['_trackEvent', 'Video', 'Play: '+self.attr('href'), location.href]);
	});
	
	
	jQuery("#navigation li").hover(
		function(){ jQuery("ul", this).fadeIn("fast"); }, 
		function() { jQuery("ul", this).fadeOut("fast");} 
	);
	
   
/*
   
	$('.readmore').click(function(e) {
		e.preventDefault();
		$(this).prev('p').fadeOut();
  		$(this).next('.full_bio').fadeIn();
  		$(this).fadeOut();

	}); 
*/
	
jQuery('div.full_bio').expander({
    slicePoint:       117,  // default is 100
    expandText:         '[...]', // default is 'read more...'
    collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
    userCollapseText: 'Read Less'  // default is '[collapse expanded text]'
  });
jQuery('div.faq_answer').expander({
		slicePoint: 250,
		widow: 20,
		expandText: 'Show Full Answer',
		colapseTimer: 0,
		userCollapseText: 'Hide Answer'
	});
/*
jQuery('#PageCommentInterface_Form_PostCommentForm').expander({
	slicepoint: 0,
	widow: 0,
	expandText: 'Click Here.',
	collapseTimer: 0,
	userCollapseText: 'Hide Form'
	});
 */
var error = jQuery('#PageCommentInterface_Form_PostCommentForm').val();
if (error == ''){
jQuery('#PageCommentInterface_Form_PostCommentForm').hide();
jQuery('#PageCommentInterface_Form_PostCommentForm').after('<a href="#" id="FormDisplayButton">Click Here.</a>');
jQuery('#FormDisplayButton').bind('click', function() {
	jQuery('#FormDisplayButton').hide();
	jQuery('#PageCommentInterface_Form_PostCommentForm').fadeIn();
	return false;
});
}

	jQuery('.formFieldText').bind('click', function(){this.select()});

	//jQuery('#index_page .ContactFormWidget').hide();
	//jQuery('#promisee').hide();
	jQuery('#employees').hide();
	jQuery('iframe#ExternalEmbeddedPage').hide();
	jQuery('iframe#ExternalEmbeddedPage').load(function(){
		jQuery('iframe#ExternalEmbeddedPage').fadeIn();
	});
}); // ends the main block onLoad

jQuery(window).load(function() {
	// 4.0 stuff
	jQuery('#emr4').delay(1000).animate({bottom: '10px'}, 1000).delay(1000);
	//jQuery('#emr4').delay(3000).animate({bottom: '15px'}, 300);
	//jQuery('#emr4').delay(300).animate({bottom: '10px'}, 300);
	bounce('#emr4', 10, 4000);
	
	jQuery('#valantemr_moreinfo').masonry();
	jQuery('#mentalhealth_moreinfo').masonry();

	//jQuery('#index_page .ContactFormWidget').delay(300).fadeIn(800);
	jQuery('#employees').fadeIn(2000, function(){});
	jQuery('#employees').jCarouselLite({
           btnNext: ".next",
           btnPrev: ".prev",
           visible: 1,
           auto: 5000
   	});
   
   jQuery('#promisee').cycle({ timeout: 3000, cleartype: 1, speed: 400 });
	//jQuery('#promisee').delay(300).fadeIn();
});

function bounce(el, times, delay) {
	if (times >= 1) {
		jQuery(el).animate({bottom: '+=4px'}, 300);
		jQuery(el).delay(300).animate({bottom: '-=4px'}, 300);
		times--;
		setTimeout('bounce("'+el+'", '+times+', '+delay+')', delay);
	}
}

function isJunkPhone(phone) {
	if (phone.indexOf('202-') != -1) {
		return true;
	}
	if (phone.indexOf('810-') != -1) {
		return true;
	}
	return false;
}

function valantSubmitContactForm() {
	// checks for bogus phone numbers
	if (isJunkPhone(jQuery('#fld_2').attr('value'))) {
		return false; // #fld_2 is the phone field
	}
	
	_gaq.push(['_trackEvent', 'Form', 'RequestFreeDemoSubmit', location.href]);
	_gaq.push(['_trackPageview','/thankyou/Signup']); //conversion
	// Capterra tracking
	capterra_vkey = "e0bac2bfcd0cc1292b93d529fc96c57f";
	capterra_vid = "2049811";
	capterra_prefix  = (("https:" == document.location.protocol) ? "https://ct.capterra.com" : "http://ct.capterra.com");
	(function() {
		var cap = document.createElement('script'); cap.type = 'text/javascript';
		cap.src = capterra_prefix + "/capterra_tracker.js?vid=" + capterra_vid + "&vkey=" + capterra_vkey;
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cap, s);
	})();
	// end Capterra tracking
	
	var form = jQuery('#free_demo_small');
	jQuery('#footer').append('<iframe id="SUBMITFORMIFRAME" name="SUBMITFORMIFRAME" src="" width="100" height="100" style="display: none;"></iframe>');
	form.attr('target', 'SUBMITFORMIFRAME')
	setTimeout('cleanUpForm()', 200);
	var name = jQuery('#fld_1_fn').attr('value');
	var nameArray = name.split(' ');
	if (nameArray && nameArray.length > 0) {
		var fnString = '';
		
		for (var i = 0; i < nameArray.length - 1; i++) {
			if (i == 0) {
				fnString = nameArray[i];
			} else {
				fnString = fnString + ' ' + nameArray[i];
			}
		}
		
		jQuery('#fld_1_fn').attr('value', fnString);
		jQuery('#fld_1_ln').attr('value', nameArray[nameArray.length - 1]);
	}
	
	document.getElementById('free_demo_small').submit();
}
function cleanUpForm() {
	var form = jQuery('#free_demo_small');
	form.append('<p class="thankyou">Thank You!</p>');
}
