$.swapImage(".swapImage");
$.swapImage(".swapImageClick", true, true, "click");

$(document).ready(function(){

/* activeButton is used to track what motion or print movie is playing. It's tested against the mouseover event to make sure
the thumbnail of the active movie playing doesn't fire on top of it. Thie variable was stored in an object so that the data could be
accessed by other objects */

clickFlag = 0;
$.activeButton = "";
$.activeInfo = "";
$.mouseFlag = 0;
$("#thumbnail").hide();
	
	// click toggle
    
    $("#printbutton").click(function () {
   	  if ($("#print").is(":hidden")) {
		$("#motion").slideUp("normal");
        $("#print").slideDown("normal");
		$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion.gif"});
		$("#printbutton").attr({ src: "images/buttons/btn_nav_print_over.gif"});
      } 
  });
	
	$("#motionbutton").click(function () {
   	  if ($("#motion").is(":hidden")) {
		$("#print").slideUp("normal");
        $("#motion").slideDown("normal");
		$("#printbutton").attr({ src: "images/buttons/btn_nav_print.gif"});
		$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion_over.gif"});
      } 
  });
   
   // rollover toggle for print + motion menus
	
	$("#printbutton").hover(function () {
		$("#printbutton").attr({ src: "images/buttons/btn_nav_print_over.gif"});
     }, function () { 
	    if ($("#print").is(":hidden")) {
	      $("#printbutton").attr({ src: "images/buttons/btn_nav_print.gif"});
		}
	 });
	
	
	$("#motionbutton").hover(function () {
		$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion_over.gif"});
     }, function () { 
        if ($("#motion").is(":hidden")) {
          $("#motionbutton").attr({ src: "images/buttons/btn_nav_motion.gif"});
		}
     } );
	
	
	// thumbnail rollovers
	
	  $("#motion li img, #print li img").mouseenter(function () {
		// show the thumbnail div if it was hidden by the click of the button
			if ($(this).attr("content1") != $.activeButton || $.activeButton == "") {
			clearTimeout($.rollOverTimer);
			$("#thumbnail").show();
			// fade in info
			var myinfo = $(this).attr("info");
		    var myInfoCode = "<img src=\"" + myinfo + "\" />";
			$("#info ul li").html(myInfoCode);
			$("#info").show();
			$.mouseFlag=0;
		} else {
			// this is the active content, so kill the timer and hide the thumbnail
			clearTimeout($.rollOverTimer);
			$("#thumbnail").hide();
			$("#info ul li").html($.activeInfo);
			//$("#info").show();
		}
		
		// hide the flash div if it was visible
		/*if ($("#content").is(":visible") && $(this).attr("content1") != $.activeButton) {
			$("#info").hide();
		}*/
		
		// set the src of the thumbnail to the attribute value of the img
		var thumbnail = $(this).attr("thumbnail");	
		$("#thumbnail img").attr({src: thumbnail});
		
      });
	  
	  // rollout to trigger replay of content (if it was activated)
	   $("#motion li img, #print li img").mouseleave(function () {
		// show the thumbnail div if it was hidden by the click of the button
		$.mouseFlag = 1;
		$.rollOverTimer = setTimeout(finishMouseLeave, 600); 
		
		function finishMouseLeave () {
			if ($.mouseFlag) {
				if ($("#thumbnail").is(":visible")) {
					$("#thumbnail").hide();
				}
				
				// show content layer if the clickFlag (which is used to track initait user interaction)
				if (clickFlag) {
					$("#info ul li").html($.activeInfo);
					$("#info").show();
				} else {
					$("#info").hide();	
				}
			}
		}
      });
	  
	  
	// load the swf files for motion and print menu
	   $("#motion li img, #print li img").click(function () {
														  
		// hide the thumbnail div if it was hidden by the click of the button
		if ($("#thumbnail").is(":visible")) {
			clearTimeout($.rollOverTimer);
			$("#thumbnail").hide();
		}
		
		/* 
		content 1 is the main FLV movie
		content 2 is the inner detail movie, that get's loaded
		   
		The player.swf movie looks for both variables and if content 2 is not NULL, the see detail button shows which plays content 2
		 
		 */
		
		var content1 = $(this).attr("content1");
		var content2 = $(this).attr("content2");
		var thumbnail = $(this).attr("thumbnail");
		var info = $(this).attr("info");
		var infoCode = "<img src=\"" + info + "\" />";
		$.activeButton = $(this).attr("content1");
		$.activeInfo = infoCode;
		clickFlag = 1;
		
		// created this variable to see if the button was of motion or print, so appropriate .swf would be loaded.
		// motion_player.swf for motion  |  print_player.swf for print
		var motionOrPrint = $(this).parents('ul:eq(0)').attr("id");	
		
		if (motionOrPrint == "motion") {
			// embed is different for motion because it's 383 tall
		var embedCode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"720\" height=\"383\"><param name=\"movie\" value=\"images/content/" + motionOrPrint  + "_player.swf?content1=" + content1 + "&content2=" + content2 + "&thumbnail=" + thumbnail + "\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\"images/content/"  + motionOrPrint + "_player.swf?content1=" + content1 + "&content2=" + content2 + "&thumbnail=" + thumbnail + "\" quality=\"high\" wmode=\"transparent\" width=\"720\" height=\"383\" type=\"application/x-shockwave-flash\" /></object>";
		} else {
		var embedCode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"720\" height=\"360\"><param name=\"movie\" value=\"images/content/" + motionOrPrint  + "_player.swf?content1=" + content1 + "&content2=" + content2 + "&thumbnail=" + thumbnail + "\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\"images/content/"  + motionOrPrint + "_player.swf?content1=" + content1 + "&content2=" + content2 + "&thumbnail=" + thumbnail + "\" quality=\"high\" wmode=\"transparent\" width=\"720\" height=\"360\" type=\"application/x-shockwave-flash\" /></object>";
		}
		
		// keeps from loading the same movie twice
		if (!myFlag) {
			$("#content").html(embedCode);
			$("#content").show();
			$("#info ul li").html(infoCode);
			var myFlag = 1;
		}
		$("#info").fadeIn("normal");
      });
	   
	    // Global Navigation Content
	   
	   $("#globalnav img").click(function () {
			// null must be passed via content attribute to override the jQuery display of content within the content div
			// this is good for external links - like the archive
			
			var contentCheck = $(this).attr("type");
			var content = $(this).attr("content");
			
			// this retracts the print / motion menu
			if ($("#print").is(":visbile")) {
        		$("#print").slideUp("normal");
				$("#printbutton").attr({ src: "images/buttons/btn_nav_print.gif"});
			}
			
			if ($("#motion").is(":visible")) {
				$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion.gif"});
				$("#motion").slideUp("normal");
			}
			
			if (contentCheck != "null") {
				
				if (contentCheck == "img") {
				//change the content div to the content attribute of this image
					var embedCode = "<img src=images/content/" + content + " />";
				} else {
					var embedCode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"720\" height=\"360\"><param name=\"movie\" value=\"images/content/" + content + "\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\"images/content/"  + content + "\" quality=\"high\" wmode=\"transparent\" width=\"720\" height=\"360\" type=\"application/x-shockwave-flash\" /></object>";
				}
				
				$("#content").html(embedCode);
				$.activeButton = $(this).attr("content");
				// reset clickflag var which is used in the print & motion buttons, and hide the info panel
				clickFlag = 0;
				$("#info").hide();
				
			}
      });
	   
	   // Feature Navigation Content
	   
	   $("#featurenav img").click(function () {
											
			// this retracts the print / motion menu
			if ($("#print").is(":visbile")) {
        		$("#print").slideUp("normal");
				$("#printbutton").attr({ src: "images/buttons/btn_nav_print.gif"});
			}
			
			if ($("#motion").is(":visible")) {
				$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion.gif"});
				$("#motion").slideUp("normal");
			}
		
			var content1 = $(this).attr("content1");
			var content2 = $(this).attr("content2");
		
			//change the content div to the content attribute of this image
			var embedCode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"720\" height=\"383\"><param name=\"movie\" value=\"images/content/motion_player.swf?content1=" + content1 + "&content2=" + content2 + "\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\"images/content/motion_player.swf?content1=" + content1 + "&content2=" + content2 + "\" quality=\"high\" wmode=\"transparent\" width=\"720\" height=\"383\" type=\"application/x-shockwave-flash\" /></object>";
			$("#content").html(embedCode);
			$.activeButton = $(this).attr("content");
			// reset clickflag var which is used in the print & motion buttons, and hide the info panel
			clickFlag = 0;
			$("#info").hide();
      });  
	   
	   
	   // Homepage movie hack, this function is for when user clicks on the homepage hero for animation.w
	   
	   $("#content img").click(function () {
											
			var content1 = $(this).attr("content1");
			var content2 = $(this).attr("content2");
			var info = $(this).attr("info");
			var infoCode = "<img src=\"" + info + "\" />";
			$.activeButton = $(this).attr("content1");
			$.activeInfo = infoCode;
			clickFlag = 1;
			$("#info ul li").html(infoCode);
			$("#info").show();
		
			//change the content div to the content attribute of this image
			var embedCode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"720\" height=\"383\"><param name=\"movie\" value=\"images/content/motion_player.swf?content1=" + content1 + "&content2=" + content2 + "\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\"images/content/motion_player.swf?content1=" + content1 + "&content2=" + content2 + "\" quality=\"high\" wmode=\"transparent\" width=\"720\" height=\"383\" type=\"application/x-shockwave-flash\" /></object>";
			
			$("#content").html(embedCode);
			$("#motion").slideDown("normal");
			$("#motionbutton").attr({ src: "images/buttons/btn_nav_motion_over.gif"});
			
      }); 
      
});