﻿function fnMNSlideLeft(a) 
{
  //$("#projSearchResultsDiv").html($("#projSearchResultsDiv").html()+'fnMNSlideLeft\n');
  if (typeof a == 'undefined' || a==null)
    return;
  if (a==false) {
    $('#MNSliderShuttle').stop();
  }
  else if (a==true) {
    var fullSlideTime = slideDist / slideRate;
    $('#MNSliderShuttle').animate({left: '0px'},{duration: parseInt(fullSlideTime*1000), easing: slideEasing});
  }
}

function fnMNSlideRight(a) 
{
  //$("#projSearchResultsDiv").html($("#projSearchResultsDiv").html()+'fnMNSlideRight\n');
  if (typeof a == 'undefined' || a==null)
    return;
  if (a==false) {
    $('#MNSliderShuttle').stop();
  }
  else if (a==true) {
    var fullSlideTime = slideDist / slideRate;
    $('#MNSliderShuttle').animate({left: '-'+slideDist+'px'},{duration: parseInt(fullSlideTime*1000), easing: slideEasing});
  }
}

function mediaNavLoadPhoto(index) {
  //alert(".");
  $("#MediaNavVideoContent").css('display','none');
  $("#MediaNavDocContent").css('display','none');
  $("#testAspectRatioDiv").html('<img id="testAspectRatioImage" alt="' + allImgToolTip[index] + '" src="proj_photos/' + allImgSrc[index] + '"/>');
  var imgWidth = parseFloat($("#testAspectRatioImage").width());
  var imgHeight = parseFloat($("#testAspectRatioImage").height());
  var containerWidth = parseFloat($("#MediaNavContent").width());
  //var containerWidth = 488;
  var containerHeight = parseFloat($("#MediaNavContent").height());
  //var containerHeight = 331;
  $("#MediaNavPhotoContent").html('<img id="mediaNavCurrentPhoto" alt="' + allImgToolTip[index] + '" src="proj_photos/' + allImgSrc[index] + '"/>');
  $("#MediaNavPhotoContent").css('visibility', 'hidden');
  $("#MediaNavPhotoContent").css('display', 'block');
  
  
  if (imgWidth/imgHeight >= containerWidth/containerHeight) {
    //$("#mediaNavCurrentPhoto").css('width',containerWidth+"px");
    //alert(imgHeight / imgWidth);
    $("#mediaNavCurrentPhoto").height(parseInt(containerWidth * (imgHeight / imgWidth)));
    //alert(parseInt(containerWidth * (imgHeight / imgWidth)));
    $("#mediaNavCurrentPhoto").width(parseInt(containerWidth));
    //alert(parseInt(containerWidth));
  }
  else {
    //$("#mediaNavCurrentPhoto").css('height',containerHeight+"px");
    //alert(imgWidth / imgHeight);
    $("#mediaNavCurrentPhoto").width(parseInt(containerHeight*(imgWidth/imgHeight)));
    //alert(parseInt(containerHeight * (imgWidth / imgHeight)));
    $("#mediaNavCurrentPhoto").height(parseInt(containerHeight));
    //alert(parseInt(containerHeight));
  }
  //$("#MediaNavPhotoContent").css('display','block');
  $("#MediaNavPhotoContent").css('visibility', 'visible');
  $("#MediaNavText").html(allImgToolTip[index]);
}

function mediaNavLoadDoc(index)
{
  $("#MediaNavVideoContent").css('display','none');
  $("#MediaNavPhotoContent").css('display','none');
  //$("#MediaNavDocContent").html('<img alt="'+allImgToolTip[index]+'" src="proj_photos/'+allImgSrc[index]+'"/>');
  //swfobject.embedSWF("proj_docs/"+allDocSrc[index],"MediaNavDocContent","400","400","9.0.0","_scripts/expressInstall.swf",null,{wmode: "transparent", play:"true"});
  $("#MediaNavDocContent").html('Click the following link to load the PDF in a pop-up window: <a title="'+allDocToolTip[index]+'" href="javascript:popUp(\'proj_docs/'+allDocSrc[index]+'\')">'+allDocTitle[index]+'</a><br>'
    + 'Right-click this link and use the menu to save the PDF to a file: <a title="'+allDocToolTip[index]+'" href="proj_docs/'+allDocSrc[index]+'">'+allDocTitle[index]+'</a>');
  $("#MediaNavDocContent").css('display','block');
  $("#MediaNavText").html(allDocTitle[index]);
}

function popUp(url)
{
  window.open(url);
}

function mediaNavLoadVideo(index)
{
  $("#MediaNavPhotoContent").css('display','none');
  $("#MediaNavDocContent").css('display','none');
  //$("#MediaNavVideoContent").html('<img alt="'+allImgToolTip[index]+'" src="proj_photos/'+allImgSrc[index]+'"/>');
  
  //$("#MediaNavContent").html('<div id="MediaNavVideoContent"><p>Error loading video.</p></div>');
  var videoHeight = allVideoHeight[index];
  var videoWidth = allVideoWidth[index];
  videoAR = videoWidth / videoHeight;
  $("#MediaNavVideoContent").css('visibility', 'hidden');
  $("#MediaNavVideoContent").css('display', 'block');
  var containerWidth = $("#MediaNavContent").width();
  var containerHeight = $("#MediaNavContent").height();
  if (videoAR >= containerWidth/containerHeight) {
    videoWidth = containerWidth;
    videoHeight = parseInt(videoWidth / videoAR);
  }
  else {
    videoHeight = containerHeight;
    videoWidth = parseInt(videoHeight * videoAR);
  }
  swfobject.embedSWF("proj_videos/"+allVideoSrc[index],"MediaNavVideoContent",videoWidth.toString(),videoHeight.toString(),"9.0.0","_scripts/expressInstall.swf",null,{wmode: "transparent", play:"false"});

  $("#MediaNavVideoContent").css('visibility', 'visible');
  $("#MediaNavText").html(allVideoToolTip[index]);
}

var MediaNavPanel;

function initMediaNav() {
  // so we can restore our MediaNavContent html in the future if neccessary
  origMediaNavContentHtml = $("#MediaNavContent").html();
  
  // create and render the new panel from the existing markup
  MediaNavPanel = new YAHOO.widget.Panel("MediaNavPanel", {y: 15, x: 20, visible:false, zIndex:3000});
  MediaNavPanel.render();
  
  // this is a destructive but probably necessary function to properly destroy flash content upon closing the panel which would otherwise remain visible - maybe display:none would work?
  MediaNavPanel.hideEvent.subscribe(function(e) { onMediaNavClose(e); });

  //mediaNavResize();
}

function onMediaNavClose(e) {
  swfobject.removeSWF("MediaNavDocContent");
  swfobject.removeSWF("MediaNavVideoContent");
  $("#MediaNavVideoContent").css('display', 'none');
  $("#MediaNavPhotoContent").css('display', 'none');
  $("#MediaNavDocContent").css('display', 'none');
  
  $('#MNSlideLeft').unbind();
  $('#MNSlideRight').unbind();
}

/*function mediaNavResize(winwidth, winheight) {
  if (winwidth === null) {
    winwidth = $(window).width();
  }
  if (winheight === null) {
    winheight = $(window).height();
  }

  $("#MediaNavPanel").width(winwidth - 50);
  $("#MediaNavPanel").height(winheight - 30);
  $("#MediaNavBody").width(winwidth - 60);
  $("#MediaNavBody").height(winwidth - 40);
}*/


