//preload images
if (document.images) {
    	img1 = new Image();
    	img1.src = "http://www.ballardrobotics.org/preloaded_images/header(eye).gif";
    	img2 = new Image();
    	img2.src = "http://www.ballardrobotics.org/preloaded_images/closebutton.gif";
    	img3 = new Image();
    	img3.src = "http://www.ballardrobotics.org/preloaded_images/background.png";
}

//logo eyes on mouseover
$(document).ready(function(){
  $("#header_logo").mouseover(function(){
    $("#header_image").css("background-image","url('http://www.ballardrobotics.org/preloaded_images/header(eye).png')");
  });
   $("#header_logo").mouseout(function(){
    $("#header_image").css("background-image","url('http://www.ballardrobotics.org/header.png')");
  });
  $("#header_logo").click(function(){
    window.open("http://www.ballardrobotics.org","_self");
  });
});

//image expand on click
$(document).ready(function(){
	$(".gallery").addClass("minimized");
	$(".minimized").click(function(){
		var original_height = $(this).css("height");
		var original_width = $(this).css("width");
		var new_height = original_height.replace("px","") / original_width.replace("px","") * 440 + "px";
		var new_width = "440px";
		var move_up = "-" + (new_height.replace("px","") - original_height.replace("px","")) / 2 + "px";
		var move_left = "-" + (new_height.replace("px","") - original_height.replace("px","")) / 2 + "px";
		var original_marginLeft = $(this).css("margin-left");
		var original_marginTop = $(this).css("margin-top");
		if ($(this).css("width") < '440px') {
			$("div.main").after('<div class="darkenBackground"></div>');
			$(this).addClass("expanded");
			$(this).css("z-index","12");
			$("div.gallery").css("position","static");
			$(this).animate({height:new_height, width:new_width, marginLeft:move_left, marginTop:move_up },400,function(){
				$(this).after('<img class="close" src="http://www.ballardrobotics.org/preloaded_images/closebutton.gif" alt="close" />');
				$("img.close,div.darkenBackground").click(function(){
					$(".close").hide();
					$(".expanded").animate({height:original_height, width:original_width, marginLeft:original_marginLeft, marginTop:original_marginTop  },100,function(){
						$(this).removeClass("expanded");
						$(this).css("z-index","0");
						$("div.gallery").css("position","relative");
						$("div.darkenBackground").hide();
						});
				});
			});
		}
	});	
});

//google analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27607237-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
