/*
(function ($) {
	$.event.special.load = {
		add: function (hollaback) {
			if ( this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '' ) {
				// Image is already complete, fire the hollaback (fixes browser issues were cached
				// images isn't triggering the load event)
				if ( this.complete || this.readyState === 4 ) {
					hollaback.handler.apply(this);
				}

				// Check if data URI images is supported, fire 'error' event if not
				else if ( this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0 ) {
					$(this).trigger('error');
				}
				
				else {
					$(this).bind('load', hollaback.handler);
				}
			}
		}
	};
}(jQuery));
*/

$(window).load(function () {
    function wrapImages () {
	    $('a.image-wrap').each(function () {   
//	    	console.log("wrap");
	    	var $this = $(this);
	    	var $img = $("img", this);
	    	function mark () {		    		
		    	rect = $this.attr("rect").split(",");    	
		    	var iw = $img.data("iw") || $img.width() || this.width, ih = $img.data("ih") || $img.height() || this.height;
		    	$img.data("iw", iw); $img.data("ih", ih);
		    	if (!rect[0].length) return;
		    	var x = parseFloat(rect[0]),
		    	    y = parseFloat(rect[1]),
		    	    w = parseFloat(rect[2]),
		    	    h = parseFloat(rect[3]);
		    		ow = parseFloat(rect[4]);
		    		oh = parseFloat(rect[5]);
		    	if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) {
		    	  return;
		    	}
		    	if (isNaN(ow)) ow = iw;
		    	if (isNaN(oh)) oh = ih;
		    	var r = Math.max(iw / ow, ih / oh);
		    	var ofx = r * ow - iw;
		    	var ofh = r * oh - ih;
		    	$rect = $("<div></div>").appendTo($this).addClass("tag-rect");
		    	$rect.css({
		    		left: r * x - ofx / 2,
		    		top: r * y - ofh / 2, 
		    		width: r * w,
		    		height: r * h,
		    		"z-index": 1000,
		    		border: "2px dashed white"
		    	});
		    };
		    var img = new Image();
		    img.onload = mark;
		    img.src = $img.attr("src");
	    });
    }
    wrapImages();		
});
(function($) {
  $(function(){
    initTooltips();
	  initCycleGallery();
	// $('a[rel*=facebox]').facebox();
    
    $('.aside-gallery').fadeGallery({
      slideElements:'ul.big-img > li',
      btnNext:'a.btn-next3',
      btnPrev:'a.btn-prev3',
      pagerLinks:'ul.pics a'
    });
    
    // $('div.aside-gallery').scrollGallery({
    //  sliderHolder: 'div.pics-wrap',
    //  btnPrev:'a.btn-prev3',
    //  btnNext:'a.btn-next3',
    //  step:true
    // });
  	
    // clearFormFields({
    //      clearInputs: true,
    //      clearTextareas: false,
    //      passwordFieldText: true,
    //      addClassFocus: "focus",
    //      filterClass: "default"
    //     });
  	
  	// hb //
  	
  	// Input placeholders
    // $('input[placeholder]').placeholder();
    $("input[placeholder]").ezpz_hint();
  	
    $("input[rel=password]").focus(function() {
			$(this).val("");
			var input = this;
			var input2 = input.cloneNode(false);
			input2.type = 'password';
			try {
				input.parentNode.replaceChild(input2,input);
				setTimeout(function() {
					input2.focus();
				}, 10);
			} catch(e) {}
		});
  	
  	// Star ratings hover
  	
  	$('.edit-ratings').find('li').bind('click', function(){
      $(this).parent().data('selected', $(this).index() + 1).end()
        .siblings().removeClass('active')
        .filter(':lt(' + ($(this).parent().data('selected') - 1) + ')')
        .addClass('active');
      $(this).addClass('active');
      $('input[name=rating]').val($(this).index() + 1);
      $(this).trigger("rate");
      return false;
  	});
  	
  	// Search autocomplete
  	var search_item_repr = function(item) {
  	  switch (item.collection) {
  	    case 'brands': return item['name-' + Room.language];
  	    case 'series': return item['name-' + Room.language] + ' - ' + item.brand;
  	    case 'products': return item['productname-' + Room.language] + ' - ' + item.brand;
  	  }
  	};
  	
  	$('input[name=q]').autocomplete({
  	  source: '/products/search?format=json',
  	  minLength: 2,
  	  select: function(event, ui) {
  	    document.location.href = ui.item['url-' + Room.language];  	      	  
				return false;
  	  }
  	}).data('autocomplete')._renderItem = function(ul, item) {
      ul.css('z-index', 5);      
      return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + search_item_repr(item) + "</a>" )
				.appendTo( ul );
  	};
  	
  	if ($('input#text3').length) {  	
    	$('input#text3').autocomplete({
    	  source: '/products/search?format=json',
    	  minLength: 2,
    	  select: function(event, ui) {
    	    document.location.href = ui.item['url-' + Room.language];  	      	  
  				return false;
    	  }
    	}).data('autocomplete')._renderItem = function(ul, item) {
        ul.css('z-index', 5);
        return $( "<li></li>" )
  				.data( "item.autocomplete", item )
  				.append( "<a>" + item.brand + " - " + item['productname-' + Room.language] + "</a>" )
  				.appendTo( ul );
    	};
  	}
  	
  	// Review votes
  	$('.review-vote').click(function(event){
  	  var self = $(this),
  	      url = self.attr('href');
  	  
  	  $.post(url, function(data) {
  	    self.parent().html(data);
  	  });
  	  
  	  event.preventDefault();
  	});
  	
  	// Alternatives
  	$('.relatedproducts').find('li > a').mouseover(function(){
  	  var self = $(this),
  	      offset = self.offset(),
  	      width = self.width();

  	  $('.product-hover:visible').hide();

  	  self.next()
  	    .css({
  	      top: offset.top,
  	      left: offset.left + width + 6
  	    })
  	    .show();
  	}).mouseout(function(){
  	  var self = $(this);
  	  self.next().data('fadeTimeout', setTimeout(function(){
  	    self.next().fadeOut();
  	  }, 400));
  	});
  	
  	$('.product-hover').mouseout(function(){
  	  var self = $(this);
  	  self.data('fadeTimeout', setTimeout(function() {
  	    self.fadeOut();
  	  }, 400));
  	}).mouseover(function(){
  	  clearTimeout($(this).data('fadeTimeout'));
  	});
  	
  	// More less
    $('.more-less-toggle').click(function(event){
      event.preventDefault();
      
      // Find the more-less element
      var $content = $(this).prev();
      
      if ($content.hasClass('more-less-shrinked')) {
        $content.removeClass('more-less-shrinked');
        $(this).text(_('Less...'));
      } else {
        $content.addClass('more-less-shrinked');
        $(this).text(_('More...'));
      }
    });
    
    $('.more-less').each(function(){
      if ($(this).height() > 80) {
        $(this).addClass('more-less-shrinked');
        $(this).next().show();
      } else {
        $(this).next().hide();
      }
    });
  	
  	// Facebook API integrations
    // Init FB API
    try {
    FB.init({appId: Room.fbAppId, 
             status: true, 
             cookie: true,
             xfbml: true});
    } catch (ee) {};
  
    $('#facebook-login-button, .facebook-login-button').click(function(e){
      FB.login(function(response){
        if (response.session) {
          $.post('/account/linked_with', {uid: response.session.uid},
            function(isLinked){
              if (isLinked) {              
                $.post('/account/do_login_with_fb', 
                      {uid: response.session.uid}, function(){
                        window.location.href = '';
                        return;
                });
              } else {
                FB.api('/me', function(response) {
                  $.post('/account/create_account', {
                    uid: response.id,
                    first_name: response.first_name,
                    last_name: response.last_name,
                    gender: response.gender
                  }, function(success){
                    if (success) {
                      window.location.href = '';
                    }
                  },
                  'json');
                });
              }
            },
          'json');
        }
      });
      e.preventDefault();
    });
    
    $('a[rel^="prettyPhoto"]').prettyPhoto({allow_resize: false, changepicturecallback: function (e) {
    	$("img#fullResImage").muaTag({nolist: true, published: true, tagContainer: "div.pp_content"});   	
    }});

    // front page date hint
    $('span.blue').hover(function(){
      var self = $(this),
          offset = self.offset(),
          width = self.width(),
          heigth = self.height();
      
      $('#frontpage-date-hint').css({
        top: offset.top + 10,
        left: offset.left + width
      }).fadeIn();
      
    }, function(){
      $('#frontpage-date-hint').fadeOut();
    });    
  }); 
    
  // tooltips function
  function initTooltips() {
  	var delay = 150;
  	var slideSize = 15;
  	var animSpeed = 200;
  	var hoverClass = 'hover-active';

  	$('ul.images > li').each(function(){
  		var t;
  		var _holder = $(this);
  		var _tooltip = _holder.find('.drop-block').hide().css({opacity:0,marginTop:slideSize});

  		_holder.hover(function(){
  			if(t) clearTimeout(t);
  			t = setTimeout(function(){
  				_holder.addClass(hoverClass);
  				_tooltip.show().css({marginTop:slideSize})
  				        .animate({opacity:1,marginTop:0},
  				                 {duration:animSpeed,complete:function(){
  					// on complete
  				}});
  			},delay)
  		},function(){
  			if(t) clearTimeout(t);
  			t = setTimeout(function(){
  				_holder.removeClass(hoverClass);
  				_tooltip.animate({opacity:0,marginTop:-slideSize},{duration:animSpeed,complete:function(){
  					_tooltip.hide();
  				}});
  			},delay)
  		});
  	});
  }

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

/*
  	$('div.inspirations').each(function(){
  		// gallery options
  		var _holder = $(this);
  		var _btnLeft = _holder.find('a.btn-prev');
  		var _btnRight = _holder.find('a.btn-next');
  		var _slidesHolder = _holder.find('div.gallery-holder');
  		var _slider = _slidesHolder.find('>ul');
  		var _slides = _slider.children();
  		var _slidesCount = _slides.length;
  		var _slideWidth = _slides.eq(0).outerWidth(true);
  		var _visibleCount = Math.round(_slidesHolder.width() / _slideWidth);
  		var _currentIndex = 0;
  		var _sumWidth = _slidesCount*_slideWidth;
  		var _animating = false;
  		var _timer;

  		// gallery init
  		_slider.append(_slides.clone()).append(_slides.clone());
  		_slider.css({marginLeft:-_sumWidth});

  		// gallery control
  		_btnLeft.click(function(){
  			prevSlide();
  			return false;
  		});
  		_btnRight.click(function(){
  			nextSlide();
  			return false;
  		});

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

  		function switchSlide() {
  			_animating = true;
  			_slider.animate({marginLeft:-_sumWidth-_currentIndex*_slideWidth},{duration:_speed, queue:false,complete:function(){
  				if(_currentIndex == _slidesCount || _currentIndex == -_slidesCount) {
  					_currentIndex = 0;
  					_slider.css({marginLeft:-_sumWidth});
  				}
  				_animating = false;
  			}});
  			autoSlide();
  		}
  		function autoSlide() {
  			if(!_autoSlide) return;
  			if(_timer) clearTimeout(_timer);
  			_timer = setTimeout(nextSlide,_switchTime);
  		}
  		autoSlide();
  	});
  	*/
  }
})(jQuery);

// scrolling gallery plugin
jQuery.fn.scrollGallery = function(_options){
  var $ = jQuery;
	var _options = jQuery.extend({
		sliderHolder: '>div',
		slider:'>ul',
		slides: '>li',
		pagerLinks:'div.pager a',
		btnPrev:'a.link-prev',
		btnNext:'a.link-next',
		activeClass:'active',
		disabledClass:'disabled',
		generatePagination:'div.pg-holder',
		curNum:'em.scur-num',
		allNum:'em.sall-num',
		circleSlide:true,
		pauseClass:'gallery-paused',
		pauseButton:'none',
		pauseOnHover:true,
		autoRotation:false,
		stopAfterClick:false,
		switchTime:5000,
		duration:650,
		easing:'swing',
		event:'click',
		splitCount:false,
		afterInit:false,
		vertical:false,
		step:false
	},_options);

	return this.each(function(){
		// gallery options
		var _this = jQuery(this);
		var _sliderHolder = jQuery(_options.sliderHolder, _this);
		var _slider = jQuery(_options.slider, _sliderHolder);
		var _slides = jQuery(_options.slides, _slider);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _generatePagination = jQuery(_options.generatePagination, _this);
		var _curNum = jQuery(_options.curNum, _this);
		var _allNum = jQuery(_options.allNum, _this);
		var _pauseButton = jQuery(_options.pauseButton, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _pauseClass = _options.pauseClass;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _disabledClass = _options.disabledClass;
		var _easing = _options.easing;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _step = _options.step;
		var _vertical = _options.vertical;
		var _circleSlide = _options.circleSlide;
		var _stopAfterClick = _options.stopAfterClick;
		var _afterInit = _options.afterInit;
		var _splitCount = _options.splitCount;

		// gallery init
		if(!_slides.length) return;

		if(_splitCount) {
			var curStep = 0;
			var newSlide = $('<slide>').addClass('split-slide');
			_slides.each(function(){
				newSlide.append(this);
				curStep++;
				if(curStep > _splitCount-1) {
					curStep = 0;
					_slider.append(newSlide);
					newSlide = $('<slide>').addClass('split-slide');
				}
			});
			if(curStep) _slider.append(newSlide);
			_slides = _slider.children();
		}

		var _currentStep = 0;
		var _sumWidth = 0;
		var _sumHeight = 0;
		var _hover = false;
		var _stepWidth;
		var _stepHeight;
		var _stepCount;
		var _offset;
		var _timer;

		_slides.each(function(){
			_sumWidth+=$(this).outerWidth(true);
			_sumHeight+=$(this).outerHeight(true);
		});

		// calculate gallery offset
		function recalcOffsets() {
			if(_vertical) {
				if(_step) {
					_stepHeight = _slides.eq(_currentStep).outerHeight(true);
					_stepCount = Math.ceil((_sumHeight-_sliderHolder.height())/_stepHeight)+1;
					_offset = -_stepHeight*_currentStep;
				} else {
					_stepHeight = _sliderHolder.height();
					_stepCount = Math.ceil(_sumHeight/_stepHeight);
					_offset = -_stepHeight*_currentStep;
					if(_offset < _stepHeight-_sumHeight) _offset = _stepHeight-_sumHeight;
				}
			} else {
				if(_step) {
					_stepWidth = _slides.eq(_currentStep).outerWidth(true)*_step;
					_stepCount = Math.ceil((_sumWidth-_sliderHolder.width())/_stepWidth)+1;
					_offset = -_stepWidth*_currentStep;
					if(_offset < _sliderHolder.width()-_sumWidth) _offset = _sliderHolder.width()-_sumWidth;
				} else {
					_stepWidth = _sliderHolder.width();
					_stepCount = Math.ceil(_sumWidth/_stepWidth);
					_offset = -_stepWidth*_currentStep;
					if(_offset < _stepWidth-_sumWidth) _offset = _stepWidth-_sumWidth;
				}
			}
		}

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				nextSlide();
				return false;
			});
		}
		if(_generatePagination.length) {
			_generatePagination.empty();
			recalcOffsets();
			var _list = $('<ul />');
			for(var i=0; i<_stepCount; i++) $('<li><a href="#">'+(i+1)+'</a></li>').appendTo(_list);
			_list.appendTo(_generatePagination);
			_pagerLinks = _list.children();
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentStep != _ind) {
						if(_stopAfterClick) stopAutoSlide();
						_currentStep = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// gallery animation
		function prevSlide() {
			recalcOffsets();
			if(_currentStep > 0) _currentStep--;
			else if(_circleSlide) _currentStep = _stepCount-1;
			switchSlide();
		}
		function nextSlide() {
			recalcOffsets();
			if(_currentStep < _stepCount-1) _currentStep++;
			else if(_circleSlide) _currentStep = 0;
			switchSlide();
		}
		function refreshStatus() {
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentStep).addClass(_activeClass);
			if(!_circleSlide) {
				_btnPrev.removeClass(_disabledClass);
				_btnNext.removeClass(_disabledClass);
				if(_currentStep == 0) _btnPrev.addClass(_disabledClass);
				if(_currentStep == _stepCount-1) _btnNext.addClass(_disabledClass);
			}
			if(_curNum.length) _curNum.text(_currentStep+1);
			if(_allNum.length) _allNum.text(_stepCount);
		}
		function switchSlide() {
			recalcOffsets();
			if(_vertical) _slider.animate({marginTop:_offset},{duration:_duration,queue:false,easing:_easing});
			else _slider.animate({marginLeft:_offset},{duration:_duration,queue:false,easing:_easing});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function stopAutoSlide() {
			if(_timer) clearTimeout(_timer);
			_autoRotation = false;
		}
		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();
			});
		}
		recalcOffsets();
		refreshStatus();
		autoSlide();

		// pause buttton
		if(_pauseButton.length) {
			_pauseButton.click(function(){
				if(_this.hasClass(_pauseClass)) {
					_this.removeClass(_pauseClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_this.addClass(_pauseClass);
					stopAutoSlide();
				}
				return false;
			});
		}

		if(_afterInit && typeof _afterInit === 'function') _afterInit(_this, _slides);
	});
}
// slideshow init
function initSlideShow() {
	jQuery('div.gallery').fadeGallery({
		slideElements:'div.slideset > div',
		pagerLinks:'div.pager a',
		btnNext:'a.next',
		btnPrev:'a.prev',
		btnPlayPause:'a.play-pause',
		pausedClass:'paused',
		playClass:'playing',
		activeClass:'active',
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		switchTime:3000,
		duration:500,
		event:'click'
	});
}

// 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',
		currentNum:false,
		allNum:false,
		startSlide:null,
		noCircle:false,
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		onChange:false,
		switchTime:3000,
		duration:650,
		event:'click'
	},_options);

	return this.each(function(){
		// gallery options
		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 _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		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;

		// gallery init
		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(_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) {
						_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;
			});
		}

		// gallery animation
		function prevSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex > 0) _currentIndex--;
			else {
				if(_noCycle) return;
				else _currentIndex = _slideCount-1;
			}
			switchSlide();
		}
		function nextSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex < _slideCount-1) _currentIndex++;
			else {
				if(_noCycle) return;
				else _currentIndex = 0;
			}
			switchSlide();
		}
		function refreshStatus() {
			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, _currentIndex);
			}
		}
		function switchSlide() {
			_slides.eq(_prevIndex).fadeOut(_duration);
			_slides.eq(_currentIndex).fadeIn(_duration);
			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();
	});
}

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 (jQuery(inputs[i]).hasClass(o.filterClass)) {
        continue;
      }
		  
			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";
	}
}



