// MOTIVE ROTATOR
	$('#motive-rotator').each(function () {
		var $this = $(this),
			time = null,
			eq = 0,
			len = $('.item', $this).length - 1;
		$('.item', $this).hide().css('position', 'absolute');
		$('.item:eq(' + eq + ')', $this).show();
		$('.pager a:eq(' + eq + ')', $this).addClass('active');
		$('.motive-rotator-wrap', $this).css('overflow', 'hidden');

		var rote = function (eq) {
			if (eq != $('div.active', $this).index()) {
				$('div.item:eq(' + eq + ')', $this).show().css({ 'z-index': '2', 'opacity': '1' });
				$('div.active', $this)
					.animate({
						'opacity': '0'
					}, 700, function () {
						$(this).hide().removeClass('active').css('z-index', '1');
						$('div.item:eq(' + eq + ')', $this).addClass('active');
					});
				$('.pager a', $this).removeClass('active');
				$('.pager a:eq(' + eq + ')', $this).addClass('active');
			}
		}
		var timex = function () {
			time = setInterval(function () {
				if (eq == len) {
					eq = 0;
				}
				else {
					eq = eq + 1;
				}
				rote(eq);
			}, 6000);
		}
		timex();

		$('.pager a', $this).click(function () {
			eq = $(this).index();
			rote(eq);
			time = clearInterval(time);
			timex();
			return false;
		});
	});
	

	//reference SCROLL
	$('.reference-scroll .scroll, #category-list, #big-img').each(function () {
		var $this = $(this)
		var scroll = {
			el: $('ul', this)
            , elWidth: function () { return scroll.el.width(); }
            , elScroll: function () { return scroll.el[0].scrollWidth; }
            , elScrollL: function () { return scroll.el[0].scrollLeft; }
            , itemWidth: function () { return $('li', scroll.el).width(); }
            , coef: 1
            , hover: function (e) {
            	e = e || window.event;
            	if (e.type == 'mouseenter') {
            		$(e.target).addClass('hover');
            	}
            	else if (e.type == 'mouseleave') {
            		$(e.target).removeClass('hover');
            	}
            }
            , controlN: function () {
            	if (left + scroll.elWidth() >= scroll.elScroll()) {
            		$('.next', $this).fadeTo("fast", 0.33).addClass('disable').removeClass('hover').unbind();
            	}
            	if ($('.prev', $this).is('.disable') && left > 0) {
            		$('.prev', $this).fadeTo("fast", 1).removeClass('disable').click(scroll.prev).bind('mouseenter mouseleave', scroll.hover);
            	}
            }
            , controlP: function () {
            	if (left <= 0) {
            		$('.prev', $this).fadeTo("fast", 0.33).addClass('disable').removeClass('hover').unbind();
            	}
            	if ($('.next', $this).is('.disable') && left + scroll.elWidth() < scroll.elScroll()) {
            		$('.next', $this).fadeTo("fast", 1).removeClass('disable').click(scroll.next).bind('mouseenter mouseleave', scroll.hover);
            	}
            }
            , next: function () {
            	scroll.el.stop();
            	var length = scroll.itemWidth() * scroll.coef;
            	left = left + length;
            	scroll.controlN();
            	scroll.el.animate({
            		scrollLeft: left + 'px'
            	}, 300 * scroll.coef);
            }
            , prev: function () {
            	scroll.el.stop();
            	var length = scroll.itemWidth() * scroll.coef;
            	left = left - length;
            	scroll.controlP();
            	scroll.el.animate({
            		scrollLeft: left + 'px'
            	}, 300 * scroll.coef);
            }
		};
		if (scroll.elWidth() < scroll.elScroll()) {
			$this.append('<span class="prev"></span><span class="next"></span>');
			var left = scroll.elScrollL();
			scroll.el.css('overflow-x', 'hidden');
			scroll.controlN();
			scroll.controlP();
			$('.next:not(.disable)', this).click(scroll.next).bind('mouseenter mouseleave', scroll.hover);
			$('.prev:not(.disable)', this).click(scroll.prev).bind('mouseenter mouseleave', scroll.hover);
		}
		else {
			$('.reference-list-mini-scroll').addClass('no-scroll').removeClass('reference-list-mini-scroll');
		}
	});
