﻿//digit reference
dojo.addOnLoad(
    function(){
        dojo.query(".headLink").forEach(function(n){
        var linkto = dojo.attr(n,"id") + "Pane";

        var widget = new dojox.widget.FisheyeLite({
            properties: {
            height:42
            },
        easeOut:dojox.fx.easing.bounceOut,
        easeIn:dojox.fx.easing.linear,
        durationOut:700,
        durationIn: 100
        },n);

    var myTarget = dojo.query(".subtext",n)[0];
    if(myTarget){

    dojo.style(myTarget,{ opacity:"0", visibility:"visible" });
    var _anim = null;
    dojo.connect(widget,"show",function(e){
    _anim && _anim.status && _anim.stop();
    _anim = dojo.fadeIn({ node: myTarget, duration:250 });
     _anim.play();
     });
    dojo.connect(widget,"hide",function(e){
    _anim && _anim.status && _anim.stop();
    _anim = dojo.fadeOut({ node: myTarget, duration:250 });
    _anim.play();
    });
    }
    });
});


//Flowplayer embed
function flowplayerEmbed(div,src)
{

    
				    //flashvars.config = '"autoPlay":false,"autoBuffering":true,"controlBarBackgroundColor":"-1","initialScale":"scale","videoFile":"../flash/video/'+src+'","controlBarGloss":"low"'
				    //flashvars.videoFile = "../flash/video/"+src
//				    flashvars.autoBuffering = "true"
//				    flashvars.width = "928";
//				    flashvars.height = "150";
//				    flashvars.backcolor = "0x000000";
//				    flashvars.lightcolor = "0xFFFFFF";
//				    flashvars.frontcolor = "0xFFFFFF";
//				    flashvars.transition = "blocks";
                    var flashvars = {
                    config: "{videoFile:'../flash/video/"+src+"', autobuffering: true, controlBarBackgroundColor:'-1', initialScale:'scale', autoPlay:false,controlBarGloss:'low'}"
                    };
				    var params = {
					    wmode:"transparent", 
					    allowfullscreen: "true"};
				    var attributes = false;
				    swfobject.embedSWF("flash/FlowPlayerDark.swf", div, "430", "290", "9", "http://www.macromedia.com/go/getflashplayer", flashvars, params, attributes);
                
//    flashembed(div, 								
//	{
//		src:'flash/FlowPlayerDark.swf',
//		wmode: 'transparent',
//		width: 430, 
//		height: 290
//	},
//	{config: {   
//		autoPlay: false,
//		autoBuffering: true,
//		controlBarBackgroundColor:'-1',
//		initialScale: 'scale',
//		videoFile: '../flash/video/'+src,
//		controlBarGloss:'low'
//	    }} 
//    );
}

function flowplayerEmbedLarge(div,src)
{
    flashembed(div, 								
	{
		src:'flash/FlowPlayerDark.swf',
		wmode: 'transparent',
		width: 615, 
		height: 415
	},
	{config: {   
		autoPlay: false,
		autoBuffering: true,
		controlBarBackgroundColor:'-1',
		initialScale: 'scale',
		videoFile: '../flash/video/'+src,
		controlBarGloss:'low'
	    }} 
    );
}

// JScript File

dojo.require("dojo.fx");

function doAnim() {
        
    dojo.animateProperty({
      node: dojo.byId("dot"),
      easing: dojox.fx.easing['quadOut'],
      duration: 1000,
      properties: {
        left: 400
      }
    }).play();
    
  }
  var currentAnimation;
  

    function hidePictures()
    {
        //then change the height.
        var Height = dojo.animateProperty(
                {
              node: String('pictures'),duration: 600,
              properties: {
                height: {end: 0}
              }
            });
        var Horizontal = dojo.animateProperty(
            {
                node: String('horizontal_container'),duration:600,
                properties:{
                height:{end:0}
                }
                });
                
        var combine = dojo.fx.combine([Height,Horizontal]);
            
            var animation = combine;
            if (animation) {
              //Play the animation. Without this call, it will not run.
              dojo.connect(animation, "onEnd", function(){
                animation = null;
              });
              animation.play();
            }
    }
    function showPictures()
    {
        var p =  dojo.byId('pictures').style.height.indexOf("p");
        var heightstring = dojo.byId('pictures').style.height.substring(0,p);
        var height = Number(heightstring);
        if(height>0)
        {
            //fade it out first
            var fadeout = dojo.fadeOut({node: dojo.byId('pictures'),duration:1000});
        
            var animation = fadeout;
            if (animation) {
              //Play the animation. Without this call, it will not run.
              dojo.connect(animation, "onEnd", function(){
                animation = null;
              });
              animation.play();
            }
            setTimeout("hidePictures();",1010);
            
            
        }
        else
        {
            var Height = dojo.animateProperty(
                    {
                  node: String('pictures'),duration: 600,
                  properties: {
                    height: {end: 75}
                  }
                });
            var Horizontal = dojo.animateProperty(
                {
                    node: String('horizontal_container'),duration:600,
                    properties:{
                    height:{end:75}
                    }
                    });
        
            var combine = dojo.fx.combine([Height,Horizontal]);
            
            var animation = combine;
            if (animation) {
              //Play the animation. Without this call, it will not run.
              dojo.connect(animation, "onEnd", function(){
                animation = null;
              });
              animation.play();
            }
            setTimeout("showPictures2();",610);
        }
    }
    
    function showPictures2()
    {
        var fadein = dojo.fadeIn({node: dojo.byId('pictures'),duration:1000});
        
        var animation = fadein;
        if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
    }
    //this function centers all 
    //of the modal popups so that they always render in the
    //middle of the screen 
    function resize()
    {
        var missionModalWidth=400;
        var width = document.documentElement.clientWidth;
        var historyModalWidth=400;
        var visionModalWidth=600;
        
        //get page size for overlay
        if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	    }
        dojo.byId('modaloverlay').style.width= document.documentElement.clientWidth;
        dojo.byId('modaloverlay').style.height= yWithScroll;
        //mission
        var leftPadding = width - missionModalWidth;
        var leftPadding = Math.ceil(leftPadding/2);
        dojo.byId('mission_modal').style.left=String(leftPadding) + 'px';
        dojo.byId('history_modal').style.left=String(leftPadding) + 'px';
        //vision modal is wider so recalculate.
        var leftPadding = width - visionModalWidth;
        var leftPadding = Math.ceil(leftPadding/2);
        dojo.byId('vision_modal').style.left=String(leftPadding) + 'px';
        
        
    }
    //this function increases the size of the image bar.
    function showPictureBar()
    {
        var Horizontal = dojo.animateProperty(
                {
                    node: String('image_bar'),duration:600,
                    properties:{
                    height:{end:40}
                    }
                    });
                    
            var animation = Horizontal;
            if (animation) {
              //Play the animation. Without this call, it will not run.
              dojo.connect(animation, "onEnd", function(){
                animation = null;
              });
              animation.play();
            }
    }
    
    var ImageToDisplay
    function shrinkImage(image)
    {
        ImageToDisplay=image
        destination = dojo.byId('image_viewer');
        var makeWidth = dojo.animateProperty(
        {
            node: destination,duration: 200,
            properties: {
             width: {end: 0}
            }
        });
        var makeHeight = dojo.animateProperty(
        {
            node: destination,duration: 200,
            properties: {
             height: {end: 0}
            }
        });
        var combine = dojo.fx.combine([makeWidth, makeHeight]);
        var animation = combine;
         if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
         setTimeout("growImage('"+image+"');",500);
        
    }
    
    function tabgrow(id)
    {
        destination = dojo.byId(id);
        var grow = dojo.animateProperty(
        {
            node: destination,duration: 200,
            properties: {
                height:{end:45}
            }
        });
        var animation = grow;
        if(animation) {
            dojo.connect(animation,"onEnd", function(){
            animation = null;
            });
            animation.play();
        }
    }
    function tabshrink(id)
    {
        destination = dojo.byId(id);
        var first = dojo.animateProperty(
        {
            node: destination,duration: 230,
            properties: {
                height:{end:3}
            }
        });
        var second = dojo.animateProperty(
        {
            node: destination,duration: 110,
            properties: {
                height:{end:8}
            }
        });
        var third = dojo.animateProperty(
        {
            node: destination,duration: 110,
            properties: {
                height:{end:3}
            }
        });
        var combine = dojo.fx.chain([first, second, third]);
        
        var animation = combine;
        if(animation) {
            dojo.connect(animation,"onEnd", function(){
            animation = null;
            });
            animation.play();
        }
    }
    
    var currentPosition=0;
    function Scroll(name,pos)
    {
        var first;
        var second;
        var third;
        
		
        if(pos>currentPosition)
        {
            first = (-1*currentPosition) + ((.75*(pos - currentPosition))*-1);
            second = (.25*(pos-currentPosition))*-1 + first;
            //third = (.10*(pos-currentPosition))*-1 + second;
        }
        else
        {
            first = (-1*currentPosition) -((.75*(pos - currentPosition)));
            second = (first-(.25*(pos-currentPosition)));
            //third = (second-(.10*(pos-currentPosition)));
        }
        currentPosition= pos;
        destination = dojo.byId('scroller');
        first = -1*pos;
        dojo.animateProperty({
            node: destination,
            easing: dojox.fx.easing['sineOut'],
            duration: 500,
            properties: {
                left: first
            }
        }).play();
		if(name=='history')
		{
			document.getElementById('video').style.display='block';
		}

    }
    function padImageViewer(imageWidth)
    {
                        
        //get page size for overlay
        if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	    }
        //mission
        var leftPadding = 928 - imageWidth;
        var leftPadding = Math.ceil(leftPadding/2);
        dojo.byId('image_viewer_div').style.paddingLeft=String(leftPadding) + 'px';
                        
        
    }
    function growImage()
    {
        //padd the image appropriately
        padImageViewer(7*ImageToDisplay.width);
        destination = dojo.byId('image_viewer');
        //set the new image as the source
        destination.src=ImageToDisplay.src;
        //var heightgetImageSize(image);
        destination.width=0;
        var makeWidth = dojo.animateProperty(
        {
            node: destination,duration: 500,
            properties: {
             width: {end: 7*ImageToDisplay.width}
            }
        });
        var makeHeight = dojo.animateProperty(
        {
            node: destination,duration: 500,
            properties: {
             height: {end: 7*ImageToDisplay.height}
            }
        });
//        destination.height=7*image.height;
//        destination.width=7*image.width;
        var combine = dojo.fx.combine([makeWidth, makeHeight]);
        var animation = combine;
         if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
        
    }
 
    function showModal(divName)
  {
//        var p =  this.innerWidth.indexOf("p");
//        var windowWidthString = this.innerWidth.substring(0,p);
        resize();
        
        dojo.byId('modaloverlay').style.zIndex=2;
        dojo.byId(divName).style.zIndex=3;
        var fadein = dojo.fadeIn({node: String(divName),duration:1000});
        var wipein =  dojo.fx.wipeIn({node: String(divName),duration:1000});
        
        var combine = dojo.fx.combine([fadein,wipein]);
        //var combine = wipein;
        
        var modalBackground = dojo.animateProperty({
              node: dojo.byId('modaloverlay'),duration: 300,
              properties: {
                opacity: {end: 0.7}
              }
            });
        animation = modalBackground;
        //var animation = dojo.fx.chain([modalBackground,combine]);    
        if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
        setTimeout("showModal2('"+divName+"');",300);
  }
  
  function showModal2(divName)
  {
        var fadein = dojo.fadeIn({node: String(divName),duration:1000});
        //var wipein =  dojo.fx.wipeIn({node: String(divName),duration:1000});
        
        //var combine = dojo.fx.combine([fadein,wipein]);
        var animation = fadein;
        if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
  }
  
  function hideModal(divName)
  {
        
        var fadein = dojo.fadeOut({node: dojo.byId(divName), duration: 600});
        //var wipein =  dojo.fx.wipeOut({node: dojo.byId(divName),duration: 600});
        
        //var combine = dojo.fx.combine([fadein,wipein]);
        
        var animation = fadein;
        if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
        setTimeout("hideModal2('"+divName+"');",650);
        
  }
  
  function hideModal2(divName)
  {
    var modalBackground = dojo.animateProperty({
              node: dojo.byId('modaloverlay'),duration: 300,
              properties: {
                opacity: {end: 0.0}
              }
            });
        var animation = modalBackground 
        if (animation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(animation, "onEnd", function(){
            animation = null;
          });
          animation.play();
        }
        setTimeout("changeZOrder('"+divName+"');",350);
        
  }

  function changeZOrder(divName)
  {
    dojo.byId('modaloverlay').style.zIndex=-1;
    dojo.byId(divName).style.zIndex=-1;
  }
  function hideMenu(menuName)
  {
        var p =  dojo.byId(menuName).style.height.indexOf("p");
        var heightstring = dojo.byId(menuName).style.height.substring(0,p);
        var height = Math.ceil(Number(heightstring))-2;
        var finishHeight = 2;
        var middleHeight = height - (.82 * height);
        var halfmiddleHeight = middleHeight/2;
        currentAnimation=dojo.fx.chain([ 
            dojo.animateProperty(
                {
              node: dojo.byId(menuName),duration: 200,
              properties: {
                height: {end: finishHeight}
              }
            }),
            dojo.animateProperty(
                {
              node: dojo.byId(menuName),duration: 75,
              properties: {
                height: {end: middleHeight}
              }
            }),
            dojo.animateProperty(
                {
              node: dojo.byId(menuName),duration: 75,
              properties: {
                height: {end: finishHeight}
              }
            }),
            dojo.animateProperty(
                {
              node: dojo.byId(menuName),duration: 35,
              properties: {
                height: {end: halfmiddleHeight}
              }
            }),
            dojo.animateProperty(
                {
              node: dojo.byId(menuName),duration: 35,
              properties: {
                height: {end: finishHeight}
              }
            })
            ]);
            
        
        if (currentAnimation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(currentAnimation, "onEnd", function(){
            currentAnimation = null;
          });
          currentAnimation.play();
        }
        //dojo.fx.chain([slideRight, slideLeft, slideRight, slideLeft]);        
    }
  function displayMenu(menuName)
  {   
        currentAnimation= dojo.animateProperty(
        {
          node: dojo.byId(menuName),duration: 80,
          properties: {
            height: {end: 45}
          }
        });
        
        if (currentAnimation) {
          //Play the animation. Without this call, it will not run.
          dojo.connect(currentAnimation, "onEnd", function(){
            currentAnimation = null;
          });
          currentAnimation.play();
        }
    }
  function right()
  {
    currentAnimation= dojo.animateProperty(
    {
      node: dojo.byId('animDiv'),duration: 300,
      properties: {
        width: {end: 600}
      }
    });
    
    if (currentAnimation) {
      //Play the animation. Without this call, it will not run.
      dojo.connect(currentAnimation, "onEnd", function(){
        currentAnimation = null;
      });
      currentAnimation.play();
    }
  }
  function left()
  {
    currentAnimation= dojo.animateProperty(
    {
      node: dojo.byId('animDiv'),duration: 300,
      properties: {
        width: {end: 300}
      }
    });
  
    if (currentAnimation) {
      //Play the animation. Without this call, it will not run.
      dojo.connect(currentAnimation, "onEnd", function(){
        currentAnimation = null;
      });
      currentAnimation.play();
    }
  }
  function pauseAnimation(){
    if(currentAnimation && currentAnimation.status() == "playing"){
      currentAnimation.pause();
    }
  }
  function resumeAnimation(){
    if(currentAnimation && currentAnimation.status() == "paused"){
      currentAnimation.play();
    }
  }