function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if (thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

var millisPerSlide = 600;
var fadesPerSlide = 5;
var partialFades = 2;
function fadeTo(o, timeout, opacity) {
	setTimeout(function() {
		// console.log('fading ' + $(o).find('img').attr('src') + ' to ' +
			// opacity );
			$(o).css('opacity', opacity);
			$(o).css('display', 'block');
		}, timeout);

}
function completeFade(curr, next, to) {
	setTimeout(function() {
		// console.log('completing fade');
			$(curr).find('a').css('top', '-9000').css('left', '-9000');
			$(curr).css('display', 'none');
			$(next).find('a').css('top', '0').css('left', '0');
		}, to);
}
$.fn.cycle.slideFade = function(curr, next, opts, after) {
	var pFade = Math.floor(fadesPerSlide / partialFades);
	// Swap the z-index so the next slide is on top of the current one
	$(next).css('display', 'block').css('z-index', '19');
	$(curr).css('z-index', '1');
	// Call fade to on each fade so we can set a timeout for each fade
	// level
	for (i = 0; i <= fadesPerSlide; i++) {
		if (i != 0 && i % pFade == 0) {
			fadeTo(curr, i * millisPerSlide / fadesPerSlide - 10, 1 - i
					/ fadesPerSlide);
			$("#counter").text(i);
		}
		fadeTo(next, i * millisPerSlide / fadesPerSlide, i / fadesPerSlide);
	}
	setTimeout(function() {
		$(curr).find('a').css('top', '-9000').css('left', '-9000');
		$(curr).css('display', 'none').css('opacity', '0');
		$(next).find('a').css('top', '0').css('left', '0');
		opts.busy = 0;
	}, millisPerSlide);

};
$.fn.cycle.transitions.none = function($cont, $slides, opts) {
	opts.fxFn = function(curr, next, opts, after) {
		$(next).show();
		$(curr).hide();
		after();
	};
};
$.fn.cycle.transitions.slideFade = function($container, $slides, opts) {
	opts.before.push(function(curr, next, opts) {
		$.fn.cycle.commonReset(curr, next, opts, true, false, true);
	});
};
$.fn.popupWindow = function(instanceSettings) {
	$.fn.popupWindow.defaultSettings = {
			centerBrowser : 0, // center window
			// over browser ?
			centerScreen : 0, // center window
			// over entire
			// screen?
			height : 500, // sets the height
			// in pixels of the
			// window.
			left : 0, // left position when
			location : 0,
			menubar : 0,
			resizable : 0,
			scrollbars : 0,
			status : 0,
			width : 500,
			windowName : null,
			windowURL : null,
			top : 0,
			toolbar : 0,
			event: 'click'
		};

		settings = $.extend( {},
				$.fn.popupWindow.defaultSettings,
				instanceSettings || {});
	return this
			.each(function() {
				$(this)
						.bind(settings.event,
								function() {
									

									var windowFeatures = 'height='
											+ settings.height + ',width='
											+ settings.width + ',toolbar='
											+ settings.toolbar + ',scrollbars='
											+ settings.scrollbars + ',status='
											+ settings.status + ',resizable='
											+ settings.resizable + ',location='
											+ settings.location + ',menuBar='
											+ settings.menubar;

									settings.windowName = this.name
											|| settings.windowName;
									settings.windowURL = this.href
											|| this.action
											|| settings.windowURL;
									var centeredY, centeredX;
									if (settings.centerBrowser) {
										if ($.browser.msie) {
											centeredY = (window.screenTop - 120)
													+ ((((document.documentElement.clientHeight + 120) / 2) - (settings.height / 2)));
											centeredX = window.screenLeft
													+ ((((document.body.offsetWidth + 20) / 2) - (settings.width / 2)));
										} else {
											centeredY = window.screenY
													+ (((window.outerHeight / 2) - (settings.height / 2)));
											centeredX = window.screenX
													+ (((window.outerWidth / 2) - (settings.width / 2)));
										}
										window.open(
												settings.windowURL,
												settings.windowName,
												windowFeatures + ',left='
														+ centeredX + ',top='
														+ centeredY).focus();
									} else if (settings.centerScreen) {
										centeredY = (screen.height - settings.height) / 2;
										centeredX = (screen.width - settings.width) / 2;
										window.open(
												settings.windowURL,
												settings.windowName,
												windowFeatures + ',left='
														+ centeredX + ',top='
														+ centeredY).focus();
									} else {
										window.open(
												settings.windowURL,
												settings.windowName,
												windowFeatures + ',left='
														+ settings.left
														+ ',top='
														+ settings.top).focus();
									}
									return false;
								});

			});
};
$(document)
		.ready(
				function() {
					var t;
					if ($("#leftNav").children().size() > 0)
						$("#leftNav").corner("tr br 5px");
					else
						$("#leftNav").remove();

					$(".newsAccordion>div").hover(
							function() {
								clearTimeout(t);
								$(this).removeClass("collapsedNews");
								$(this).addClass("expandedNews");
								var $sibs = $(this).siblings(".expandedNews")
										.each(
												function() {
													$(this).removeClass(
															"expandedNews");
													$(this).addClass(
															"collapsedNews");
												});
							}, function() {
								var $this = $(this);
								t = setTimeout(function() {
									$this.removeClass("expandedNews");
									$this.addClass("collapsedNews");
									var $sibs = $this.parent().children();
									$first = $($sibs[0]);
									$first.removeClass("collapsedNews");
									$first.addClass("expandedNews");
								}, 3000);
							});
					$('#suggestion_form input:first-child')
							.focus(function() {
								var box = $(this);
								box.css('background-image', 'none');
							})
							.blur(
									function() {
										var box = $(this);
										if (box.val().length <= 0) {
											box
													.css('background',
															"url('/vgn-ext-templating/static/images/searchbox.gif') no-repeat 2px 2px");
										}
									}).blur();
					$('#navContainer>ul>li:last').css('width', '209px').css(
							'margin-right', 0);
					$('#navContainer li').hover(function() {
						$(this).toggleClass('sfhover', true);
					}, function() {
						$(this).toggleClass('sfhover', false);
					});
					$('.maaForm').popupWindow( {
						centerBrowser : 1,
						width : 620,
						height : 670,
						scrollbars : 1,
						windowName : 'makeAppt',
						event: 'submit'
					});
					
					$('.button').mouseover( function() {
						var but = $(this);
						but.addClass('hover_button');
					}).mousedown( function () {
						var but = $(this);
						but.removeClass('hover_button');
						but.addClass('active_button');
					}).mouseup( function () {
						var but = $(this);
						but.removeClass('hover_button');
						but.removeClass('active_button');
					}).mouseout( function () {
						var but = $(this);
						but.removeClass('hover_button');
						but.removeClass('active_button');
					});
				});
