$(function(){
	initCufon();
	initPage();
	initCycleGallery();
	initFooterGallery();
	initGallery();
})

function initGallery(){
	jQuery('div.gallery').fadeGallery({
		slideElements:'.gallery-box > .holder',
		pagerLinks:'.gallery-list li',
		autoHeight: true
	});
}

// horizontal gallery init
function initFooterGallery() {
	// settings
	var _activeClass = 'active';
	var _switchTime = 5000;
	var _speed = 600;

	$('.footer-box').each(function(){
		// gallery options
		var _holder = $(this);
		var _btnPrev = _holder.find('a.prev');
		var _btnNext = _holder.find('a.next');
		var _pagination = _holder.find('ul.menu li');
		var _slidesHolder = _holder.find('div.footer-slider');
		var _slider = _slidesHolder.find('ul');
		var _slides = _slider.children();
		var _slidesCount = _slides.length;
		var _currentIndex = 0;
		var _sumWidth = 0;
		var _animating = false;
		var _autoRotation = true;
		var _rotateDirection = nextSlide;
		var _pauseOnHover = true;
		var _timer;
		
		_holder.css({position: 'relative'});
		_slider.css({position: 'relative'});
		if(_pagination){_pagination.eq(_currentIndex).addClass(_activeClass);}
		// gallery init
		_slides.each(function(ind){
			_sumWidth += $(this).attr('rel',ind).outerWidth(true);
		});
		_slider.prepend(_slides.clone()).append(_slides.clone());
		_slider.css({marginLeft:-_sumWidth});
		
		if(_autoRotation){autoRotate();}
		
		function autoRotate() {
			if(_timer) clearInterval(_timer);
			if(_autoRotation){
				_timer = setInterval(_rotateDirection, _switchTime);
			}
		}
		
		if(_pauseOnHover){
			_holder.hover(function(){
				if(_timer) clearInterval(_timer);
			},function(){
				autoRotate();
			});
		}
		
		// gallery control
		_btnPrev.click(prevSlide);
		_btnNext.click(nextSlide);

		// gallery animation
		function prevSlide() {
			if(!_animating) {
				_currentIndex--;
				switchSlide();
			}
			return false;
		}
		function nextSlide() {
			if(!_animating) {
				_currentIndex++;
				switchSlide();
			}
			return false;
		}

		function switchSlide() {
			_animating = true;
			var offset = 0;
			if(_currentIndex>=0) offset = -_sumWidth- _slider.children().eq(_currentIndex ).position().left
			else offset = -_slider.children().eq(_slidesCount+_currentIndex).position().left;
			
			_slider.animate({marginLeft:offset},{duration:_speed, queue:false,complete:function(){
				if(Math.abs(_currentIndex) == _slidesCount) {
					_currentIndex = 0;
					_slider.css({marginLeft:-_sumWidth});
				}
				_animating = false;
			}});
			if(_pagination.length){
				_pagination.removeClass(_activeClass);
				_pagination.eq(_currentIndex).addClass(_activeClass);
				if(_currentIndex > _pagination.length - 1){
					_pagination.eq(0).addClass(_activeClass);
				}
			}
		}

		// event handler
		_holder.bind('scrollto',function(e,h){
			if(!_animating) {
				if(_currentIndex == _slidesCount-1) _currentIndex = _slidesCount;
				else _currentIndex = h.num;
				switchSlide();
			}
		})

		// clone events
		_slider.children().each(function(){
			var link = $(this);
			var ind = parseInt(link.attr('rel'));
			link.click(function(){
				_holder.trigger('setslide',{num:ind});
				return false;
			})
		})
	});
}

// horizontal gallery init
function initCycleGallery() {
	// settings
	var _activeClass = 'active';
	var _switchTime = 5000;
	var _speed = 450;

	$('.carusel').each(function(){
		// gallery options
		var _holder = $(this);
		var _btnPrev = _holder.find('a.prev');
		var _btnNext = _holder.find('a.next');
		var _pagination = _holder.find('ul.menu li');
		var _slidesHolder = _holder.find('div.carusel-holder');
		var _slider = _slidesHolder.find('ul');
		var _slides = _slider.children();
		var _slidesCount = _slides.length;
		var _currentIndex = 0;
		var _sumWidth = 0;
		var _animating = false;
		var _autoRotation = true;
		var _rotateDirection = nextSlide;
		var _pauseOnHover = true;
		var _timer;
		
		_holder.css({position: 'relative'});
		_slider.css({position: 'relative'});
		if(_pagination){_pagination.eq(_currentIndex).addClass(_activeClass);}
		// gallery init
		_slides.each(function(ind){
			_sumWidth += $(this).attr('rel',ind).outerWidth(true);
		});
		_slider.prepend(_slides.clone()).append(_slides.clone());
		_slider.css({marginLeft:-_sumWidth});
		
		if(_autoRotation){autoRotate();}
		
		function autoRotate() {
			if(_timer) clearInterval(_timer);
			if(_autoRotation){
				_timer = setInterval(_rotateDirection, _switchTime);
			}
		}
		
		if(_pauseOnHover){
			_holder.hover(function(){
				if(_timer) clearInterval(_timer);
			},function(){
				autoRotate();
			});
		}
		
		// gallery control
		_btnPrev.click(prevSlide);
		_btnNext.click(nextSlide);

		// gallery animation
		function prevSlide() {
			if(!_animating) {
				_currentIndex--;
				switchSlide();
			}
			return false;
		}
		function nextSlide() {
			if(!_animating) {
				_currentIndex++;
				switchSlide();
			}
			return false;
		}

		function switchSlide() {
			_animating = true;
			var offset = 0;
			if(_currentIndex>=0) offset = -_sumWidth- _slider.children().eq(_currentIndex ).position().left
			else offset = -_slider.children().eq(_slidesCount+_currentIndex).position().left;
			
			_slider.animate({marginLeft:offset},{duration:_speed, queue:false,complete:function(){
				if(Math.abs(_currentIndex) == _slidesCount) {
					_currentIndex = 0;
					_slider.css({marginLeft:-_sumWidth});
				}
				_animating = false;
			}});
			if(_pagination.length){
				_pagination.removeClass(_activeClass);
				_pagination.eq(_currentIndex).addClass(_activeClass);
				if(_currentIndex > _pagination.length - 1){
					_pagination.eq(0).addClass(_activeClass);
				}
			}
		}

		// event handler
		_holder.bind('scrollto',function(e,h){
			if(!_animating) {
				if(_currentIndex == _slidesCount-1) _currentIndex = _slidesCount;
				else _currentIndex = h.num;
				switchSlide();
			}
		})

		// clone events
		_slider.children().each(function(){
			var link = $(this);
			var ind = parseInt(link.attr('rel'));
			link.click(function(){
				_holder.trigger('setslide',{num:ind});
				return false;
			})
		})
	});
}

function initCufon() {
	Cufon.replace('.promo-box strong', { textShadow: '#003b49 2px 3px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.more', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.mail-form .submit', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.signup-form .btn-signup', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.btn', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.gallery-block .more-link', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.products .more-link', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.table-box .book a', { textShadow: '#003b49 2px 2px, #003b49 1px 1px',fontFamily: 'neo_sans', hover: true });
	Cufon.replace('.effects-test .shadow', { textShadow: '#555 1px 1px, #000 2px 2px',fontFamily: 'Frutiger'});
}

function initPage()
{
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: false,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
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.filterClass) o.filterClass = "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) == -1) {
				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) == -1) {
				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";
	}
}

// slideshow plugin
jQuery.fn.fadeGallery = function(_options){
	var _options = jQuery.extend({
		slideElements:'div.slideset > div',
		pagerLinks:'div.pager a',
		btnNext:'a.next',
		btnPrev:'a.prev',
		btnPlayPause:'a.play-pause',
		btnPlay:'a.play',
		btnPause:'a.pause',
		pausedClass:'paused',
		disabledClass: 'disabled',
		playClass:'playing',
		activeClass:'active',
		loadingClass:'ajax-loading',
		loadedClass:'slide-loaded',
		dynamicImageLoad:false,
		dynamicImageLoadAttr:'alt',
		currentNum:false,
		allNum:false,
		startSlide:null,
		noCircle:false,
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		onBeforeFade:false,
		onAfterFade:false,
		onChange:false,
		disableWhileAnimating:false,
		switchTime:3000,
		duration:650,
		event:'click'
	},_options);

	return this.each(function(){
		// gallery options
		if(this.slideshowInit) return; else this.slideshowInit;
		var _this = jQuery(this);
		var _slides = jQuery(_options.slideElements, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _btnPlayPause = jQuery(_options.btnPlayPause, _this);
		var _btnPause = jQuery(_options.btnPause, _this);
		var _btnPlay = jQuery(_options.btnPlay, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _dynamicImageLoad = _options.dynamicImageLoad;
		var _dynamicImageLoadAttr = _options.dynamicImageLoadAttr;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _loadingClass = _options.loadingClass;
		var _loadedClass = _options.loadedClass;
		var _disabledClass = _options.disabledClass;
		var _pausedClass = _options.pausedClass;
		var _playClass = _options.playClass;
		var _autoHeight = _options.autoHeight;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _currentNum = (_options.currentNum ? jQuery(_options.currentNum, _this) : false);
		var _allNum = (_options.allNum ? jQuery(_options.allNum, _this) : false);
		var _startSlide = _options.startSlide;
		var _noCycle = _options.noCircle;
		var _onChange = _options.onChange;
		var _onBeforeFade = _options.onBeforeFade;
		var _onAfterFade = _options.onAfterFade;
		var _disableWhileAnimating = _options.disableWhileAnimating;
		var actSlide = true;

		// gallery init
		var _anim = false;
		var _hover = false;
		var _prevIndex = 0;
		var _currentIndex = 0;
		var _slideCount = _slides.length;
		var _timer;
		if(_slideCount < 2) return;

		_prevIndex = _slides.index(_slides.filter('.'+_activeClass));
		if(_prevIndex < 0) _prevIndex = _currentIndex = 0;
		else _currentIndex = _prevIndex;
		
		if(actSlide){
			var ind = _pagerLinks.index(_pagerLinks.filter('.active'));
			_currentIndex = ind;
			actSlide = false;
		}

		
		if(_startSlide != null) {
			if(_startSlide == 'random') _prevIndex = _currentIndex = Math.floor(Math.random()*_slideCount);
			else _prevIndex = _currentIndex = parseInt(_startSlide);
		}
		_slides.hide().eq(_currentIndex).show();
		if(_autoRotation) _this.removeClass(_pausedClass).addClass(_playClass);
		else _this.removeClass(_playClass).addClass(_pausedClass);

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				nextSlide();
				return false;
			});
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentIndex != _ind) {
						if(_disableWhileAnimating && _anim) return;
						_prevIndex = _currentIndex;
						_currentIndex = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// play pause section
		if(_btnPlayPause.length) {
			_btnPlayPause.bind(_controlEvent,function(){
				if(_this.hasClass(_pausedClass)) {
					_this.removeClass(_pausedClass).addClass(_playClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_autoRotation = false;
					if(_timer) clearTimeout(_timer);
					_this.removeClass(_playClass).addClass(_pausedClass);
				}
				return false;
			});
		}
		if(_btnPlay.length) {
			_btnPlay.bind(_controlEvent,function(){
				_this.removeClass(_pausedClass).addClass(_playClass);
				_autoRotation = true;
				autoSlide();
				return false;
			});
		}
		if(_btnPause.length) {
			_btnPause.bind(_controlEvent,function(){
				_autoRotation = false;
				if(_timer) clearTimeout(_timer);
				_this.removeClass(_playClass).addClass(_pausedClass);
				return false;
			});
		}
		// dynamic image loading (swap from ATTRIBUTE)
		function loadSlide(slide) {
			if(!slide.hasClass(_loadingClass) && !slide.hasClass(_loadedClass)) {
				var images = slide.find(_dynamicImageLoad) // pass selector here
				var imagesCount = images.length;
				if(imagesCount) {
					slide.addClass(_loadingClass);
					images.each(function(){
						var img = this;
						img.onload = function(){
							img.loaded = true;
							img.onload = null;
							setTimeout(reCalc,_duration);
						}
						img.setAttribute('src', img.getAttribute(_dynamicImageLoadAttr));
						img.setAttribute(_dynamicImageLoadAttr,'');
					}).css({opacity:0});

					function reCalc() {
						var cnt = 0;
						images.each(function(){
							if(this.loaded) cnt++;
						});
						if(cnt == imagesCount) {
							slide.removeClass(_loadingClass);
							images.animate({opacity:1},{duration:_duration,complete:function(){
								if(jQuery.browser.msie && jQuery.browser.version < 9) jQuery(this).css({opacity:'auto'})
							}});
							slide.addClass(_loadedClass)
						}
					}
				}
			}
		}

		// gallery animation
		function prevSlide() {
			if(_disableWhileAnimating && _anim) return;
			_prevIndex = _currentIndex;
			if(_currentIndex > 0) _currentIndex--;
			else {
				if(_noCycle) return;
				else _currentIndex = _slideCount-1;
			}
			switchSlide();
		}
		function nextSlide() {
			if(_disableWhileAnimating && _anim) return;
			_prevIndex = _currentIndex;
			if(_currentIndex < _slideCount-1) _currentIndex++;
			else {
				if(_noCycle) return;
				else _currentIndex = 0;
			}
			switchSlide();
		}
		function refreshStatus() {
			if(_dynamicImageLoad) loadSlide(_slides.eq(_currentIndex));
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentIndex).addClass(_activeClass);
			if(_currentNum) _currentNum.text(_currentIndex+1);
			if(_allNum) _allNum.text(_slideCount);
			_slides.eq(_prevIndex).removeClass(_activeClass);
			_slides.eq(_currentIndex).addClass(_activeClass);
			if(_noCycle) {
				if(_btnPrev.length) {
					if(_currentIndex == 0) _btnPrev.addClass(_disabledClass);
					else _btnPrev.removeClass(_disabledClass);
				}
				if(_btnNext.length) {
					if(_currentIndex == _slideCount-1) _btnNext.addClass(_disabledClass);
					else _btnNext.removeClass(_disabledClass);
				}
			}
			if(typeof _onChange === 'function') {
				_onChange(_this, _slides, _prevIndex, _currentIndex);
			}
		}
		function switchSlide() {
			_anim = true;
			if(typeof _onBeforeFade === 'function') _onBeforeFade(_this, _slides, _prevIndex, _currentIndex);
			_slides.eq(_prevIndex).fadeOut(_duration,function(){
				_anim = false;
			});
			_slides.eq(_currentIndex).fadeIn(_duration,function(){
				if(typeof _onAfterFade === 'function') _onAfterFade(_this, _slides, _prevIndex, _currentIndex);
			});
			if(_autoHeight) _slides.eq(_currentIndex).parent().animate({height:_slides.eq(_currentIndex).outerHeight(true)},{duration:_duration,queue:false});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		refreshStatus();
		autoSlide();
	});
}

/* TESTIMONIALS */
$(document).ready(function(){
	var gallery1 = $('.testimonials-gallery').gallery({
		duration: 600,
		listOfSlides: '.testimonials>ul>li',
		changeHeight: true
	});
	$('.testimonials-gallery').mouseenter(function(){
		gallery1.stop();
	}).mouseleave(function(){
		gallery1.play();
	});
});

(function($) {
	/* Gallery */
	function Gallery(el, options) {
		this._hold = $(el);
		this.initOptions(options);
		this._timer = options.autoRotation;
		this._t;
		this.initialize();
	}
	
	$.fn.gallery = function(options) {
		return new Gallery(this.get(0), options);
	};
	
	Gallery.prototype = {
		initOptions: function(_obj){
			this.options = {
				randomSlide: false,
				changeHeight: false,
				duration: 700,
				slideElement: 1,
				event: 'click',
				autoRotation: false,
				effect: false,
				listOfSlides: 'ul > li',
				switcher: false,
				disableBtn: false,
				nextBtn: 'a.next-link, a.btn-next, a.next, a.link-next',
				prevBtn: 'a.prev-link, a.btn-prev, a.prev, a.link-prev',
				circle: true,
				direction: false,
				IE: false,
				swicherBuilder: false,
				titleReplace: false
			};
			for(key in _obj) this.options[key] = _obj[key];
		},
		initialize: function(){
			var _this = this;
			var _hold = _this._hold;
			var _speed = _this.options.duration;
			var _timer = _this.options.autoRotation;
			var _el = _hold.find(_this.options.listOfSlides);
			if(_el.length){
				_el.css('display','block');
				if (_this.options.effect){
					_el.css('position','absolute');
					var _list = _el;
				}
				else var _list = _el.parent();
				var _switcher = _hold.find(_this.options.switcher);
				var _next = _hold.find(_this.options.nextBtn);
				var _prev = _hold.find(_this.options.prevBtn);
				var _count = _el.index(_el.filter(':last'));
				var _w = _el.outerWidth(true);
				var _h = _el.outerHeight(true);
				if (_this.options.switcher) var _active = _switcher.index(_switcher.filter('.active:eq(0)'));
				else var _active = _el.index(_el.filter('.active:eq(0)'));
				if (_active < 0) _active = 0;
				var _last = _active;
				if(_this.options.swicherBuilder){
					this._hold.append('<ul class="'+_this.options.swicherBuilder+'" />');
					var _newSwitcher = $('.' + _this.options.swicherBuilder, this._hold);
					
					for (var i = 0; i < _el.length; i++){
						_newSwitcher.append('<li><a href="#">'+ (i+1) +'</a></li>');
						if(i==_active){
							_newSwitcher.find('li').eq(_active).addClass('active');
						}
					};
					
					_switcher = _newSwitcher.find('li');
				}
				if(_this.options.titleReplace){
					var titleReplace = _hold.find(_this.options.titleReplace);
					if(titleReplace.length){
						_el.each(function(i){
							var this_el = $(this);
							var this_title = this_el.attr('title');
							if(this_title.length){
								_el.eq(i).data("title", this_title);
							}else{
								_el.eq(i).data("title", 'No title');
							}
							this_el.removeAttr('title');
						});
						titleReplace.html(_el.eq(_active).data("title"));
					}
				}
				
				// Installation directions
				if (!_this.options.direction) {
					var _wrapHolderW = Math.ceil(_list.parent().width() / _w);
					if (((_wrapHolderW - 1) * _w + _w / 2) > _list.parent().width()) _wrapHolderW--;
				}
				else{
					var _wrapHolderW = Math.ceil(_list.parent().height()/_h);
					if (((_wrapHolderW-1)*_h + _h/2) > _list.parent().height()) _wrapHolderW--;
				}
				
				// Setting "fade" or "slide" effect
				if (!_this.options.effect) var rew = _count - _wrapHolderW + 1;
				else var rew = _count;
				if (!_this.options.effect) {
					if (!_this.options.direction) _list.css({marginLeft: -(_w * _active)})
					else _list.css({marginTop: -(_h * _active)})
				}
				else {
					_list.css({
						opacity: 0
					}).removeClass('active').eq(_active).addClass('active').css({
						opacity: 1
					}).css('opacity', 'auto');
					_switcher.removeClass('active').eq(_active).addClass('active');
					if ($.browser.msie && _this.options.IE){
						_list.css({
							display: 'none'
						});
						_list.eq(_active).css({
							display: 'block'
						});
					}
				}
				
				// Disable or enable buttons "prev next"
				if (_this.options.disableBtn) {
					if (_count < _wrapHolderW) _next.addClass(_this.options.disableBtn);
					_prev.addClass(_this.options.disableBtn);
				}
				
				// Function to "fade"
				if(_this.options.changeHeight){
					if (_this.options.effect){
						_el.parent().css({height: _list.eq(_active).outerHeight(true), overflow: 'hidden'});
					}else{
						if(_this.options.slideElement>1){
							var active_H = _list.children().eq(_active).outerHeight(true);
							for (var i = 1; i < _this.options.slideElement; i++){
								if(active_H<_list.children().eq(_active+i).outerHeight(true)){
									active_H=_list.children().eq(_active+i).outerHeight(true)
								}
							};
							_el.parent().css({height: active_H, overflow: 'hidden'});
						}else _el.parent().css({height: _list.children().eq(_active).outerHeight(true), overflow: 'hidden'});
					}
				}
				function fadeElement(){
					if ($.browser.msie && _this.options.IE){
						_list.eq(_last).css({
							opacity:0,
							display: 'none'
						});
						_list.removeClass('active').eq(_active).addClass('active').css({
							opacity:'auto',
							display: 'block'
						});
					}
					else{
						_list.eq(_last).animate({opacity:0}, {queue:false, duration: _speed});
						_list.removeClass('active').eq(_active).addClass('active').animate({
							opacity:1
						}, {queue:false, duration: _speed, complete: function(){
							$(this).css('opacity','auto');
						}});
					}
					if(_this.options.changeHeight){
						_el.parent().animate({
							height: _list.eq(_active).outerHeight(true)
						}, {queue:false, duration:_speed});
					}
					if (_this.options.switcher) _switcher.removeClass('active').eq(_active).addClass('active');
					_last = _active;
					if(titleReplace){
						titleReplace.html(_el.eq(_active).data("title"));
					}
				}
				// Function for "slide"
				function scrollEl(){
					if (!_this.options.direction) _list.animate({marginLeft: -(_w * _active)}, {queue:false, duration: _speed})
					else _list.animate({marginTop: -(_h * _active)}, {queue:false, duration: _speed})
					if (_this.options.switcher && _this.options.slideElement) _switcher.removeClass('active').eq(_active/_this.options.slideElement).addClass('active');
					else{
						if (_this.options.switcher) _switcher.removeClass('active').eq(_active).addClass('active');
					}
					if(_this.options.changeHeight){
						if(_this.options.slideElement>1){
							var active_H = _list.children().eq(_active).outerHeight(true);
							for (var i = 1; i < _this.options.slideElement; i++){
								if(active_H<_list.children().eq(_active+i).outerHeight(true)){
									active_H=_list.children().eq(_active+i).outerHeight(true)
								}
							};
							_el.parent().animate({
								height: active_H
							}, {queue:false, duration:_speed});
						}else{
							_el.parent().animate({
								height: _list.children().eq(_active).outerHeight(true)
							}, {queue:false, duration:_speed});
						}
					}
					if(titleReplace){
						titleReplace.html(_el.eq(_active).data("title"));
					}
				}
				function toPrepare(){
					if ((_active == rew) && _this.options.circle) _active = -_this.options.slideElement;
					for (var i = 0; i < _this.options.slideElement; i++){
						if(_this.options.randomSlide){
							var pre_active = _active;
							if(_this.options.listOfSlides.length){
								while(pre_active == _active){
									_active = parseInt(Math.random()*(_count+1));
								}
							}
						}else{
							_active++;
						}
						if (_active > rew) {
							_active--;
							if (_this.options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_this.options.disableBtn);
						}
					}
					if (_active == rew) if (_this.options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_this.options.disableBtn);
					if (!_this.options.effect) scrollEl();
					else fadeElement();
				}
				if(_this._timer){
					_this._hold.bind('runTimer', function(){
						if(_this._t) clearTimeout(_this._t);
						_this._t = setInterval(function(){
							toPrepare();
						}, _this._timer);
					});
				}
				_next.click(function(){
					if(_this._t) clearTimeout(_this._t);
					if (_this.options.disableBtn &&(_count > _wrapHolderW)) _prev.removeClass(_this.options.disableBtn);
					toPrepare();
					if (_this._timer) _this._hold.trigger('runTimer');
					return false;
				});
				_prev.click(function(){
					if(_this._t) clearTimeout(_this._t);
					if (_this.options.disableBtn &&(_count > _wrapHolderW)) _next.removeClass(_this.options.disableBtn);
					if ((_active == 0) && _this.options.circle) _active = rew + _this.options.slideElement;
					for (var i = 0; i < _this.options.slideElement; i++){
						_active--;
						if (_active < 0) {
							_active++;
							if (_this.options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_this.options.disableBtn);
						}
					};
					if (_active == 0) if (_this.options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_this.options.disableBtn);
					if (!_this.options.effect) scrollEl();
					else fadeElement();
					if (_this._timer) _this._hold.trigger('runTimer');
					return false;
				});
				if (_this.options.switcher) _switcher.click(function(){
					if (_this.options.event=='click'){
						if (_this.options.slideElement){
							_active = _switcher.index($(this))*_this.options.slideElement;
						}else{
							_active = _switcher.index($(this));
						}
						if(_this._t) clearTimeout(_this._t);
						if (!_this.options.effect) scrollEl();
						else fadeElement();
						if (_this._timer) _this._hold.trigger('runTimer');
					}
					return false;
				}).mouseenter(function(){
					if (_this.options.event=='hover'){
						if (_this.options.slideElement){
							_active = _switcher.index($(this))*_this.options.slideElement;
						}else{
							_active = _switcher.index($(this));
						}
						if(_this._t) clearTimeout(_this._t);
						if (!_this.options.effect) scrollEl();
						else fadeElement();
						if (_this._timer) _this._hold.trigger('runTimer');
					}
				});
				if (_this._timer) _this._hold.trigger('runTimer');
			}
		},
		stop: function(){
			var _this = this;
			if (_this._t) clearTimeout(_this._t);
		},
		play: function(){
			var _this = this;
			if (_this._t) clearTimeout(_this._t);
			if (_this._timer) _this._hold.trigger('runTimer');
		}
	}
}(jQuery));
