var plauditUI = (function($){
	
	var ui = {
		common: function(){
			$('a[href^="http://"]').not(".calendar-link").attr({target: "_blank", title: "Opens in a new window"});
			$("a[href*=.pdf]").attr("target","_blank");
			
			$("#main-search-form, #inline-search-form").placeHolder("Site Search...");
			$("#associate-search-form").placeHolder("First and/or Last Name");
			
			if ( $.browser.msie	&& parseInt($.browser.version) < 9 ) {
				// Some versions of ie do not submit the form using the first submit if the field only contains
				// one input field. We must have it use the first button so the correct JSF action runs.
				$('input').keypress(function(event){
					var input = $(this);
				    if (event.keyCode == 13) {
				    	var submitButtons = input.closest("form").find(":submit:first, input.submit:first");
				    	if ( submitButtons.length > 0 ) {
				    		// handle the submit
				    		submitButtons.first().click();
				        	return false;
				    	}
				    	return true;
				    }
				});
			}
			
			$("#calendar-select select").change(function(){
				$(this).closest("form").submit();
			});
			$("#calendar-select input[type='submit']").hide();
					
		}// common
		,associatesForm: function(){
			var associatesInput = $("#associate-search-form input.query");
			if(associatesInput.val() == "First and/or Last Name"){
				associatesInput.val("");
			}
		}// associatesForm
		,lightBox: function(){
			$('a.image-link').lightBox({
				imageLoading: 'images/lightbox/loading.gif',
				imageBtnClose: 'images/lightbox/close.gif',
				imageBtnPrev: 'images/lightbox/prev.gif',
				imageBtnNext: 'images/lightbox/next.gif'
			});
		}// lightBox
		,sideBarGallery: function(){
			$('#right-sidebar .imageGroup').cycle('fade');
		}// sideBarGallery
		,slideDowns: function(){
			$(".extraInfo").hide();
			$(".readMore").toggle(
				function(){
					$(".extraInfo").slideDown();
				}, function(){
					$(".extraInfo").slideUp();
				}
			);
		}// slideDowns
		,swfObject: function(){
			if ($("#home-animation").length){
				swfobject.embedSWF("flash/home.swf", "home-animation-inner", "912", "214", "9.0.0", {}, {},{wmode:'opaque',bgcolor:'#FFFFFF'});
			}
		}// swfObject
		,captchaAttack: function(){
			if ( $('#home-recaptcha').length > 0 ){
				$("#recaptcha_area").hide( 'fast', function(){
					$(this).addClass('jquery')
				} );
				var theForm = $("#home-subscribe");
				$('body').click(function(evt){
					if ( $(evt.target).parents("#home-subscribe").length > 0 ){
						//console.log( 'show it' );
						theForm.animate({ 
							width: 320 
							}, 500, function() {
								$(this).addClass('expanded');
								$("#recaptcha_area").show('slow');
						});
					} else {
						//console.log( 'hide it' );
						$("#recaptcha_area").hide('normal', function(){
							theForm.removeClass('expanded');
						});
						theForm.animate( {width: 191}, 400);
					}
				});
			}
		}// captchaAttack
		,init: function(){
			this.common();
			this.lightBox();
			this.sideBarGallery();
			this.slideDowns();
			this.swfObject();
			this.captchaAttack();
		}		
		
	}; // End UI Def
	
	return ui;
	
})(jQuery); // End onload func


$(function(){
	plauditUI.init();
});



