(function($) {				    

	
	$.fn.searchFocus = function() {
		this.focus(function() {
			if (this.value=="SEARCH")					
				this.value = "";
		}).blur(function() {
			if (this.value=="")
				this.value = "SEARCH";
		});
	}
	
	$.fn.tileSwitch = function() {
		
		bannerLists = $(this).parent().parent();
		// array of id and associated background images for #banner-bg
		bannerBg = {'tile1':'banner-img1a.jpg','tile2':'banner-img2.jpg','tile3':'banner-img2.jpg','tile4':'banner-img2.jpg'};
		
		//console.log($("#banner-bg").css('background-image'));
		
		blockAnimation = false;		
		$(this).click(
			function(){				
				
				if (blockAnimation != true) {
					blockAnimation = true;
					
					listParent = $(this).parent().parent();
					tileSiblingID = $(this).parent().next().attr('id');
					sliderStart = $('#redSlider').position().left;
					sliderEnd = $(listParent).position().left;
					slidePix = sliderEnd - sliderStart + 20;
					
					if (listParent.attr('class') == "active") { blockAnimation=false;return false;}								
					
					$(".spinner").show();
					$("#banner-bg2").css('background-image',$("#banner-bg").css('background-image')).show();
					//$("#banner-bg").hide();	
	
					// remove all the li's from being active
					$(bannerLists).each(
						function() { bannerLists.attr('class',''); }
					);																		
					
					$('<img id="loadimg" />').attr('src','images/'+bannerBg[tileSiblingID]).one("load",
						function() {						
							$(".spinner").hide();
							$(".tiles").hide();														
							
							$("#"+tileSiblingID).show();
							
							$("#banner-bg").css('background-image','url(images/'+bannerBg[tileSiblingID]+')');												
							// after load of bg image, slide the red bg
							$('#redSlider').animate(
									{"left":"+="+slidePix+"px"},
									"medium",						
									function() {										
										listParent.attr('class','active');
										blockAnimation=false;
										//$("#"+tileSiblingID).show();
									}
								);																						
							$("#banner-bg2").fadeOut('slow');																					
						}
					// if cached in browser, trigger a load
					).each(function(){ 
						if(this.complete) $(this).trigger("load");
						
						//$(this).trigger("load");
					});
					
				}
				
				return false;
			}
		);
		
	}		
	
	$.fn.dropDowns = function() {
				
		// get rid of nav css hover elements
		//$('#navbar li').removeClass();
		
		// array of width and background-position x values
		var bgX = [[84,0],[104,84],[115,188],[120,303],[125,423],[106,548],[92,654]];
		
		// grab the active menu item
		activeUL = '#' + $(this).attr('id');
		
		// set the width for the anchor tag to inherit
		$(activeUL).children('li').each(			
			function(i){
				navMatch = i+1;
				if ($(this).attr('class').indexOf("active") != -1 ) {
					$(this).attr('class','jqnav'+i+' nav'+navMatch+' active')
				} else {
					$(this).attr('class','jqnav'+i)					
				}
				$(this).css({'width': bgX[i][0]+'px'});
			}			
		);
		
		// set actions for mouseover,mouseout
		$(activeUL).children('li').hoverIntent(
			function(){				
				// grab the number of the class to associate with background-position x value from bgX array
				navNum = $(this).attr('class').substring(5,6);
				if ( $(this).attr('class').indexOf("active") != -1 ) {
					$(this).removeClass('active');
					$(this).addClass('wasactive');
				}
				$(this).css('background','url(images/sprite-navbar.gif) no-repeat -'+bgX[navNum][1]+'px -61px');
				$('ul', this).slideDown('fast');
			},
			function() {
				masterHov = $(this);				
				navNum = $(masterHov).attr('class').substring(5,6);
				// check to see if a subnav ul exists before running a slide - if not then just toggle bg image sprite
				if (  $(this).children('.subnav').length ) {
					// on finish of slideUp toggle bg image sprite
					$('ul', this).slideUp('fast',
						function(){
							// regrabbing this as hoverIntent plugin
							navNum = $(masterHov).attr('class').substring(5,6);						
							$(masterHov).css('background-position','-'+bgX[navNum][1]+'px 0px');
							if ( masterHov.attr('class').indexOf("wasactive") != -1 ) {								
								masterHov.addClass('active');					
							}
						}
					);
				}else{					
					$(masterHov).css('background-position','-'+bgX[navNum][1]+'px 0px');
				}
			}
		);
	 
		return this;
	 
	};		
		
	
})(jQuery);

