/**
 * Check if the mouse is inside the click area
 *
 * @param [MouseEvent] e
 * @param [Object] obj
 */
function isInside(e, obj) {
  var x = e.pageX - obj.offset().left;
  return (x > obj.width() - 15);
}

/**
 * Remove the submit button and enable pressing the looking glass
 */
$svjq(function() {
  $svjq('#search-form input[type=submit]').attr('name', 'mysubmit'); // jQuery can't submit form if a submit with the name submit exists in the form
  $svjq('#search-form input[type=submit]').hide();
  $svjq('#search-form input[type=text]').mousemove(function(e){
    if (isInside(e, $svjq(this))) {
      $svjq(this).css('cursor', 'pointer');
    } else {
      $svjq(this).css('cursor', 'auto');
    }
  });
  $svjq('#search-form input[type=text]').click(function(e){
    if (isInside(e, $svjq(this))) {
      e.preventDefault();
      $svjq(this).closest('form').submit();
    }
  });
});

$svjq(function() {

  if ($svjq.browser.msie  && parseInt($svjq.browser.version, 10) <= 8) {
    $svjq('#slider').closest('.pagewidth').parent().css('background', '#f3f3f3');
    $svjq('#slider p, #slider img').css('background', '#f3f3f3');
    if (parseInt($svjq.browser.version, 10) === 7) {
      $svjq('#slider').css('margin-top', '30px');
    }
  }

  var play = $svjq('<a class="play" href="#">Play</a>').click(function(e) {
    e.preventDefault();
    $svjq('#slider').cycle('resume');
    return false;
  });
  var pause = $svjq('<a class="pause" href="#">Pause</a>').click(function(e) {
    e.preventDefault();
    $svjq('#slider').cycle('pause');
    return false;
  });
  $svjq('#controls').append(play).append(pause);

  $svjq('#slider').cycle({
    fx: 'fade',
    speed: 1000,
    timeout: 6000,
    prev: '#prev',
    next: '#next',
    pager: '#nav',
    cleartypeNoBg: true
  });
});

