$(document).ready(function() {

   $('#notificationbg').click(function() {
     closenotification();
   });

   $('#logonForm').ajaxForm(
    {
      target:'#notification',
      success: function()
       {
         window.location.reload();
       }
    });
 });


function tog(id)
 {
   $(".statement" + id).toggle();
 }

function centrenotification(wi,he)
 {
   var winH = $(window).height();
   var winW = $(window).width();
   var centerDiv = $('#notification');
   centerDiv.css('width', wi);
   centerDiv.css('height', he); 
   centerDiv.css('top', (winH/2) - (he/2));
   centerDiv.css('left', (winW/2) - (wi/2)); 
   $("#notificationbg").css({"opacity": "1"});  
 }

function closenotification()
 {
  $("#notificationbg").fadeOut();
  $("#notification").fadeOut();
 }

function closecontact()
 {
  window.location = "http://www.sandysykes.co.uk/"
 }

function vwImage(wi,he,path)
 {
   $("#notification").load('library/ajax.php?t=vwImage&path=' + escape(path),'',function()
    {
      centrenotification(wi,he);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });
 }

function remText(id,v)
 {
   var newVal;

      newVal = $("#" + id).val();
      switch(newVal)
       {
         case '':
         $("#" + id).val(v);
         $("#" + id).css("color","#999999");
         $("#" + id).css("fontStyle","italic");
         break;
         case v:
         $("#" + id).val('');
         $("#" + id).css("color","#333333");
         $("#" + id).css("fontStyle","normal");
         break;
       }
 }
 
 function sendEmail()
 {
   var forename;
   var surname;
   var email;
   var mobile;
   var tel_home;
   var tel_work;
   var message;
   
   forename = escape($("#forename").val());
   surname = escape($("#surname").val());
   email = escape($("#email").val());
   mobile = escape($("#mobile").val());
   tel_home = escape($("#tel_home").val());
   tel_work = escape($("#tel_work").val());
   message = escape($("#message").val());
   
   $("#notification").load('library/ajax.php?t=email&forename=' + forename + '&surname=' + surname + '&email=' + email + '&mobile=' + mobile + '&tel_home=' + tel_home + '&tel_work=' + tel_work + '&message=' + message,'',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });

 }

function createPost()
 {
   $("#notification").load('library/blog.php?t=createPost','',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });
 }

function insertPost()
 {
   var title;
   var dt;
   var post;
   
   title = escape($("#title").val());
   dt = escape($("#datetime").val());
   post = escape($("#postcontent").val());

   $("#notification").load('library/blog.php?t=insertPost&title=' + title + '&dt=' + dt + '&post=' + post,'',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();
       $("#leftpane").load('library/blog.php?t=selectPost');
    });
 }

function editPost(id)
 {
   $("#notification").load('library/blog.php?t=editPost&id=' + id,'',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();
    });
 }

function deletePost(id)
 {
   $("#notification").load('library/blog.php?t=deletePost&id=' + id,'',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
       $("#leftpane").load('library/blog.php?t=selectPost');
    });
 }

function updatePost()
 {
   var title;
   var post;
   var id;
   var dt;

   title = escape($("#title").val());
   dt = escape($("#datetime").val());
   id = escape($("#postID").val());
   post = escape($("#postcontent").val());

   $("#notification").load('library/blog.php?t=updatePost&title=' + title + '&dt=' + dt + '&postID=' + id + '&post=' + post,'',function()
    {
       centrenotification(460,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();
       $("#leftpane").load('library/blog.php?t=selectPost');
    });
 }

function editAbout()
 {
   $("#notification").load('library/adminAbout.php?t=edit','',function()
    {
      $('#body').wysiwyg(
       {
        rmUnusedControls: true,
        controls:
         {
           bold : { visible : true },
           insertOrderedList : { visible : true },
           insertUnorderedList : { visible : true },
           /*h1 : { visible : true },*/
           h2 : { visible : true },
           //h3 : { visible : true },
           //h4 : { visible : true },
           //h5 : { visible : true },
           paragraph : { visible : true },
           italic  : { visible : true },
           //removeFormat : { visible : true },
           createLink : { visible : true },
           insertTable : { visible : true },

           html : { visible : true }
         }
         ,css: 'library/wysiwyg_content.css'
       });

      $('#form').ajaxForm(
       {
         success: function()
          {
            window.location.reload();
          }
       });

       centrenotification(650,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });
 }

function editCV()
 {
   $("#notification").load('library/adminCV.php?t=edit','',function()
    {

      $('#body').wysiwyg(
       {
        rmUnusedControls: true,
        controls:
         {
           bold : { visible : true },
           insertOrderedList : { visible : true },
           insertUnorderedList : { visible : true },
           /*h1 : { visible : true },*/
           /*h2 : { visible : true },*/
           h3 : { visible : true },
           //h4 : { visible : true },
           //h5 : { visible : true },
           paragraph : { visible : true },
           italic  : { visible : true },
           //removeFormat : { visible : true },
           createLink : { visible : true },
           html : { visible : true },
           insertTable : { visible : true }
         }
         ,css: 'library/wysiwyg_content.css'
       });

       centrenotification(650,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  

      $('#form').ajaxForm(
       {
         success: function()
          {
            window.location.reload();
          }
       });
    });
 }

function selectAlbums()
 {
   $("#notification").load('library/adminAlbums.php?t=select','',function()
    {
       centrenotification(650,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();
    });
 }

function createAlbum()
 {

   $("#notification").load('library/adminAlbums.php?t=create','',function()
    {
      $('#form').ajaxForm(
       {
         success: function()
          {
            $("#notification").load('library/adminAlbums.php?t=select','',function()
             {
              centrenotification(650,350);
              $("#notificationbg").fadeIn();
              $("#notification").fadeIn();  
             });
          }
       });

       centrenotification(650,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });

 }

function editAlbum(id)
 {

   $("#notification").load('library/adminAlbums.php?t=edit&id=' + id,'',function()
    {

      $('#form').ajaxForm(
       {
         success: function()
          {
            $("#notification").load('library/adminAlbums.php?t=select','',function()
             {
              centrenotification(650,350);
              $("#notificationbg").fadeIn();
              $("#notification").fadeIn();  
             });
          }
       });

       centrenotification(650,350);
       $("#notificationbg").fadeIn();
       $("#notification").fadeIn();  
    });

 }

function publishAsset(id, val)
 {
   $("#publish").load('library/adminAlbums.php?t=publish&id=' + id + '&val=' + val);
 }

function position(dir,pos,id)
 {
   $("#publish").load('library/adminAlbums.php?t=position&dir=' + dir + '&pos=' + pos + '&id=' + id,'',function()
    {
      window.location.reload();
    });
 }

function deleteAlbum(id)
 {
   var answer = confirm("Delete Album?");
   if (answer)
    {
     $("#publish").load('library/adminAlbums.php?t=delete&id=' + id,"",function()
      {
            $("#notification").load('library/adminAlbums.php?t=select','',function()
             {
              centrenotification(650,350);
              $("#notificationbg").fadeIn();
              $("#notification").fadeIn();  
             });
      });
    }
 }
function sandyLogon()
 {
   var sandy_un;
   var sandy_pw;
   
   sandy_un = escape($("#sandy_un").val());
   sandy_pw = escape($("#sandy_pw").val());

   $("#logon").load('library/ajax.php?t=sandyLogon&sandy_un=' + sandy_un + '&sandy_pw=' + sandy_pw,'',function()
    {
      $("#leftpane").load('library/blog.php?t=selectPost');
    });
 }
