/********************************
*                               *
* MooTools More added by Michael Goldberg  *
*                               *
********************************/

// MooTools: the javascript framework.
// Load this file's selection again by visiting: http://mootools.net/more/1b84f78e3952c74d74d3e2d3be481364 
// Or build this file again with packager using: packager build More/Fx.Scroll
/*
---

script: More.js

name: More

description: MooTools More

license: MIT-style license

authors:
  - Guillermo Rauch
  - Thomas Aylott
  - Scott Kyle
  - Arian Stolwijk
  - Tim Wienk
  - Christoph Pojer
  - Aaron Newton
  - Jacob Thornton

requires:
  - Core/MooTools

provides: [MooTools.More]

...
*/

MooTools.More = {
	'version': '1.4.0.1',
	'build': 'a4244edf2aa97ac8a196fc96082dd35af1abab87'
};


/*
---

script: Fx.Scroll.js

name: Fx.Scroll

description: Effect to smoothly scroll any element, including the window.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Fx
  - Core/Element.Event
  - Core/Element.Dimensions
  - /MooTools.More

provides: [Fx.Scroll]

...
*/

(function(){

Fx.Scroll = new Class({

	Extends: Fx,

	options: {
		offset: {x: 0, y: 0},
		wheelStops: true
	},

	initialize: function(element, options){
		this.element = this.subject = document.id(element);
		this.parent(options);

		if (typeOf(this.element) != 'element') this.element = document.id(this.element.getDocument().body);

		if (this.options.wheelStops){
			var stopper = this.element,
				cancel = this.cancel.pass(false, this);
			this.addEvent('start', function(){
				stopper.addEvent('mousewheel', cancel);
			}, true);
			this.addEvent('complete', function(){
				stopper.removeEvent('mousewheel', cancel);
			}, true);
		}
	},

	set: function(){
		var now = Array.flatten(arguments);
		if (Browser.firefox) now = [Math.round(now[0]), Math.round(now[1])]; // not needed anymore in newer firefox versions
		this.element.scrollTo(now[0], now[1]);
		return this;
	},

	compute: function(from, to, delta){
		return [0, 1].map(function(i){
			return Fx.compute(from[i], to[i], delta);
		});
	},

	start: function(x, y){
		if (!this.check(x, y)) return this;
		var scroll = this.element.getScroll();
		return this.parent([scroll.x, scroll.y], [x, y]);
	},

	calculateScroll: function(x, y){
		var element = this.element,
			scrollSize = element.getScrollSize(),
			scroll = element.getScroll(),
			size = element.getSize(),
			offset = this.options.offset,
			values = {x: x, y: y};

		for (var z in values){
			if (!values[z] && values[z] !== 0) values[z] = scroll[z];
			if (typeOf(values[z]) != 'number') values[z] = scrollSize[z] - size[z];
			values[z] += offset[z];
		}

		return [values.x, values.y];
	},

	toTop: function(){
		return this.start.apply(this, this.calculateScroll(false, 0));
	},

	toLeft: function(){
		return this.start.apply(this, this.calculateScroll(0, false));
	},

	toRight: function(){
		return this.start.apply(this, this.calculateScroll('right', false));
	},

	toBottom: function(){
		return this.start.apply(this, this.calculateScroll(false, 'bottom'));
	},

	toElement: function(el, axes){
		axes = axes ? Array.from(axes) : ['x', 'y'];
		var scroll = isBody(this.element) ? {x: 0, y: 0} : this.element.getScroll();
		var position = Object.map(document.id(el).getPosition(this.element), function(value, axis){
			return axes.contains(axis) ? value + scroll[axis] : false;
		});
		return this.start.apply(this, this.calculateScroll(position.x, position.y));
	},

	toElementEdge: function(el, axes, offset){
		axes = axes ? Array.from(axes) : ['x', 'y'];
		el = document.id(el);
		var to = {},
			position = el.getPosition(this.element),
			size = el.getSize(),
			scroll = this.element.getScroll(),
			containerSize = this.element.getSize(),
			edge = {
				x: position.x + size.x,
				y: position.y + size.y
			};

		['x', 'y'].each(function(axis){
			if (axes.contains(axis)){
				if (edge[axis] > scroll[axis] + containerSize[axis]) to[axis] = edge[axis] - containerSize[axis];
				if (position[axis] < scroll[axis]) to[axis] = position[axis];
			}
			if (to[axis] == null) to[axis] = scroll[axis];
			if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
		}, this);

		if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
		return this;
	},

	toElementCenter: function(el, axes, offset){
		axes = axes ? Array.from(axes) : ['x', 'y'];
		el = document.id(el);
		var to = {},
			position = el.getPosition(this.element),
			size = el.getSize(),
			scroll = this.element.getScroll(),
			containerSize = this.element.getSize();

		['x', 'y'].each(function(axis){
			if (axes.contains(axis)){
				to[axis] = position[axis] - (containerSize[axis] - size[axis]) / 2;
			}
			if (to[axis] == null) to[axis] = scroll[axis];
			if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
		}, this);

		if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
		return this;
	}

});



function isBody(element){
	return (/^(?:body|html)$/i).test(element.tagName);
}

})();




/********************************
*                               *
* End MooTools More
* Original engine.js below      *
*                               *
********************************/


window.addEvent('load', function(){
	$$('.gkTab').each(function(el,i){
		var module_id = el.getProperty('id');
		var $G = $Gavick['gktab-'+module_id]; 
		var tabs = el.getElements('.gkTabItem');
		var items = el.getElements('.gkTabs li');
		var animation = ($G['animation'] == 0) ? true : false;
		var currentTab = $G['active_tab'] - 1;
		var eventActivator = $G['activator'];
		var amount = tabs.length;
		var timer = false;
		var blank = false;
		var falsy_click = false;
		var animation_type = $G['animation_type'];
		var opacityFx = [];
		// prepare scroll effect
		var scrollFx = null; 
		if(animation_type == 'slider') {
			scrollFx = new Fx.Scroll(el.getElement(".gkTabContainer1"), {duration: $G['animation_speed'], wait: 'ignore', wheelStops:false, transition: $G['animation_function']});

			var sum = 0;
			
            el.getElement('.gkTabContainer0').setStyle('width', el.getElement('.gkTabContainer2 .active').getSize().x + 'px');
			
			tabs.each(function(tab, i){ 
				var size = el.getElement('.gkTabContainer2 .active').getSize().x;
				sum += size; 
				tab.setStyles({
					'position' : 'absolute',
					'left' : i * size + 'px',
					'width' : size + 'px'
				});
			});
			
			el.getElement('.gkTabContainer2').setStyle('width', sum + 'px');
		}
		// initial settings for opacity animation
		if(animation_type == 'opacity') {
			tabs.each(function(tab, i){ 
				tab.setStyles({
					'left' : 0,
					'position' : 'absolute',
					'opacity' : tab.hasClass('active') ? 1 : 0
				});
				opacityFx[i] = new Fx.Tween(tab, {property: 'opacity', duration: $G['animation_speed'], wait: 'ignore'});
			});
			// hide unnecessary tabs
			if(el.getElement('.gkTabContainer2').getElement('.nspMain')) {
				(function() {
					tabs.setStyle('display', 'none');
					tabs[0].setStyle('display', 'block');
				}).delay(2000); // delay for the NSP module
			}
		}
		// add events to tabs
		items.each(function(item, i){
			
			item.addEvent(eventActivator, function(){
				if(i != currentTab) {
					// specific operations for selected type of the animation
					if(animation_type == 'slider') {
						scrollFx.toElement(tabs[i]);
					} else {
						opacityFx[currentTab].start(0);
						opacityFx[i].start(1);
						// anim
						tabs[i].setStyle('display', 'block');
						//
						(function(){
							tabs.setStyle('display', 'none');
							tabs[i].setStyle('display', 'block');	
						}).delay($G['animation_speed']);
					}
					// common operations for both types of animation
					currentTab = i;
					if(!falsy_click) blank = true;
					else falsy_click = false;
					items.removeClass('active');
					item.addClass('active');
					if($G['cookie_save'] == 1) Cookie.write('gktab-' + module_id, i + 1, { domain: '/', duration: 256 });
				}
			});
		});
		// add events to buttons
		if(el.getElement('.gkTabButtonNext')) {
			el.getElement('.gkTabButtonNext').addEvent('click', function() {
				if(currentTab < amount - 1) items[currentTab + 1].fireEvent(eventActivator);	
				else items[0].fireEvent(eventActivator);
			});
			
			el.getElement('.gkTabButtonPrev').addEvent('click', function() {
				if(currentTab > 0) items[currentTab - 1].fireEvent(eventActivator);	
				else items[amount - 1].fireEvent(eventActivator);
			});
		}
		
		if($G["animation"] == 1){
			timer = (function(){
				if(!blank) {
					falsy_click = true;
					if(currentTab < amount - 1) items[currentTab + 1].fireEvent(eventActivator);	
					else items[0].fireEvent(eventActivator);
				} else {
					blank = false;
				}
			}).periodical($G["animation_interval"]);
		}
	});
});
