jQuery.noConflict();
jQuery(document).ready(function($){
  var chwidth = 0;
  var chheight = 0;
  var timerId;
  var maxScroll = $(".content-holder").outerWidth();
  var left_begin = 0;
  var left_end = 100;
  var right_begin = $(".scrollarea").outerWidth() - 100;
  var right_end = $(".scrollarea").outerWidth();

  $('.sielaff_image').each(function(i,e){
    chwidth += $(this).outerWidth()+1;
  });
  
  if(chwidth==0) {
    chwidth = $('.content-holder:first-child').width();
  }
  
  $('.content-holder').width(chwidth);
  
  $('.scrollarea').bind('mousemove',function(e){
    clearInterval(timerId);
    var mousepos = e.pageX - $('.scrollarea').offset().left;
    timerId = setInterval(function() {
      if(mousepos >= left_begin && mousepos <= left_end && $('.content-scroll').scrollLeft()>0) {  
        var pos = $('.content-scroll').scrollLeft() - 3;
        $('.content-scroll').scrollLeft(pos);
      } else if(mousepos >= right_begin && mousepos <= right_end && $('.content-scroll').scrollLeft()<maxScroll) {
        var pos = $('.content-scroll').scrollLeft() + 3;        
        $('.content-scroll').scrollLeft(pos);
      } else clearInterval(timerId);
    }, 10);
  });
  
  $('.content-scroll').hover(function(e) { }, function(e) { clearInterval(timerId); });
  
  $('.sielaff_image img[title]').tooltip({position:'bottom center', offset:[-50, 0]});
  
  
  if($('#headersearch_sword').attr('value').length < 1) {
    $('#headersearch_sword').attr('value', $('#headersearch_sword').attr('title'));
  }
  
  $('#headersearch_sword').bind(
    'focusin',
    function() {
      if($(this).attr('value') == $(this).attr('title')) {
        $(this).attr('value','');
      }
    }
  );
  $('#headersearch_sword').bind(
    'focusout',
    function() {
      if($(this).attr('value').length < 1) {
        $(this).attr('value',$(this).attr('title'));
      }
    }
  );
  $('#headersearch_submit').bind(
    'click',
    function() {
      if($('#headersearch_sword').attr('value') == $('#headersearch_sword').attr('title')) {
        $('#headersearch_sword').attr('value','');
      }
    }
  );
});
