/* checkPosition()
 * VERTICALLY & HORIZONTALLY CENTERS AN ELEMENT WITH ID = "page-container"
 * CALL THIS FUNCTION IN $(document).ready()
 * INCLUDE THE FOLLOWING SCRIPT IN DOCUMENT HEADER TO ACCOMMODATE BROWSER RESIZING
 *  $(window).resize(function(){checkPosition();});
-------------------------------------------------*/
function checkPosition()
  {
  
      
    //alert("checking position");
    var containerHeight = $("#page-container").height();
    //alert("container height: " + containerHeight);
    var winHeight = $(window).height();
    //alert("window height: " + winHeight);
    $("#page-container").css
      (
        {
          top:"50%",
          marginTop:-containerHeight/2          
        }
      );
    if (winHeight < containerHeight || $("#page-container").css("position") != "absolute")
      {
        $("#page-container").css
          (
            {
              top:0,
              marginTop:0          
            }
          );
      }
    
    var containerWidth = $("#page-container").width();
    //alert("container width: " + containerWidth);
    var winWidth = $(window).width();
    //alert("window width: " + winWidth);
    $("#page-container").css
      (
        {
          left:"50%",
          marginLeft:-containerWidth/2          
        }
      );
    if (winWidth < containerWidth || $("#page-container").css("position") != "absolute")
      {
        $("#page-container").css
          (
            {
              left:0,
              marginLeft:0          
            }
          );
      }
     //alert("finished checking position");
     

  }




/* initFades()
 * MAKES NAVIGATION LINKS FADE OUT THE 'page-container' ELEMENT
 *  WHEN TRANSITIONING BETWEEN PAGES
 * CALL THIS FUNCTION IN $(document).ready()
-------------------------------------------------*/
function initFades()
  {
    //alert("starting fade");
    $("#page-container").fadeIn(500);
    $("#navigation a").click
      (
        function()
          {
            var url = $(this).attr("href");
            //alert(url);
            $("#page-container").fadeOut
              (
                300,
                function(){window.location.href = url;}
              );
            return false; 
          }
      );
    //alert("fade finished");
    
  }

  
  
/* dropCaps()
 * REPLACES TEXT DROP CAPS WITH IMAGES
 * CALL THIS FUNCTION IN $(document).ready()
-------------------------------------------------*/
function dropCaps()
  {
  
    //alert("replacing dropcaps");
    if ($("body").attr("id") != "contact")
      {
        $("h2 + p, #content > p:first-child").each
          (
            function()
              {
                var dropcap = $(this).text().slice(0,1);
                var text = $(this).html().slice(1);
                var dropcapLetter = dropcap.toLowerCase();
                var dropcapWrap = "<span class='dropcap'><img src='_images/drop_" + dropcapLetter + ".png' alt='" + dropcap + "' /></span>";
                $(this).html(dropcapWrap + text);
              }
          );
      }
    //alert("dropcaps finished");
  }
  
function initAnchors()
  {  
  
    $(".toc-menu").change(
        function()
          {
            var anchorLink = this.options[this.selectedIndex].value; 
            //alert(anchorLink);
            $("#content").jScrollPane({animateTo:true});
            $("#content")[0].scrollTo("" + anchorLink + "");
          }
      );
      
      
    $("a[href*='#']").click
      (
        function()
          {
            var anchorURL = $(this).attr("href");
            
            if(anchorURL.split("#")[0]) var filepath = anchorURL.split("#")[0]; else var filepath = "";
           //alert(filepath);
            
            $(this).attr("href", filepath + "?" + anchorURL.split("#")[1]);
            
            //IF LINK GOES TO DIFFERENT PAGE
            if(anchorURL.split("#")[0] != "")
              {
                window.location.href = anchorURL.split("#")[0] + "?" + anchorURL.split("#")[1];
              }
           
            //IF LINK GOES TO SAME PAGE
            $("#content").jScrollPane({animateTo:true});
            $("#content")[0].scrollTo("" + anchorURL + "");  
            
            $(this).attr("href", anchorURL);
            return false;
            
          }
      );
      
    if($("body").attr("id") != "contact" && $("body").attr("id") != "home" && $("body").attr("id") != "index")
      {
    //alert("checking for anchor links");
        // CHECK FOR ANY ANCHOR LINKS WHEN A NEW PAGE IS LOADED
        var anchorURL = window.location.href;
        var anchorName = "#" + anchorURL.split("?")[1];
        //alert(anchorName);
        $("#content").jScrollPane({animateTo:true});
        $("#content")[0].scrollTo("" + anchorName + "");  
    //alert("finished checking for anchor links");
      }
  }
  

/*
function initPrint()
  {
    $("#print").click
      (
        function()
          {
            $("#content-wrapper").html($("#content").html());
            $("#content").remove();
            return false;
          }  
      );
  }
*/
