function initAbout(){
	$('#content').each(function(){		var hold = $(this);
		var logo = $('div.about-hold');		var link = logo.find('a.about-up');
		var article = logo.find('div.article:eq(1)');
		var box = logo.find('div.article:eq(0)');
		var flag = true;		
		box.addClass('hidden');
		article.hide();
		logo.mouseover(function(){
			box.removeClass('hidden');
			article.removeClass('hidden');
		});
		logo.mouseout(function(){
			if (flag){
				box.addClass('hidden');
				article.addClass('hidden');
			}
		});
		link.click(function(){
			box.hide();
			article.show();
			flag = false;
			return false;
		});
		article.click(function(){
			box.show();
			article.hide();
			flag = true;
		});	});
}
$(document).ready(function(){
	initAbout();
	$('.scrollable').customScrollV();
	$('a[rel = group1]').lightBox();
	$('div.painting-holder').gallery({
		duration: 700,
		autoRotation: 6000,
		effect: 'fade',
		listOfSlides: 'ul > li'
	});
});


(function($) {
	function Gallery(el, options) {
		this._hold = $(el);
		this.initOptions(options);
		this.initialize();
	}
	
	$.fn.gallery = function(options) {
		return new Gallery(this.get(0), options);
	};
	
	Gallery.prototype = {
		initOptions: function(_obj){
			this.options = {
				duration: 700,
				slideElement: 1,
				autoRotation: false,
				effect: false,
				listOfSlides: 'ul > li',
				switcher: false,
				disableBtn: false,
				nextBtn: 'a.link-next, a.btn-next, a.next',
				prevBtn: 'a.link-prev, a.btn-prev, a.prev',
				circle: true,
				direction: 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 (_this.options.effect) 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 (_timer) var _t;
			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;
			
			// 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');
			}
			
			// 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"
			function fadeElement(){
				_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.switcher) _switcher.removeClass('active').eq(_active).addClass('active');
				_last = _active;
			}
			
			// 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) _switcher.removeClass('active').eq(_active).addClass('active');
			}
			function toPrepare(){
				if ((_active == rew) && _this.options.circle) _active = -_this.options.slideElement;
				for (var i = 0; i < _this.options.slideElement; i++){
					_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();
			}
			function runTimer(){
				_t = setInterval(function(){
					toPrepare();
				}, _timer);
			}
			_next.click(function(){
				if(_t) clearTimeout(_t);
				if (_this.options.disableBtn &&(_count > _wrapHolderW)) _prev.removeClass(_this.options.disableBtn);
				toPrepare();
				if (_timer) runTimer();
				return false;
			});
			_prev.click(function(){
				if(_t) clearTimeout(_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 (_timer) runTimer();
				return false;
			});
			if (_this.options.switcher) _switcher.click(function(){
				_active = _switcher.index($(this));
				if(_t) clearTimeout(_t);
				if (!_this.options.effect) scrollEl();
				else fadeElement();
				if (_timer) runTimer();
				return false;
			});
			if (_timer) runTimer();
		},
		stop: function(){
			alert(1);
			if (_t) clearTimeout(_t);
		},
		play: function(){
			if (_t) clearTimeout(_t);
			if (_timer) runTimer();
		}
	}
}(jQuery));
/*--- mousewheel ---*/
var types = ['DOMMouseScroll', 'mousewheel'];
jQuery.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener ) for ( var i=types.length; i; ) this.addEventListener( types[--i], handler, false );
		else this.onmousewheel = handler;
	},
	teardown: function() {
		if ( this.removeEventListener ) for ( var i=types.length; i; ) this.removeEventListener( types[--i], handler, false );
		else this.onmousewheel = null;
	}
};
jQuery.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});
function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	event = jQuery.event.fix(event || window.event);
	event.type = "mousewheel";
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	args.unshift(event, delta);
	return jQuery.event.handle.apply(this, args);
}
/*--- custom scroll ---*/
jQuery.fn.customScrollV = function(_options){
	var _options = jQuery.extend({
		lineWidth: 33 /* this parameter sets the width of the scroll*/
	}, _options);
	return this.each(function(){
		var _box = jQuery(this);
		if (_box.is(':visible')) {
			if (_box.children('.scroll-content').length == 0) {
				var line_w = _options.lineWidth;
				/*--- init part ---*/
				var scrollBar = jQuery('<div class="scroll-bar"><div class="scroll-up"></div><div class="scroll-line"><div class="bg-b"></div><div class="scroll-slider"></div></div><div class="scroll-down"></div></div>');
				_box.wrapInner('<div class="scroll-content"><div class="scroll-hold"></div></div>').append(scrollBar);
				var scrollContent = _box.children('.scroll-content');
				var scrollSlider = scrollBar.find('.scroll-slider');
				var scrollSliderH = scrollSlider.parent();
				var scrollUp = scrollBar.find('.scroll-up');
				var scrollDown = scrollBar.find('.scroll-down');
				/*--- different variables ---*/
				var box_h = _box.height();
				var slider_h = 0;
				var slider_f = 0;
				var cont_h = scrollContent.height();
				var _f = false;
				var _f1 = false;
				var _f2 = true;
				var _t1, _t2, _s1, _s2;
				/*--- set styles ---*/
				_box.css({
					position: 'relative',
					overflow: 'hidden',
					height: box_h
				});
				scrollContent.css({
					position: 'absolute',
					top: 0,
					left: 0,
					zIndex: 1,
					height: 'auto'
				});
				scrollBar.css({
					position: 'absolute',
					top: 46+'%',
					right: 0,
					zIndex: 2,
					width: line_w,
					height: box_h,
					overflow: 'hidden'
				});
				scrollUp.css({
					width: line_w,
					height: line_w,
					overflow: 'hidden',
					cursor: 'pointer'
				});
				scrollDown.css({
					width: line_w,
					height: line_w,
					overflow: 'hidden',
					cursor: 'pointer'
				});
				slider_h = scrollBar.height();
				if (scrollUp.is(':visible')) 
					slider_h -= scrollUp.height();
				if (scrollDown.is(':visible')) 
					slider_h -= scrollDown.height();
				scrollSliderH.css({
					position: 'relative',
					width: line_w,
					height: slider_h,
					overflow: 'hidden',
					display:'none'
				});
				slider_h = 0;
				scrollSlider.css({
					position: 'absolute',
					top: 0,
					left: 0,
					width: line_w,
					height: slider_h,
					overflow: 'hidden',
					cursor: 'pointer'
				});
				box_h = _box.height();
				cont_h = scrollContent.height();
				if (box_h < cont_h) {
					_f = true;
					slider_h = Math.round(box_h / cont_h * scrollSliderH.height());
					if (slider_h < 5) 
						slider_h = 5;
					scrollSlider.height(slider_h);
					slider_h = scrollSlider.outerHeight();
					slider_f = (cont_h - box_h) / (scrollSliderH.height() - slider_h);
					_s1 = (scrollSliderH.height() - slider_h) / 15;
					_s2 = (scrollSliderH.height() - slider_h) / 3;
					scrollContent.children('.scroll-hold').css('padding-right', scrollSliderH.width());
				}
				else {
					_f = false;
					scrollBar.hide();
					scrollContent.css({
						width: _box.width(),
						top: 0,
						left: 0
					});
					scrollContent.children('.scroll-hold').css('padding-right', 0);
				}
				var _top = 0;
				/*--- element's events ---*/
				scrollUp.mousedown(function(){
					_top -= _s1;
					scrollCont();
					_t1 = setTimeout(function(){
						_t2 = setInterval(function(){
							_top -= 4 / slider_f;
							scrollCont();
						}, 20);
					}, 500);
					return false;
				}).mouseup(function(){
					if (_t1) 
						clearTimeout(_t1);
					if (_t2) 
						clearInterval(_t2);
				}).mouseleave(function(){
					if (_t1) 
						clearTimeout(_t1);
					if (_t2) 
						clearInterval(_t2);
				});
				scrollDown.mousedown(function(){
					_top += _s1;
					scrollCont();
					_t1 = setTimeout(function(){
						_t2 = setInterval(function(){
							_top += 4 / slider_f;
							scrollCont();
						}, 20);
					}, 500);
					return false;
				}).mouseup(function(){
					if (_t1) 
						clearTimeout(_t1);
					if (_t2) 
						clearInterval(_t2);
				}).mouseleave(function(){
					if (_t1) 
						clearTimeout(_t1);
					if (_t2) 
						clearInterval(_t2);
				});
				scrollSliderH.click(function(e){
					if (_f2) {
						_top = e.pageY - scrollSliderH.offset().top - scrollSlider.outerHeight() / 2;
						scrollCont();
					}
					else {
						_f2 = true;
					}
				});
				var t_y = 0;
				var tttt_f = (jQuery.browser.msie) ? (true) : (false);
				scrollSlider.mousedown(function(e){
					t_y = e.pageY - jQuery(this).position().top;
					_f1 = true;
					return false;
				}).mouseup(function(){
					_f1 = false;
				});
				jQuery('body').mousemove(function(e){
					if (_f1) {
						_f2 = false;
						_top = e.pageY - t_y;
						if (tttt_f) 
							document.selection.empty();
						scrollCont();
					}
				}).mouseup(function(){
					_f1 = false;
				});
				document.body.onselectstart = function(){
					if (_f1) 
						return false;
				}
				if (!_box.hasClass('not-scroll')) {
					_box.bind('mousewheel', function(event, delta){
						if (_f) {
							_top -= delta * _s1;
							scrollCont();
							if ((_top > 0) && (_top + slider_h < scrollSliderH.height())) 
								return false;
						}
					});
				}
				function scrollCont(){
					if (_top < 0) 
						_top = 0;
					else 
						if (_top + slider_h > scrollSliderH.height()) 
							_top = scrollSliderH.height() - slider_h;
					scrollSlider.css('top', _top);
					scrollContent.css('top', -_top * slider_f);
				}
				this.scrollResize = function(){
					box_h = _box.height();
					cont_h = scrollContent.height();
					if (box_h < cont_h) {
						_f = true;
						scrollBar.show();
						scrollBar.height(box_h);
						slider_h = scrollBar.height();
						
						if (scrollUp.is(':visible')) 
							slider_h -= scrollUp.height();
						if (scrollDown.is(':visible')) 
							slider_h -= scrollDown.height();
						scrollSliderH.height(slider_h);
						slider_h = Math.round(box_h / cont_h * scrollSliderH.height());
						if (slider_h < 5) 
							slider_h = 5;
						scrollSlider.height(slider_h);
						slider_h = scrollSlider.outerHeight();
						slider_f = (cont_h - box_h) / (scrollSliderH.height() - slider_h);
						if (cont_h + scrollContent.position().top < box_h) 
							scrollContent.css('top', -(cont_h - box_h));
						_top = -scrollContent.position().top / slider_f;
						scrollSlider.css('top', _top);
						_s1 = (scrollSliderH.height() - slider_h) / 15;
						_s2 = (scrollSliderH.height() - slider_h) / 3;
						scrollContent.children('.scroll-hold').css('padding-right', scrollSliderH.width());
					}
					else {
						_f = false;
						scrollBar.hide();
						scrollContent.css({
							top: 0,
							left: 0
						});
						scrollContent.children('.scroll-hold').css('padding-right', 0);
					}
				}
				
				setInterval(function(){
					if (_box.is(':visible') && cont_h != scrollContent.height()) 
						_box.get(0).scrollResize();
				}, 200);
				
			}
			else {
				this.scrollResize();
			}
		}
	});
};
