


var showMenu = function(){
    
    attr = $(this).attr('tooltip');
 
    
    $('#tooltip').html(attr);
    
    //get the position of the image element
    pos   = $(this).offset();
    width = $(this).width();
    //show the tooltip directly to the right of the icon
    $menu.css({ "left": (pos.left + width+ 20) + "px", "top":(pos.top+10) + "px" }).fadeIn('fast');
   
}

var hideMenu = function(){
     $menu.hide()
}

var closePopups = function(){
     $('#timePopup').fadeOut('fast');
    $menu.fadeOut();
  
}

var showTimePopup = function(){
  
    //get the position of the placeholder element
    pos   = $(this).offset();
    width = $(this).width();
    
   
    //show the menu directly over the placeholder
    $time.css({ "left": (pos.left)-40 + "px", "top":(pos.top+30) + "px" }).fadeIn('fast');    
    
    
}


$(document).ready(function() {
                  
     CoolClock.findAndCreateClocks();
                  startTime();
                  
     //if submit button is clicked
     $('#submit').click(function () {        
                                     
           //Get the data from all the fields
           var name = $('input[name=name]');
           var email = $('input[name=email]');
           var website = $('input[name=website]');
           var comment = $('textarea[name=comment]');
                                     
            //Simple validation to make sure user entered something
            //If error found, add hightlight class to the text field
            if (name.val()=='') {
                name.addClass('hightlight');
                return false;
             } else name.removeClass('hightlight');
                                     
             if (email.val()=='') {
                 email.addClass('hightlight');
                 return false;
             } else email.removeClass('hightlight');
                                     
             if (comment.val()=='') {
                 comment.addClass('hightlight');
                 return false;
              } else comment.removeClass('hightlight');
                                     
              //organize the data properly
              var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
                  + website.val() + '&comment='  + encodeURIComponent(comment.val());
                                     
              //disabled all the text fields
              $('.text').attr('disabled','true');
                                     
              //show the loading sign
              $('.loading').show();
                                     
              //start the ajax
              $.ajax({
                  //this is the php file that processes the data and send mail
                  url: "process.php", 
                                            
                  //GET method is used
                  type: "GET",
                                            
                  //pass the data         
                  data: data,     
                                            
                 //Do not cache the page
                  cache: false,
                                            
                  //success
                  success: function (html) {              
                  //if process.php returned 1/true (send mail success)
                  if (html==1) {                  
                       //hide the form
                       $('.form').fadeOut('slow');                 
                                            
                       //show the success message
                        $('.done').fadeIn('slow');
                                            
                       //if process.php returned 0/false (send mail failed)
                  } else alert('Sorry, I am unable to send this email, either you have been sending me spam or I there is a problem at my end.  Either way you could try again later if it makes you feel better.');               
              }       
          });
                                     
       //cancel the submit button default behaviours
         return false;
        }); 
 }); 


function startTime()
{
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    var d=today.getDay();
    var dow;
    var ap;
    
    
    switch(d)
    {
        case 1:
            dow = "Monday";
            break;
        case 2:
            dow = "Tuesday";
            break;
        case 3:
            dow = "Wednesday";
            break;
        case 4:
            dow = "Thursday";
            break;
        case 5:
            dow = "Friday";
            break;
        case 6:
            dow = "Saturday";
            break;
        case 0:
            dow = "Sunday";
            break;
 
    
    }
    
    
    if (h==0) { h = 12; }
    if (h<12) { ap = "AM  "; } else { ap = "PM  "}
    if (h>12) { h= h - 12; }
    
    
    
    // add a zero in front of numbers<10
    m=checkTime(m);
    s=checkTime(s);
    document.getElementById('time').innerHTML=dow+" "+h+":"+m+":"+s + " " + ap;
    t=setTimeout('startTime()',1000);
}

function checkTime(i)
{
    if (i<10)
    {
        i="0" + i;
    }
    return i;
}


function isCanvasSupported(){
    var elem = document.createElement('canvas');
    return !!(elem.getContext && elem.getContext('2d'));
}

function clearObsolete(){
    document.getElementById('obsolete').innerHTML = "";
}

