$(document).ready(function() {
    $('.slideshow').cycle({
    fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  });
  
//Show default text on input fields.
        $(".defaultText").focus(function(srcc)
        {
          if ($(this).val() == $(this)[0].title)
          {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
          }
        });
        
        $(".defaultText").blur(function()
        {
          if ($(this).val() == "")
          {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
          }
        });
        
        $(".defaultText").blur();      
  
  
});

$(function(){
      
   $("p").each(function() {
      // get paragraph text
      var mystring = $(this).text(); 
      // regular expression for a youtube video
      var expression = /http:\/\/(\w{0,3}\.)?youtube\.\w{2,3}\/watch\?v=[\w-]{11}/gi; 
       
      // get an array of matched video urls
      var videoUrl = mystring.match(expression);
      if (videoUrl !== null) {
         // for each video url change it to embedded
         for(count = 0; count < videoUrl.length; count++) {
            // replace url with embedded video
            mystring = mystring.replace(videoUrl[count], embedVideo(videoUrl[count]));      
         }
         $(this).replaceWith(mystring);
      }
      
      // replace old paragraph with new paragraph
      // $(this).replaceWith(mystring); 
   });
   
   function embedVideo(content) {
      var youtubeUrl = content;
      var youtubeId = youtubeUrl.match(/=[\w-]{11}/);
      var strId = youtubeId[0].replace(/=/,'');
      var result = '<div class="embedded_video">\n';
      result += '<object width="425" height="344">\n';
     // result += '<object width="580" height="400">\n';
      result += '<param name="movie" value="http://www.youtube.com/v/' + strId + 'g&hl=en&fs=1&"></param>\n';
      result += '<param name="allowFullScreen" value="true"></param>\n';
      result += '<param name="allowscriptaccess" value="always"></param>\n';
      result += '<embed src="http://www.youtube.com/v/' + strId + '&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>\n';
      result += '</object>\n';
      result += '</div>\n';
      return result;
   }

});
