/*
JavaScript frontend CCTV
Author: Fabien Schurter
Uses: jQuery
*/

$(document).ready(function()
{
  // Interactive form inputs

  var inputs = $('input[type^="text"].can_empty');

  inputs.each(function(index, value)
  {
    var node = $(value);
    var baseVal = node.val();

    node.bind('click focus', function()
    {
      var target = $(this);

      if(target.val() == baseVal)
      {
        target.val('');
      }
    });

    node.blur(function()
    {
      var target = $(this);

      if(target.val() == '')
      {
        target.val(baseVal);
      }
    });
  });

  // Search form

  $('#search_submit').click(function()
  {
    $('#search_form').submit();
  });

  // Fancyboxes

  if(jQuery.fancybox)
  {
    var options = {
      width: 640,
      height: 360,
      padding: 20,
      autoScale: false,
      type: 'iframe',
      centerOnScroll: true,
      showNavArrows: false
    };

    $('#read_comments').fancybox(options);
    //$('#share_on_facebook').fancybox(options);

    options.width = 380;
    options.height = 520;

    $('#post_comment').fancybox(options);
  }

  // Video slides carousel

  if(jQuery().jCarouselLite)
  {
    $('#video_list').jCarouselLite({
      btnNext: '.control_right',
      btnPrev: '.control_left',
      visible: 8,
      scroll: 1,
      circular: false,
      speed: 250
    });
  }

  // Video slides hover

  $('div.thumb.hover').mouseover(function()
  {
    var target = $(this);
    var offset = target.offset();

    var clone = target.clone()
                      .mouseout(function() { $(this).remove(); })
                      .click(function() { location = target.attr('title'); })
                      .addClass('clone')
                      .css('position', 'absolute')
                      .offset({'top': offset.top - 8, 'left': offset.left - 12});

    $('body').append(clone);
  });
});

