jQuery.noConflict();

var plauditSite = (function($){
	
	var defaultMethods = function(){
		$("body").addClass("jsEnabled");
		$("tr:odd").addClass("odd");
		$(".searchForm input#query").focus(function(){ 
			$(this).data("inputValue",$(this).val()); // Store for use later if needed
			$(this).val("");
		});
		
		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, input[type='image']:first");
			    	if ( submitButtons.length > 0 ) {
			    		// handle the submit
			    		submitButtons.first().click();
			        	return false;
			    	}
			    	return true;
			    }
			});
		}
		
		$("#aside a[href^=\"http://\"]").attr("target", "_blank");
		
		// Setup submit
		$("#servicesType").change(function(){
			$(this).closest("form").submit();
		});
		
		$("#marketTypesFormSubmit").hide();
	}();
	
	var externalPlugins = function(){
		var params = { wmode: "transparent" };
		var attributes = {};
		var flashvars = {};
		
		swfobject.embedSWF("assets/flash/home.swf", "animationInner", "910", "320", "9.0.0", "assets/flash/expressInstall.swf", flashvars, params, attributes);
	}();
	
	var findForm = function( jQElem ) {
		return jQElem.parents("form:first");
	};
	
	// Setup General Page Media Gallery
	var mediaGallery = function(){
		
		var lightBoxOptions = {
			animationSpeed: 'normal',
			allowresize: false,
			showTitle: false,
			theme: 'light_rounded'	
		};
		
		var sliderOptions = {
			size: 1,
			clickable: false,
			next: "#next",
			prev: "#prev"
		};
		
		$("a[rel^='lightbox']").prettyPhoto(lightBoxOptions);
		$("#imageGallery").scrollable(sliderOptions);
	}();
	
	var accordians = function(){
		// Setup accordian
		
		$(".listItem span", $("#serviceList")).toggle(
			function(){
				$(this).siblings(".subSections").slideDown();
				$(this).parent().addClass("listItemOpen");
			}, function(){
				$(this).siblings(".subSections").hide();
				$(this).parent().removeClass("listItemOpen");
			}
		);
		
		//toggle -federal contracts
		$("#federal h3").toggle(function(){
			$(this).addClass("active");
			$(this).next("ul").slideDown();
		},function(){
			$(this).next("ul").hide();
			$(this).removeClass("active");
		});
		
	}();
	
	// Setup ToolTip
	var toolTip = function(){
		
		var documentHeight,
			toolTip = $("#overlay"),
			toolTipContent = $("#overlayContent"),
			toolTipHeight,
			toolTipY;
		
		function reverseToolTip(elem, height, point){
			// If tooltip is too tall for browser window flip
			var documentHiddenHeight = $(window).scrollTop();
			
			if ( elem.offset().top - documentHiddenHeight < 0 ) {
				elem.addClass("reversed").css({
					top: point + 25
				});
			}
		}
		
		$("#locationMap .mapPoint").hover(
			function(){
				
				var point = $(this) // cache this
				var pointX = point.offset().left;
				var pointY = point.offset().top;
				
				toolTipContent.empty();
				toolTipContent.append(point.children(".overlay").html());
				
				toolTipHeight = toolTip.height();
				
				toolTip.css({
					left: pointX - 138,
					top: pointY - toolTipHeight
				});
				
				// If Browsers supports opacity fadeIn otherwise just show
				if ($.support.opacity) {
					toolTip.fadeTo(350, 1);
					reverseToolTip(toolTip, toolTipHeight, pointY);
				} else {
					toolTip.show();
					reverseToolTip(toolTip, toolTipHeight, pointY);
				}
				
			}, function(){
				toolTip.hide().removeClass("reversed");
			}
		);
		
		$(".overlay ul").addClass("group");
		
	}();

	
})(jQuery);

