$(function(){
	$.expr[':'].external = function(obj){
		return !obj.href.match(/^mailto\:/)
		&& (obj.hostname != location.hostname);
	};
	$.expr[':'].internal = function(obj){
		return obj.hostname == location.hostname;
	};
	$('a.ajax').live('click',function(){
		var href = $(this).attr('href');
		title = $(this).text();
		$('#newsModal').load(href + ' #wrapper #content div.text',function() {
			$('#newsModalOverlay').show('fade',400);
			$(this).show('fade',600);
		});
		return false;
	});
	$('body').append('<div id="newsModalOverlay"></div><div id="newsModal"></div>');
	$('#newsModal').hide();
	$('#newsModalOverlay').hide();
	$('#newsModalOverlay').live('click',function(){
		$('#newsModal').hide('fade',500);
		$('#newsModalOverlay').hide('fade',500);
	});
	$('#newsModal').live('click',function(){
		$('#newsModal').hide('fade',500);
		$('#newsModalOverlay').hide('fade',500);
	});
	$('button.toggleComment').live('click',function(){
		$(this).next('div.hiddenComment').toggle('blind',300);
	});
	function siteEnhancement() {
		$('#multiple.accordion').accordion({
			'header':'h2',
			'active':false,
			'collapsible':true,
			'autoHeight':false,
			'clearStyle': true
		});
		$('form.wpcf7-form br').remove();
		$('a[href$=.pdf]').addClass('pdfData');
		$('p.form br').remove();
		$('.oldie #oldie .browser:not(#chrome)').fadeTo(0,.6).hover(function(){
			$(this).stop(true,true).fadeTo(400,1);
		},function(){
			$(this).stop(true,true).fadeTo(500,.6);
		});
		$('.current_page_item').removeClass('current_page_item');
	}
	siteEnhancement();
	$('.linkIt').unbind().click(function(){
		location = $(this).attr('href');
		return false;
	});
	/*function loadURL(url){
		if(url.length == 1){
			url = '';
		}
		if(location.pathname != '/'){
			location.href = 'http://'+location.host+'/#'+location.pathname;
		}
		$('#content > *').fadeTo(800,0);
		$('#content').load(url+'/?ajax=true #content > *',function(){
			siteEnhancement();
			$('#content > *').fadeTo(800,1);
		});
	}
	$.address.change(function(event){
		loadURL(event.value);
	});
	$('a:internal:not(.pdfData)').live('click',function(event){
		event.preventDefault();
		if($(this).parent().hasClass('ui-accordion-header') == false || $(this).hasClass('linkIt')){
			$.address.value(this.pathname);
		}
	});
	*/
	$('.wpcf7-response-output:empty').removeClass();
	if($('.wpcf7-response-output:not(:empty)').length){
		$('.wpcf7-response-output:not(:empty)').parent().parent().parent().prev().click();
		$('.wpcf7-response-output:not(:empty)').fadeTo(200,1).delay(3000).fadeOut(500);
	}
});
