if (window.innerWidth && window.innerWidth >= 480) {

(function(jQuery) {

	jQuery.fn.gallery = function(options) { return new Gallery(this.get(0), options); };

	

	function Gallery(context, options) { this.init(context, options); };

	

	Gallery.prototype = {

		options:{},

		init: function (context, options){

			this.options = jQuery.extend({

				duration: 700,									//duration of effect it 1000 = 1sec

				slideElement: 1,								//number of elements for a slide

				autoRotation: false,							//false = option is disabled; 1000 = 1sec

				effect: false,									//false = slide; true = fade

				listOfSlides: 'ul > li',						//elements galleries

				switcher: false,								//false = option is disabled; 'ul > li' = elements switcher

				disableBtn: false,								//false = option is disabled; 'hidden' = class adds an buttons "prev" and "next"

				nextBtn: 'a.link-next, a.btn-next, a.next',		//button "next"

				prevBtn: 'a.link-prev, a.btn-prev, a.prev',		//button "prev"

				circle: true,									//true = cyclic gallery; false = not cyclic gallery

				direction: false,								//false = horizontal; true = vertical

				event: 'click',									//event for the buttons and switcher

				IE: false										//forced off effect it "fade" in IE

			}, options || {});

			var _el = jQuery(context).find(this.options.listOfSlides);

			if (this.options.effect) this.list = _el;

			else this.list = _el.parent();

			this.switcher = jQuery(context).find(this.options.switcher);

			this.nextBtn = jQuery(context).find(this.options.nextBtn);

			this.prevBtn = jQuery(context).find(this.options.prevBtn);

			this.count = _el.index(_el.filter(':last'));

			

			if (this.options.switcher) this.active = this.switcher.index(this.switcher.filter('.active:eq(0)'));

			else this.active = _el.index(_el.filter('.active:eq(0)'));

			if (this.active < 0) this.active = 0;

			this.last = this.active;

			

			this.woh = _el.outerWidth(true);

			if (!this.options.direction) this.installDirections(this.list.parent().width());

			else {

				this.woh = _el.outerHeight(true);

				this.installDirections(this.list.parent().height());

			}

			

			if (!this.options.effect) {

				this.rew = this.count - this.wrapHolderW + 1;

				if (!this.options.direction) this.anim = '{marginLeft: -(this.woh * this.active)}';

				else this.anim = '{marginTop: -(this.woh * this.active)}';

				eval('this.list.css('+this.anim+')');

			}

			else {

				this.rew = this.count;

				this.list.css({opacity: 0}).removeClass('active').eq(this.active).addClass('active').css({opacity: 1}).css('opacity', 'auto');

				this.switcher.removeClass('active').eq(this.active).addClass('active');

			}

			

			this.initEvent(this, this.nextBtn, true);

			this.initEvent(this, this.prevBtn, false);

			if (this.options.disableBtn) this.initDisableBtn();

			if (this.options.autoRotation) this.runTimer(this);

			if (this.options.switcher) this.initEventSwitcher(this, this.switcher);

		},

		initDisableBtn: function(){

			this.prevBtn.removeClass('prev-'+this.options.disableBtn);

			this.nextBtn.removeClass('next-'+this.options.disableBtn);

			if (this.active == 0 || this.count+1 == this.wrapHolderW) this.prevBtn.addClass('prev-'+this.options.disableBtn);

			if (this.active == 0 && this.count == 1 || this.count+1 == this.wrapHolderW) this.nextBtn.addClass('next-'+this.options.disableBtn);

			if (this.active == this.rew) this.nextBtn.addClass('next-'+this.options.disableBtn);

		},

		installDirections: function(temp){

			this.wrapHolderW = Math.ceil(temp / this.woh);

			if (((this.wrapHolderW - 1) * this.woh + this.woh / 2) > temp) this.wrapHolderW--;

		},

		fadeElement: function(){

			if (jQuery.browser.msie && this.options.IE){

				this.list.eq(this.last).css({opacity:0});

				this.list.removeClass('active').eq(this.active).addClass('active').css({opacity:'auto'});

			}

			else{

				this.list.eq(this.last).animate({opacity:0}, {queue:false, duration: this.options.duration});

				this.list.removeClass('active').eq(this.active).addClass('active').animate({

					opacity:1

				}, {queue:false, duration: this.options.duration, complete: function(){

					jQuery(this).css('opacity','auto');

				}});

			}

			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');

			this.last = this.active;

		},

		scrollElement: function(){

			eval('this.list.animate('+this.anim+', {queue:false, duration: this.options.duration});');

			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active / this.options.slideElement).addClass('active');

		},

		runTimer: function(jQuerythis){

			if(jQuerythis._t) clearTimeout(jQuerythis._t);

			jQuerythis._t = setInterval(function(){

				jQuerythis.toPrepare(jQuerythis, true);

			}, this.options.autoRotation);

		},

		initEventSwitcher: function(jQuerythis, el){

			el.bind(jQuerythis.options.event, function(){

				jQuerythis.active = jQuerythis.switcher.index(jQuery(this)) * jQuerythis.options.slideElement;

				if(jQuerythis._t) clearTimeout(jQuerythis._t);

				if (jQuerythis.options.disableBtn) jQuerythis.initDisableBtn();

				if (!jQuerythis.options.effect) jQuerythis.scrollElement();

				else jQuerythis.fadeElement();

				if (jQuerythis.options.autoRotation) jQuerythis.runTimer(jQuerythis);

				return false;

			});

		},

		initEvent: function(jQuerythis, addEventEl, dir){

			addEventEl.bind(jQuerythis.options.event, function(){

				if(jQuerythis._t) clearTimeout(jQuerythis._t);

				jQuerythis.toPrepare(jQuerythis, dir);

				if (jQuerythis.options.autoRotation) jQuerythis.runTimer(jQuerythis);

				return false;

			});

		},

		toPrepare: function(jQuerythis, side){

			if ((jQuerythis.active == jQuerythis.rew) && jQuerythis.options.circle && side) jQuerythis.active = -jQuerythis.options.slideElement;

			if ((jQuerythis.active == 0) && jQuerythis.options.circle && !side) jQuerythis.active = jQuerythis.rew + jQuerythis.options.slideElement;

			for (var i = 0; i < jQuerythis.options.slideElement; i++){

				if (side) { if (jQuerythis.active + 1 <= jQuerythis.rew) jQuerythis.active++; }

				else { if (jQuerythis.active - 1 >= 0) jQuerythis.active--; }

			};

			if (this.options.disableBtn) this.initDisableBtn();

			if (!jQuerythis.options.effect) jQuerythis.scrollElement();

			else jQuerythis.fadeElement();

		},

		stop: function(){

			if (this._t) clearTimeout(this._t);

		},

		play: function(){

			if (this._t) clearTimeout(this._t);

			if (this.options.autoRotation) this.runTimer(this);

		}

	}

}(jQuery));



function initTabs(){

	jQuery('ul.tabset').each(function(){

		var btn_h = jQuery(this);

		var _btn = jQuery(this).find('a.tab');

		var _a = _btn.index(_btn.filter('.active:eq(0)'));

		if(_a == -1) _a = 0;

		_btn.parent().removeClass('active').eq(_a).addClass('active');

		_btn.each(function(_i){

			this._box = this.href.substr(this.href.indexOf("#") + 1);

			if(this._box){

				this._box = jQuery('#'+this._box);

				if(_i == _a) this._box.show();

				else this._box.hide();

			}

			this.onclick = function(){

				changeTab(_i);

				return false;

			}

		});

		function changeTab(_ind){

			if(_ind != _a){

				if(_btn.get(_a)._box) _btn.get(_a)._box.hide();

				if(_btn.get(_ind)._box) _btn.get(_ind)._box.show();

				_btn.eq(_a).parent().removeClass('active');

				_btn.eq(_ind).parent().addClass('active');

				_a = _ind;

			}

		}

	});

}



jQuery('document').ready(function(){

	jQuery('div.gallery').gallery({

		duration: 500,

		autoRotation: 5000,

		listOfSlides: 'div.holder > ul > li'

	});

	initTabs();

});

}
