$(document).ready(function() 
{
  //Enter the content in to contact form
  $.post("/presentation.htm", {}, function(content)
  {
    $('#presentation').html(content);
    
    //Resize the layer if visible and the user resizes the window
    $(window).bind("resize", function()
    { 
      if($('#layer').is(':visible'))
      {
       $("#layer").height($(document).height());
       $("#layer").width($(document).width());
      }
    });
        
    //Make the contact box draggable
    $('#presentation').draggable( 
    { 
      zIndex:    20,  
      opacity: 0.7, 
      handle: '#presentationhandle', 
      cursor: 'move'
    });
     
        
    //Contact box to dissapear  on click
    $('#presentationclose').click(function(e) 
    { 
        e.preventDefault();
        $("#presentation").fadeOut(700);
        $('#layer').hide();
        $("#layer").height(1);
        $("#layer").width(1); 
    }); 
     
    //Contact box to appear on click
    $('.presentationrequest').click(function(e) 
    {   
        e.preventDefault();
        scrollToTopPlease();
        displayContact();
    }); 
      
    function displayContact()
    {
        if(!$('#presentation').is(':visible'))
        {
          $('#presentationerror').html("");
          $('#layer').show();
          $("#presentation").fadeIn(700);
          $("#layer").height($(document).height());
          $("#layer").width($(document).width());
        }
    }
      
    //Submit the form
    $('#presentationsubmit').click(function(e)
    {
      e.preventDefault();

      
      //Validate
      var presentationname=$('#presentationname').val();
      var presentationcompname=$('#presentationcompname').val();
      var presentationemail=$('#presentationemail').val();
      if ($('#presentationtick').attr('checked'))
      { var presentationtick="TRUE"; }
      else
      { var presentationtick="FALSE"; }
        
      var error="";
      if(presentationname.length<5) { error+="Enter name<br />"; }
      if(presentationcompname.length<2) { error+="Enter company name<br />"; }
      if(presentationemail.length<2) { error+="Enter email address<br />"; }
        else if(!IsEmail(presentationemail)) { error+="Enter valid email address<br />"; }
      //Display error
      if(error!="")
      {
        $('#presentationerror').html("<strong>Please complete the following:</strong><br />"+error);
      }
      
      else
      {              
        //or post via AJAX and get thank you message
        $.post("/ajax/ajaxpresentation.php", {presentationname: presentationname, presentationcompname: presentationcompname, presentationemail: presentationemail, presentationtick: presentationtick}, function(content)
        {
          $('#presentationcontent').html(content);
        });
      }
    });
  });
});

function setOpacity()
{
  var layer=document.getElementById("layer");
  layer.style.opacity="0.5";
  layer.style.filter="alpha(opacity=50)";
}
   

function scrollToTopPlease()
{
 scroll(0,0);
}