/// <reference path="jquery-1.4.4-vsdoc.js" />
// svcr-functions.js - requires jquery.js 1.5+
// created by Mindfly Web Studio
// created: Feb 09, 2011
// modified: May 09, 2011

$(document).ready(function() {
    bg.Twitter.buildABadge('mindflystudio', '#twitter', 'tweet tweet-time');
  $('header ul.menu a').last().click(function() { // nasty looking but works for blog too
      $('html, body').animate({
        scrollTop: $('footer').offset().top
      }, 1200);
    });
    blurBoxes();
    revealThankYou();
    testimonialAJAX();
});

function blurBoxes() {
    $('#contact input[type="text"], #contact textarea, #commentform input[type="text"], #commentform textarea, #searchform input[type="text"]').focus(function() {
        var clearThis = false;
        if ($(this).attr('class') == "txt_name" && $(this).attr('value') == "Name") clearThis = true;
        if ($(this).attr('class') == "txt_email" && $(this).attr('value') == "Email") clearThis = true;
        if ($(this).attr('class') == "txt_message" && $(this).attr('value') == "Message") clearThis = true;
    if ($(this).attr('class') == "txt_author" && $(this).attr('value') == "Name*") clearThis = true;
    if ($(this).attr('class') == "txt_address" && $(this).attr('value') == "Email*") clearThis = true;
    if ($(this).attr('class') == "txt_website" && $(this).attr('value') == "Website") clearThis = true;
    if ($(this).attr('class') == "txt_comment" && $(this).attr('value') == "Comment") clearThis = true;
  if ($(this).attr('id') == "s" && $(this).attr('value') == "search our blog") clearThis = true;
        if (clearThis) $(this).attr('value', '');
    });
    $('#contact input[type="text"], #contact textarea, #commentform input[type="text"], #commentform textarea, #searchform input[type="text"]').blur(function() {
        if ($(this).attr('value') == '') {
            var insertValue = '';
            if ($(this).attr('class') == "txt_name") insertValue="Name";
            if ($(this).attr('class') == "txt_email") insertValue="Email";
            if ($(this).attr('class') == "txt_message") insertValue="Message";
      if ($(this).attr('class') == "txt_author") insertValue="Name*";
      if ($(this).attr('class') == "txt_address") insertValue="Email*";
            if ($(this).attr('class') == "txt_website") insertValue="Website";
            if ($(this).attr('class') == "txt_comment") insertValue="Comment";
      if ($(this).attr('id') == "s") insertValue="search our blog";
            $(this).attr('value', insertValue);
        }
    });
}


function testimonialAJAX(){
  $.ajax({
    type: "POST",
    url:"/webservices/Testimonial.asmx/GetRandom",
    data:'{}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: ajaxWin,
    error: ajaxFail
  });
}

function ajaxWin(data){  
  var testimonial = $.parseJSON(data.d);      
  $('#testimonial').append('<blockquote>' + testimonial.statement + '</blockquote> <cite>' + testimonial.contact + ' <em>(' + testimonial.company + ')</em></cite> ');  
}

function ajaxFail(data){
  
}


function revealThankYou() {
    if (location.hash == "#contact") {
      $('#contact .sent button').css('display','block');
      var t = setTimeout("$('#contact .sent button').fadeOut(1000);",4000);
        $('#contact .sent button').click(function() { $(this).fadeOut(1000); });
    }
}
