$(document).ready(function(){
	// ColorBox
	$('.colorbox a, a.colorbox').colorbox({
		current: "{current} of {total}",
		initialHeight: '150px',
		initialWidth: '150px',
		maxHeight: '95%',
		maxWidth: '95%',
		opacity: 0.25,
		speed: 250,
		transition: "elastic"
	});
	$('div.news_engineer img').parent('a').colorbox({
		current: "{current} of {total}",
		initialHeight: '150px',
		initialWidth: '150px',
		maxHeight: '90%',
		maxWidth: '950px',
		opacity: 0.25,
		speed: 250,
		transition: "elastic"
	});
	// Drop-down menus
	leave_rollover_open = 'no';
	$('div.header ul.navigation li ul').css({
		'left': '0',
		'top': '34px'
	});
	$('div.header ul.navigation li ul').hide();
	$('div.header ul.navigation li').hover(function(){
		$(this).children('ul').fadeIn(0);
		if ( $(this).find('ul').length != 0 ) {
			leave_rollover_open = 'yes';
		}
	},
	function(){
		$(this).children('ul').fadeOut(0);
		if ( $(this).find('li').length != 0 ) {
			$('div.header ul.navigation img').fadeTo(0, 1);
			leave_rollover_open = 'no';
		}
	});
	// Home page associations
	//$('div.main_area_home_page li.associations img.association_2').everyTime(1500, function() {
	//	$(this).fadeTo(1500, 0);
	//	$(this).fadeTo(1500, 0);
	//	$(this).fadeTo(1500, 1);
	//	$(this).fadeTo(1500, 1);
	//});
	// Remove focus outline on click
	$('a, input').mousedown(function(){
		this.blur();
		this.hideFocus = true;
		this.style.outline = 'none';
	});
	// Image transition rollovers
	rollover_triggered = 'no';
	$('img.rollover_transition, img.rollover_transition_slow, .rollover_transition img, .rollover_transition_slow img').parent('a').focus(function(){
		if ( $(this).hasClass('rollover_transition_slow') || $(this).parents().hasClass('rollover_transition_slow') ) {
			var fade_speed = 125;
		}
		else {
			var fade_speed = 0;
		}
		var source_image = $(this).children('img').attr('src');
		var rollover_image = source_image.replace(/\_off./gi, '_on.');
		$(this).css({
			'background': 'url("' + rollover_image + '") no-repeat',
			'display': 'block'
		});
		$(this).children('img').stop().fadeTo(fade_speed, 0);
		rollover_triggered = 'yes';
	});
	$('img.rollover_transition, img.rollover_transition_slow, .rollover_transition img, .rollover_transition_slow img').parent('a').blur(function(){
		$(this).children('img').stop().fadeTo(350, 1);
		rollover_triggered = 'no';
	});
	$('img.rollover_transition, img.rollover_transition_slow, .rollover_transition img, .rollover_transition_slow img').hover(function(){
		if ( $(this).hasClass('rollover_transition_slow') || $(this).parents().hasClass('rollover_transition_slow') ) {
			var fade_speed = 125;
		}
		else {
			var fade_speed = 0;
		}
		var source_image = $(this).attr('src');
		var rollover_image = source_image.replace(/\_off./gi, '_on.');
		$(this).parent('a').css({
			'background': 'url("' + rollover_image + '") no-repeat',
			'display': 'block'
		});
		$(this).stop().fadeTo(fade_speed, 0);
	},
	function(){
		if ( rollover_triggered != 'yes' && leave_rollover_open != 'yes' ) {
			$(this).stop().fadeTo(350, 1);
		}
	});
	// Instant rollovers
	$('.rollover_instant img, .rollover_instant input:image, img.rollover_instant, input.rollover_instant:image').parent('a').focus(function(){
		$(this).children('img').attr('src', $(this).children('img').attr('src').replace(/\_off./gi, '_on.'));
		rollover_triggered = 'yes';
	});
	$('.rollover_instant img, .rollover_instant input:image, img.rollover_instant, input.rollover_instant:image').parent('a').blur(function(){
		$(this).children('img').attr('src', $(this).children('img').attr('src').replace(/\_on./gi, '_off.'));
		rollover_triggered = 'no';
	});
	$('.rollover_instant img, .rollover_instant input:image, img.rollover_instant, input.rollover_instant:image').hover(function(){
		$(this).attr('src', $(this).attr('src').replace(/\_off./gi, '_on.'));
	},
	function(){
		if ( rollover_triggered != 'yes' ) {
			$(this).attr('src', $(this).attr('src').replace(/\_on./gi, '_off.'));
		}
	});
	// Opacity fade rollovers
	$('.rollover_fade img, .rollover_fade_slow img, img.rollover_fade, img.rollover_fade_slow').parent('a').focus(function(){
		if ( $(this).hasClass('rollover_fade_slow') || $(this).parents().hasClass('rollover_fade_slow') ) {
			var fade_speed = 125;
		}
		else {
			var fade_speed = 0;
		}
		$(this).children('img').stop().fadeTo(fade_speed, 0.85);
		rollover_triggered = 'yes';
	});
	$('.rollover_fade img, .rollover_fade_slow img, img.rollover_fade, img.rollover_fade_slow').parent('a').blur(function(){
		$(this).children('img').stop().fadeTo(350, 1);
		rollover_triggered = 'no';
	});
	$('.rollover_fade input:image, .rollover_fade_slow input:image, input.rollover_fade:image, input.rollover_fade_slow:image').focus(function(){
		if ( $(this).hasClass('rollover_fade_slow') || $(this).parents().hasClass('rollover_fade_slow') ) {
			var fade_speed = 125;
		}
		else {
			var fade_speed = 0;
		}
		$(this).stop().fadeTo(fade_speed, 0.85);
		rollover_triggered = 'yes';
	});
	$('.rollover_fade input:image, .rollover_fade_slow input:image, input.rollover_fade:image, input.rollover_fade_slow:image').blur(function(){
		$(this).stop().fadeTo(350, 1);
		rollover_triggered = 'no';
	});
	$('.rollover_fade img, .rollover_fade_slow img, .rollover_fade input:image, .rollover_fade_slow input:image, img.rollover_fade, img.rollover_fade_slow, input.rollover_fade:image, input.rollover_fade_slow:image').hover(function(){
		if ( $(this).hasClass('rollover_fade_slow') || $(this).parents().hasClass('rollover_fade_slow') ) {
			var fade_speed = 125;
		}
		else {
			var fade_speed = 0;
		}
		$(this).stop().fadeTo(fade_speed, 0.85);
	},
	function(){
		if ( rollover_triggered != 'yes' ) {
			$(this).stop().fadeTo(350, 1);
		}
	});
	$('img.rollover_transition, img.rollover_transition_slow, .rollover_transition img, .rollover_transition_slow img, .rollover_instant img, .rollover_instant input:image, img.rollover_instant, input.rollover_instant:image').each(function(){
		var source_image = $(this).attr('src');
		var rollover_image = source_image.replace(/\_off./gi, '_on.');
		$('<img>').attr('src', rollover_image);
	});
});