(function ($) {
        $('ul.menu_top li li a.current').parentsUntil('ul.menu_top').addClass('current');
	$('ul.menu_top').superfish();
	$('.support_container').hide();
	$('.support_label').toggle(function() {
		$('.support_container').slideDown("slow");
		$(this).html('CLOSE');
	}, function() {
		$('.support_container').slideUp("slow");
		$(this).html('SUPPORT');
	});
	/*
	$("#accrinet_tweet_feed").tweet({
		username: "accrinet",
		avatar_size: 0,
		count: 2,
		template: "{join}{text}",
		loading_text: "loading tweets..."
	});
	*/

	$("#toTop").scrollToTop({
		speed: 500,
		start: 200
	});
	$('.leftcolboxmid').filter(function () {
		return ($(this).height() === 0);
	}).each(function () {
		var removeSet = $().add(this).add($(this).prev())
			.add($(this).next());
		removeSet.remove();
	});
	(function () { 
		//for getting fields necessary to submit forms from another page
		//if you use this, e-mail thomas.hopkins@accrinet.com with any questions
		var getHiddenFields,
			submitInlineForm;
		getHiddenFields = function (formName, formSelector, submitInline) {
			if ($(formSelector).length === 0) {
				return false;
			}
			$.ajax({
				url: 'index.php',
				cache: false,
				dataType: 'html',
				data: {
					'src' : 'forms',
					'ref' : encodeURIComponent(formName)
				}
			}).done(function (d) {
				$(d).find('#form div:hidden > input[type="hidden"]')
					.appendTo(formSelector);
				if (submitInline === true) {
					submitInlineForm(formSelector);
				}
			});
		};
		submitInlineForm = function (formSelector) {
			var cleanupForm = function () {
				$(formSelector).find('input,textarea').not(':hidden').not('input[type="submit"]').val('');
				window.initFormPlaceholders();
				$('.support_container').slideUp("slow");
				$('.support_label').html('SUPPORT');
			};
			$(formSelector).submit(function (evt) {
				var formData = $(this).serialize(),
					shouldFail;
				evt.preventDefault();
				$('input', this).not(':hidden').each(function () {
					if ($(this).val() === '' || $(this).hasClass('placeholder')) {
						alert('Please complete all fields; enter N/A if the field does not apply.');
						shouldFail = true;
						return false;
					}
				});
				if (shouldFail === true) {
					return false;
				}
				$.ajax({
					url: 'index.php',
					cache: false,
					type: 'post',
					data: formData
				}).done(function (d) {
					if ($(d).find('#form-submit-success').length === 1) {
					$.fancybox({
							content: $(d).find('#form-submit-success').parent().text(),
							title: 'Thank you!',
							autoDimensions: false,
							width: 300,
							height: 'auto',
							onClosed: cleanupForm
						});
					} else {
						$.fancybox({
							content: 'There was an error submitting this form. ' +
								'Please call us at (888) 965-3330 if the problem persists.',
							title: 'Error!',
							autoDimensions: false,
							width: 325,
							height: 'auto',
							onClosed: cleanupForm
						});
					}
				});
			});
		};
		getHiddenFields('TROUBLE_TICKET', 'form.supportTicket', true);
		getHiddenFields('Call to Action - Request for Info', '#call-to-action-form');
	}());
	/*
	$("a.fbox-iframe").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'width' : '75%',
		'height' : '75%',
		'type' : 'iframe'
	});
	*/
	
}(jQuery));
