/*******************************************************************************************/
// jquery.event.wheel.js - rev 1
// Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
// Liscensed under the MIT License (MIT-LICENSE.txt)
// http://www.opensource.org/licenses/mit-license.php
// Created: 2008-07-01 | Updated: 2008-07-14
// $(body).bind('wheel',function(event,delta){    alert( delta>0 ? "up" : "down" );    });
/*******************************************************************************************/
;(function($){$.fn.wheel=function(a){return this[a?"bind":"trigger"]("wheel",a)};$.event.special.wheel={setup:function(){$.event.add(this,b,wheelHandler,{})},teardown:function(){$.event.remove(this,b,wheelHandler)}};var b=!$.browser.mozilla?"mousewheel":"DOMMouseScroll"+($.browser.version<"1.9"?" mousemove":"");function wheelHandler(a){switch(a.type){case"mousemove":return $.extend(a.data,{clientX:a.clientX,clientY:a.clientY,pageX:a.pageX,pageY:a.pageY});case"DOMMouseScroll":$.extend(a,a.data);a.delta=-a.detail/3;break;case"mousewheel":a.delta=a.wheelDelta/120;if($.browser.opera)a.delta*=-1;break}a.type="wheel";return $.event.handle.call(this,a,a.delta)}})(jQuery);

/*
 * jQuery crawlLine v1.2.0
 * Copyright (c) 2008 Taranets Aleksey
 * email: aleks_tar@ukr.net
 * www: markup-javascript.com
 * (http://markup-javascript.com/2009/06/06/begushhaya-stroka-na-jquery-c-prokrutkoj-teksta/)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

jQuery.fn.crawlLine = function(_options){
  // defaults options
  var _options = jQuery.extend({
    speed:'170',
    crawElement:'div',
    textElement:'li',
    hoverClass:'viewText',
    delay:'2300'
  },_options);

  $('#about ul').show();
  var width_parent = $('#about').width();
  var add_width_elem = $('#about ul li').innerWidth();

  return this.each(function(){
    var _THIS = jQuery(this);
    var _el = $(_options.crawElement, _THIS).css('position','absolute');
    var _text = $(_options.textElement, _THIS);
    //var _clone = _text.css('whiteSpace','nowrap').clone();
    var _elWidth = 0;
    var _k = 1;

    // set parametrs *******************************************************
    var _textWidth = 0;
    _text.each(function(){
      _textWidth += $(this).outerWidth(true);
    });
    var _duration = _textWidth*50 / _options.speed;
   // _el.append(_clone);
    _el.css('width',_textWidth*2);

    var left_val;

    function getCookie(name) {
      var cookie = " " + document.cookie;
      var search = " " + name + "=";
      var setStr = null;
      var offset = 0;
      var end = 0;
      if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
          offset += search.length;
          end = cookie.indexOf(";", offset)
          if (end == -1) {
             end = cookie.length;
          }
        setStr = unescape(cookie.substring(offset, end));
        }
      }
      _el.css('left',setStr);
    }

    function writeInCookie(value_cookie) {
      document.cookie="left_name=" + value_cookie + "; path=/;";
    }

    var animate = function() {
    _el.animate({left:'-=' + add_width_elem +'px'}, {queue:false, duration:_duration*_k, easing:'linear', complete:function(){
      _k=1;
      left_val = _el.css('left');
      writeInCookie(left_val);
      if (left_val == -_textWidth+'px') {writeInCookie(add_width_elem);_el.css('left', add_width_elem + 'px'); setTimeout(animate, 0);}
        else setTimeout(animate, _options.delay);
      }})
    }

    if (_textWidth > add_width_elem) {
      getCookie('left_name');
      animate();
    }

    // scrolling with mouse
    /*
    _THIS.bind('wheel',function(event,delta){
      var _marginScroll;
      if (delta<0) {
        _marginScroll = parseInt(_el.css('left')) - 20;
        _el.animate({left:_marginScroll}, {queue:false, duration:100, easing:'linear', complete:function(){
          _k = (_textWidth + parseInt(_el.css('left')))/_textWidth;
        }});
      } else {
        _marginScroll = parseInt(_el.css('left')) + 20;
        if (_marginScroll > 0) _marginScroll = 0;
        _el.animate({left:_marginScroll}, {queue:false, duration:100, easing:'linear', complete:function(){
          _k = (_textWidth + parseInt(_el.css('left')))/_textWidth;
        }});
      }
      return false;
    });
    */

  });
}





