// Filetype icons and external links
$(document).ready(function() {	
		
	// Add pdf icons to pdf links
	$("a[href$='.pdf']").addClass("pdf").attr("target", "_blank");
	
	// Add email icons to email links
	$("a[href^='mailto:']").addClass("email");

	//Add external link icon to external links - 
	$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external").attr("target", "_blank");	
	 
});


/* Homepage Sliding Menu - Accordion */
$(document).ready(function () {
		
		$('#accordion li').click(function () {

			//slideup or hide all the Submenu
			$('#accordion li').children('ul').slideUp('slow');	
			
			//remove all the "Over" class, so that the arrow reset to default
			$('#accordion li > a').each(function () {
				if ($(this).attr('rel')!='') {
					$(this).removeClass($(this).attr('rel') + 'Over');	
				}
			});
			
			//show the selected submenu
			$(this).children('ul').slideDown('fast');
			
			//add "Over" class, so that the arrow pointing down
			$(this).children('a').addClass($(this).children('li a').attr('rel') + 'Over');			

		});
	
	});


/* Classes for the Homepage Sliding Menu - Accordion */
$(document).ready(function(){ 

			$("li.one").click( function(){ $
				("body").removeClass('bghome , bg2 , bg3 , bg4').addClass("bg1"); 
			});

			$("li.two").click( function(){ $
				("body").removeClass("bghome , bg1 , bg3 , bg4").addClass("bg2"); 
			});

			$("li.three").click( function(){ $
				("body").removeClass("bghome , bg1 , bg2 , bg4").addClass("bg3"); 
			}); 
			
			$("li.four").click( function(){ $
				("body").removeClass("bghome , bg1 , bg2 , bg3").addClass("bg4"); 
			}); 
				
		});


(function($) {
	
	$.fn.toggleVal = function(theOptions) {
		// check whether we want real options, or to destroy functionality
		if(!theOptions || typeof theOptions == 'object') {
			theOptions = $.extend({}, $.fn.toggleVal.defaults, theOptions);
		}
		else if(typeof theOptions == 'string' && theOptions.toLowerCase() == 'destroy') {
			var destroy = true;
		}
		
		return this.each(function() {
			// unbind everything if we're destroying, and stop executing the script
			if(destroy) {
				$(this).unbind('focus.toggleval').unbind('blur.toggleval').removeData('defText');
				return false;
			}
			
			// define our variables
			var defText = '';
			
			// let's populate the field, if not default
			switch(theOptions.populateFrom) {
				case 'title':
					if($(this).attr('title')) {
						defText = $(this).attr('title');
						$(this).val(defText);
					}
					break;
				case 'label':
					if($(this).attr('id')) {
						defText = $('label[for="' + $(this).attr('id') + '"]').text();
						$(this).val(defText);
					}
					break;
				case 'custom':
					defText = theOptions.text;
					$(this).val(defText);
					break;
				default:
					defText = $(this).val();
			}			
			
			$(this).addClass('toggleval').data('defText', defText);
			
		
			if(theOptions.removeLabels == true && $(this).attr('id')) {
				$('label[for="' + $(this).attr('id') + '"]').remove();
			}
			
			
			$(this).bind('focus.toggleval', function() {
				if($(this).val() == $(this).data('defText')) { $(this).val(''); }
				
				
				$(this).addClass(theOptions.focusClass);
			}).bind('blur.toggleval', function() {
				if($(this).val() == '' && !theOptions.sticky) { $(this).val($(this).data('defText')); }
				
			
				$(this).removeClass(theOptions.focusClass);
				if($(this).val() != '' && $(this).val() != $(this).data('defText')) { $(this).addClass(theOptions.changedClass); }
					else { $(this).removeClass(theOptions.changedClass); }
			});
		});
	};
	
	// default options
	$.fn.toggleVal.defaults = {
		focusClass: 'tv-focused', // class during focus
		changedClass: 'tv-changed', // class after focus
		populateFrom: 'default', // choose from: default, label, custom, or title
		text: null, // text to use in conjunction with populateFrom: custom
		removeLabels: false, // remove labels associated with the fields
		sticky: false // if true, default text won't reappear
	};
	
	// create custom selectors
	// :toggleval for affected elements
	// :changed for changed elements
	$.extend($.expr[':'], {
		toggleval: function(elem) {
			return $(elem).data('defText') || false;
		},
		changed: function(elem) {
			if($(elem).data('defText') && $(elem).val() != $(elem).data('defText')) {
				return true;
			}
			return false;
		}
	});
})(jQuery);


// load toggle

		$(document).ready(function() {
		
			
			$("#searchform input[name='SearchString']").toggleVal();
			
			
		});


