/*******************************************************************************************/
// 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);
(function($){
	$(function(){
		clearFormFields({
			clearInputs: true,
			clearTextareas: true,
			passwordFieldText: true,
			addClassFocus: "focus",
			filterClass: "default"
		});
		$('div.slider').crawlLine();
		initHover();
	});
	function initHover(){
		var _holder = $('div.infobox');
		var _btn = $('div.btn > a');
		_btn.hover(function(){
			_holder.addClass('hover-block');
		}).mouseout(function(){
			_holder.removeClass('hover-block');
		});
	}
	jQuery.fn.crawlLine = function(_options){
	// defaults options
	var _options = jQuery.extend({
		speed:3,
		crawElement:'ul',
		textElement:'li',
		hoverClass:'viewText'
	},_options);
	
	return this.each(function(){
		var _THIS = jQuery(this);
		var _el = $(_options.crawElement, _THIS).css('position','relative');
		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.prepend(_clone);
		_el.css({width:_textWidth*2,left:193});
	    var animate = function() {
			_el.animate({left:-_textWidth}, {queue:false, duration:_duration*_k, easing:'linear', complete:function(){
				_el.css('left',193);
				_k=1;
				animate();
			}})
	    }
		animate();
	    _THIS.hover(function() {
			_el.stop();
			_THIS.addClass(_options.hoverClass);
	    }, function(){
			_THIS.removeClass(_options.hoverClass);
			animate();
	    })
		_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;
		});
	});
}
}(jQuery))
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filter) o.filter = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
