if (jQuery) // Check if jQuery is loaded
{
  jQuery.noConflict();
  (function($) { // Making $ accessible even in noConflict
    $(document).ready(function(){
      
      // Adding placeholders for form fields
      if($.fn.placeholder)
      {
        $(".placeholder").placeholder();
      }
      
      // Setting up action url for contact form
      var contactForm = $("#contactForm").attr('action', '/cmail-form.php');
    
      // Adding basic validation to contact form
      if($.fn.checkRequired)
      {
        contactForm.checkRequired();
      }
      
      contactForm.submit(
        function ()
        {
          if (window.hasChecked == true)
            return true;
          
          var getFormField = function (id) { 
            return $('#form' + id).val()
          };

          $.post(
            '/ajax-test.php',
            {
              name:     getFormField('Name'),
              email:    getFormField('Email'),
              phone:    getFormField('Phone'),
              message:  getFormField('Message')
            },
            function () { window.hasChecked = true; contactForm.submit() }
          );

          return false;
        }
      );
      
      if ($.fn.cycle)
      {
        $('#implant-header').cycle({ fx: 'fade' });
      }

      
      $('input.niceField, textarea.niceField').focus(function () {
        $(this).addClass('focused');
      })

      $('input.niceField, textarea.niceField').blur(function () {
        $(this).removeClass('focused');
      });

      $('#formName').focus();
			
			$('#formName, #formEmail, #formPhone').keypress(
			  function (data) 
				{
				  if (data.which == '13')
					{
						$(this).blur();
						$(this).parent().next().children('input, textarea').focus();
						return false;
					}
				}
			);
      
      $('ul.videos li a').click(
        function ()
        {
					var createEmbed = function (src) {
						 /*<embed src="http://www.youtube.com/v/WU7tXl_dQWA"
         type="application/x-shockwave-flash"
         allowscriptaccess="always"
         class="change"
         wmode="transparent"
         width="550" height="339"></embed>*/
				    
				    return $(' \
							<object width="550" height="339">\
  <param name="movie"\
         value="' + src + '?rel=0&showinfo=0&autoplay=1"></param> \
         <param name="wmode" value="transparent"></param>\
          <param name="allowScriptAccess" value="always"></param>\
  <embed src="' + src + '?rel=0&showinfo=0&autoplay=1"\
         type="application/x-shockwave-flash"\
         allowscriptaccess="always"\
         wmode="transparent"\
         width="550" height="339"></embed>\
</object>\
							');
					};
					
					var url = $(this).attr('href')
                   .replace('watch?v=', 'v/');
          // p://www.youtube.com/watch?v=hJt2TmiJOCk
          /*$('#youtube-video param.change, #youtube-video param[name="movie"]').attr(
            'value',
            url
          );*/
					
					$('#youtube-video').html('');
					$('#youtube-video').append(createEmbed(url));

          return false;
        }
      );
    });
  })(jQuery);
}
