/******************************************************************************/
/*
    \file       isreallyamazing.js
    \brief      This is the javascript functionality for isreallyamazing.com.
    \version    1.0
*/
/******************************************************************************/

/********** globals ***********************************************************/
var Browser =
{
  detect: function()
  {
    var UA = navigator.userAgent;
    this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
    this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
    this.isOpera = /Opera/.test(UA);
    this.isMSIE  = (/MSIE/.test(UA) && !this.isOpera);
    this.isMSIE7 = this.isMSIE && !(/MSIE 6\./.test(UA) && !this.isOpera);
  }
}
var CertificateX = 0;

/********** implementation ****************************************************/
Browser.detect();

/**************************************************************************/
/*
    \function   MainSitePostLoad
    \brief      This function performs the post load processing for the main site.
    \param      None.
    \return     None.
*/
/**************************************************************************/
function MainSitePostLoad()
{
    // Set style on header
    $('header').setStyle({top:'170px',left:'-700px'});
    
    // Set style on logo
    $('logo').setStyle({display:'block'});
    
    // Transition in the header
    new Effect.Move('header',{ x: 700, y: -170 });
    
    // Create bubbles
    CreateBubble('people', 50,  150, { delay:0.2, duration:1.1 });
    CreateBubble('places', 320, 180, { delay:0.5, duration:1.1 });
    CreateBubble('things', 590, 210, { delay:0.8, duration:1.1 });
    
    // Make the bubbles draggable
    ['people-bubble','places-bubble','things-bubble'].each(
        function(b)
        {
            new Draggable(b,{revert:true,handle:b+'-handle'});
        });
}

/**************************************************************************/
/*
    \function   MainSiteComingSoonPostLoad
    \brief      This function performs the post load processing for the main site.
    \param      None.
    \return     None.
*/
/**************************************************************************/
function MainSiteComingSoonPostLoad()
{
    // Set style on header
    $('header').setStyle({top:'170px',left:'-700px'});
    
    // Set style on logo
    $('logo').setStyle({display:'block'});
    
    // Transition in the header
    new Effect.Move('header',{ x: 700, y: -170 });
    
    // Create bubbles
    CreateBubble('comingsoon', 320, 180, { delay:0.5, duration:1.1 });
    
    // Make the bubbles draggable
    ['comingsoon-bubble'].each(
        function(b)
        {
            new Draggable(b,{revert:true,handle:b+'-handle'});
        });
}

/**************************************************************************/
/*
    \function   CertificateSitePostLoad
    \brief      This function performs the post load processing for the certificate site.
    \param      isAvailable - If the site is available or not, will make the buy now button visible if so.
    \return     None.
*/
/**************************************************************************/
function CertificateSitePostLoad(isAvailable)
{
  CertificateX = GetScreenCenterX()-(349/2);

  // Create bubble
  CreateBubble('certificate', CertificateX, 110, { delay:0.2, duration:1.1 });
  
  // Make the bubbles draggable
  ['certificate-bubble'].each(
      function(b)
      {
          new Draggable(b,{revert:true,handle:b+'-handle'});
      });
  
  // Make footer appear
  new Effect.Appear('certificate-footer');
}

/**************************************************************************/
/*
    \function   OnCertificateSiteResize
    \brief      This function recenters the certificate if the browser is resized.
    \param      None.
    \return     None.
*/
/**************************************************************************/
function OnCertificateSiteResize()
{
    var newX = GetScreenCenterX()-(349/2);
    var oldX = CertificateX;
    var difference = newX - oldX;
    
    // Move the certificate to the new location
    new Effect.MoveBy('certificate-bubble', 0, difference);
    
    // Update global
    CertificateX = newX;
}

/**************************************************************************/
/*
    \function   CreateBubble
    \brief      This function creates a bubble effect for a div.
    \param      id - The div id to apply the effect to.
    \param      x - The x-offset in pixels.
    \param      y - The y-offset in pixels.
    \return     None.
*/
/**************************************************************************/
function CreateBubble(id,x,y)
{
    // Set the style
    $(id+'-bubble').setStyle({left:x+'px',top:y+'px'});
    
    // Create a new effect for the div
    new Effect.Scale(id+'-bubble',100,
                    Object.extend(
                    {
                        beforeStart:function(effect)
                        {
                            $(effect.element).style.display = 'block';
                            $(effect.element).setOpacity(0);
                            $$('#'+id+'-bubble p').each(function(p)
                                                        {
                                                            p.hide()
                                                        });
                        },
                        afterUpdate:function(effect)
                        {
                            $(effect.element).setOpacity(effect.position);
                        },
                        scaleFrom:0,
                        scaleFromCenter:true,
                        afterFinish:function(effect)
                        {
                            $$('#'+id+'-bubble p').each(function(p)
                                                        {
                                                            new Effect.Appear(p,{duration:0.4});
                                                        });
                        }
                    },
                    arguments[3] || {}));        
}

/**************************************************************************/
/*
    \function   GetScreenCenterY
    \brief      This function calculates the y coordinate for the screen center.
    \param      None.
    \return     y coordinate of screen center.
*/
/**************************************************************************/
function GetScreenCenterY()
{
  return( GetScrollOffset() + (GetInnerHeight() / 2) );
}

/**************************************************************************/
/*
    \function   GetScreenCenterX
    \brief      This function calculates the x coordinate for the screen center.
    \param      None.
    \return     x coordinate of screen center.
*/
/**************************************************************************/
function GetScreenCenterX()
{
  return( document.body.clientWidth / 2 );  
}

/**************************************************************************/
/*
    \function   GetInnerHeight
    \brief      This function calculates the inner height of the page space.
    \param      None.
    \return     inner height.
*/
/**************************************************************************/
function GetInnerHeight()
{
  var y = 0;  
  if (self.innerHeight) // all except Explorer  
  {
    y = self.innerHeight;  
  }
  else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
  {
    y = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    y = document.body.clientHeight;
  }

  return(y);
}

/**************************************************************************/
/*
    \function   GetScrollOffset
    \brief      This function calculates the scroll offset of the page space.
    \param      None.
    \return     scroll offset.
*/
/**************************************************************************/
function GetScrollOffset()
{
  var y = 0;
  
  if (self.pageYOffset) // all except Explorer
  {
    y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict  
  {
    y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    y = document.body.scrollTop;
  }
  
  return(y);
}

/**************************************************************************/
/*
    \function   CheckNameAvailability
    \brief      This function checks to see if the name is available.
    \param      None.
    \return     scroll offset.
*/
/**************************************************************************/
function CheckNameAvailability()
{
}