// JavaScript Document

jQuery.preloadImages = function(arr)
{
  for(var i = 0; i<arr.length; i++)
  {
    jQuery("<img>").attr("src", arr[i]);
  }
}
//relative to html file
var exxonSources = new Array(
"../Images/advanced_off.jpg", 
"../Images/advanced_on.jpg", 
"../Images/field_on.jpg", 
"../Images/field_off.jpg", 
"../Images/motor_off.jpg", 
"../Images/motor_on.jpg", 
"../Images/test_off.jpg", 
"../Images/test_on.jpg"
);

function removeHover($image,base){
	//$image.attr('src', off);
	$image.attr('src', base +'.jpg')
	$('.sub_text_over').hide();
	$('.sub_text').show();
}

function turnOff(className){
	$(className).each(function(){
		var img = $(this).find('img').eq(0);
		var b = $(this).attr('name');
		img.attr('src', b + '.jpg');	
	});
}

$(document).ready(function(){
	$.preloadImages(exxonSources);
	
	$('.buttons').each(function(){
		var $image = $(this).find('img').eq(0);
		var on = $(this).attr('name');
		var off = $image.attr('src');
		$(this).hover(
		function(){
			$image.attr('src', on);
		},
		function(){
			$image.attr('src', off);
		}	
	)
	});
	
	var $glb_image = null;
	var $glb_base = null;
	var timeout = null;
	$('.sub_button').each(function(){
		$link = $(this);
		var $image_self = $(this).find('img').eq(0);
		var base = $(this).attr('name');
		var id_self = $link.attr('link');
		$link.hover(
		function(){
			window.clearTimeout(timeout);
			turnOff('.sub_button');
			$glb_base = base;
			$glb_image = $image_self;
			$image_self.attr('src', base + '_on.jpg');
			$('.sub_text_over, .sub_text').hide();
			$(id_self).show();
		},
		function(){
		timeout = window.setTimeout(function(){removeHover($image_self, base);},100);
		}	
	)
	});
	
	$('.sub_text_over').hover(
		function(){
			window.clearTimeout(timeout);
		},
		function(){
			removeHover($glb_image, $glb_base);
		}
	);
	$('#engine').mouseover(
		function(){
			id = $('#engine').attr('href');
			$(id).show();
		}
	);
	$('#btm_div').mouseout(
		function(){
			$('#btm_div').hide();
		}
	);
});
