// Functions specific to a site.

(function($) {
	$(document).ready(function() {
		// Place document manipulation code here
		Cufon.replace('h1, .job-header, .home .message span, .home .message p, h3');
		
		$('#subnav .current_page_item > a').addClass('active');
		
		//$('#mainnavigation .menu > ul').addClass('L1');
		$('#mainnavigation ul ul li:last-child').addClass('last-child');
		$('#mainnavigation .menu > ul > li:contains("Home")').addClass('nav-home');
		
		$('.district-info tr:last-child').addClass('last-row');
		$('.quick-facts tr:last-child').addClass('last-row');
		$('.quick-facts tr td:even').addClass('last-cell');
		
		$('#searchsubmit').val('');
		if($('#s').val() == ''){
			$('#s').val('Search');
		}
		$('#s').focus( function(){ 
			var focusVal = $(this).val();
			if (focusVal == 'Search') {
				$(this).val('');
			}
		});
		$('.accordian table tr:first-child').addClass('table-header');
		$('.accordian table tr:last-child').addClass('last-row');
		$('ul.accordian > li > a:first-child').attr('href', 'javascript:void[0]');
		$('.accordian a').click( function() {
			if($(this).parent().hasClass('open')) {
				$(this).parent().animate({height: '40px'}, 200).removeClass('open');
			} else {
				$(this).parent().css('height', 'auto');
				var accHeight = $(this).parent().css('height');
				$(this).parent().css('height', '40px');
				$(this).parent().addClass('open').animate({ height: accHeight}, 200);
			}
		});
		
		$('.cta-newsletter .submit').val('');
		$('.cta-newsletter .signup').focus( function(){
			if($(this).val() == 'Your Email') {
				$(this).val('');
			}
		});
		$('.cta-newsletter .signup').blur( function(){
			if($(this).val() == '') {
				$(this).val('Your Email');	
			}
		});
		$('.cta-gallery li a').fancybox({
			
		});
//	Superfish drop-down menus
//		jQuery('.menu > ul').superfish({
//		$('.menu > ul').superfish({
//			delay: 500, // one second delay on mouseout
//			animation: { opacity: 'show' }, // fade-in and slide-down animation
//			speed: 'fast', // faster animation speed
//			autoArrows: false,
//			dropShadows: false
//		});
		
		var district = $('#District');
		if (district.length != 0) { // DOM Exists
			var suggestions = [];
			var url = [];
			district.autocomplete( {
				minLength: 0,
				source : function(req, add) {
					/*$.ajax( {
					  url : 'wp-content/themes/future/school-search.php/?s=empty',
					  success : function(data, textStatus, XMLHttpRequest) {
					  console.log(data)
					  }
					  });*/
					$.getJSON('wp-content/themes/future/school-search.php/?s='+req.term, null, function(data, textStatus) {
						suggestions = [];
						url = [];
						$.each(data, function(key, value) {
							suggestions.push(value.title);
							url.push(value.url);
						});
						add(suggestions);
					});
				},
				select: function(event, ui) {
							$.each(suggestions, function(key, value2){
								if(ui.item.value == value2) {
									if(url[key] != '') {
										window.location = url[key];
										return false;
									}
								}
							});
						}
			});
		}
	});
})(jQuery);
