window.addEvent('domready', function() {
	disperseHome();
	$$('div.gallery').each(function(obj){
		new slideGallery(obj,{before: '.box-gallery'});
	});
	$$('div.case-content').each(function(obj){
		new slideGallery(obj,{opacity:true,duration:300});
	});
	dropHeight();
	dropDown();
	$$('a.lightbox-opener').each(function(obj,i){
		var lightbox = new initLightbox(obj);
	});
	initTabs();
	clearForms();
	openClose();
	$$('img').addEvent('contextmenu', function(e) { e.stop() });
	if($('prod-01-01')) {
		var foo = new Ui.Lightbox(null, { content: 'Jet Netherlands | Cardboard box - Exclusive' });
		$('prod-01-01').addEvent('click', foo.show);
	}
});
/* open close */
function openClose() {
	var activeClass = 'active';
	var duration = 500;

	$$('.contact-text').each(function(obj){
		var opener = obj.getElement('.opener');
		var slider = obj.getElement('.slide');
		var sliderHeight = slider.getSize().y;
		opener.addEvent('click',function(e){
			if(obj.hasClass(activeClass)) {
				obj.removeClass(activeClass)
				animateElement(slider,{height: 0},duration,'eval','VSA_handleResize()');
			} else {
				obj.addClass(activeClass)
				animateElement(slider,{height: sliderHeight},duration,'eval','VSA_handleResize()');
			}
			return false;
		});
		
		if(!obj.hasClass(activeClass)) slider.setStyles({height:0});
	});
}
/* clear forms js */
function clearForms(){
	$$('input[type=text],input[type=password],textarea').each(function(input){
		input.setProperty('flag', input.value);
		input.addEvent('focus',function(e){
			if (input.value == '' || input.value == input.getProperty('flag'))
			input.setProperty('value', '');
		});
		input.addEvent('blur',function(e){
			if (input.value == '') input.setProperty('value', input.getProperty('flag'))
		});
	});
}
/* initTabs */
function initTabs() {
	$$('ul.tabset').each(function(obj){
		var links = obj.getElements('a');
		var hover = document.createElement("li");
		var hover = $(hover);
		var duration = 300;
		var holder = $$('.tabs-holder')[0];
		var t;
		hover.addClass('hover');
		obj.grab(hover);
		obj.addEvent('mouseleave',function(e){
			if (t) clearTimeout(t);
			t = setTimeout(function(){
				links.each(function(objlink) {
					if(objlink.hasClass('active')){
						animateElement(hover,{left: objlink.getPosition(obj).x},duration,false,false,Fx.Transitions.easeOut);
					}
				});
			},100);
		});
		links.each(function(link) {
			var href = link.hash.replace('#','');
			var tab = $(href);
			var linkX = link.getPosition(obj).x;
			var tabHeight = tab.getSize().y;

			if(link.hasClass('active')) {
				tab.setStyles({display:'block'});
				hover.setStyles({left:linkX});
				holder.setStyles({height:tabHeight});
			}
			else tab.setStyles({display:'none'});
			link.addEvent('click',function(e){
				if (t) clearTimeout(t);
				t = setTimeout(function(){
					animateElement(hover,{left:linkX},duration,false,false,Fx.Transitions.easeOut);
				},10);
				
			});
			link.addEvent('click',function(e){
				links.each(function(objlink) {
					if (objlink.hasClass('active')){
						objlink.removeClass('active');
						var currTab = $(objlink.hash.replace('#',''));
						animateElement(currTab,{opacity: 0},duration,currTab,'setStyles({display:"none"})');
					}
				});
				link.addClass('active');
				animateElement(holder,{height: tabHeight},duration);
				tab.setStyles({display:'block',opacity:0});
				animateElement(tab,{opacity: 1},duration,'eval','VSA_handleResize()');
				return false;
			});
		});
	});
}
/* drop height */
function dropHeight(){
	$$('.navigation').each(function(nav){
		var maxHeight = 0;
		nav.getElements('>li').each(function(obj){
			if (obj.getSize().y > maxHeight) maxHeight = obj.getSize().y;
		});
		nav.getElements('>li').each(function(obj){
			obj.setStyles({height:maxHeight});
		});
	});
}
/* slide dropdown */
function dropDown(){
	$$('#header .navigation').each(function(nav){
		var navHeight = nav.getSize().y;
		var maxDropHeight = 0;
		var duration = 400;
		nav.getElements('ul').each(function(drop){
			if (drop.getSize().y > maxDropHeight) maxDropHeight = drop.getSize().y;
		});
		nav.setStyles({height:navHeight-maxDropHeight});
		nav.getElements('>li').each(function(obj){
			obj.addEvent('mouseenter',function(e){
				nav.addClass('opened');
				animateElement(nav,{height:navHeight},duration);
			});
			obj.addEvent('mouseleave',function(e){
				animateElement(nav,{height:navHeight-maxDropHeight},duration,nav,'removeClass("opened")');
			});
		});
	});
}
/* home layout */
function disperseHome(){
	$$('.home-content').each(function(obj){
		var gallery = obj.getElement('.box-gallery');
		var cont = obj.getElement('.box-gallery .shadow-in');
		var back = obj.getElement('.link-back');
		
		var galleryWidth = gallery.getSize().x;
		var galleryHeight = gallery.getSize().y;
		var galleryFullWidth = 730;
		var galleryFullHeight = 530;
		var duration = 300;
		//var smallGallery = obj.getElement('.small-gallery');
		var bigGallery = obj.getElement('.gallery'); //.setStyles({opacity:0});

		var parentCol = obj.getElement('.parent-col');
		var moreCol = obj.getElement('.more-col');
		
		var moreColTop = moreCol.getPosition(obj).y;
		var moreColLeft = moreCol.getPosition(obj).x;
		
		var parentColTop = parentCol.getPosition(obj).y + parentCol.getSize().y;
		var parentColLeft = parentCol.getPosition(obj).x;
		
		/*gallery.addEvent('click',function(e) {
			if (!gallery.hasClass('active')) {
				gallery.addClass('active');
				if (!moreCol.hasClass('absolute')) moreCol.addClass('absolute').setStyles({top:moreColTop,left:moreColLeft});
				
				if (smallGallery.anim) smallGallery.anim.cancel();
				smallGallery.anim = new Fx.Morph(smallGallery, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear
				});
				smallGallery.anim.start({opacity:0});
				
				if (moreCol.anim) moreCol.anim.cancel();
				moreCol.anim = new Fx.Morph(moreCol, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear,
					onComplete:function(){
						moreCol.setStyles({top:parentColTop,left:parentColLeft})
						if (cont.anim) cont.anim.cancel();
						cont.anim = new Fx.Morph(cont, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.easeOut,
							onComplete:function(){
								if (moreCol.anim) moreCol.anim.cancel();
								moreCol.anim = new Fx.Morph(moreCol, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear
								});
								moreCol.anim.start({opacity:1});
							}
						});
						cont.anim.start({width:galleryFullWidth,height:galleryFullHeight});
						if (bigGallery.anim) bigGallery.anim.cancel();
						bigGallery.anim = new Fx.Morph(bigGallery, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.linear
						});
						bigGallery.anim.start({opacity:1});
					}
				});
				moreCol.anim.start({opacity:0});
			}
			return false;
		});*/
		/*back.addEvent('click',function(e){
			if (gallery.hasClass('active')) {
				if (moreCol.anim) moreCol.anim.cancel();
				moreCol.anim = new Fx.Morph(moreCol, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear,
					onComplete:function(){
						moreCol.setStyles({top:moreColTop,left:moreColLeft});
						if (cont.anim) cont.anim.cancel();
						cont.anim = new Fx.Morph(cont, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.easeOut,
							onComplete:function(){
								if (moreCol.anim) moreCol.anim.cancel();
								moreCol.anim = new Fx.Morph(moreCol, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear,
									onComplete:function(){gallery.removeClass('active');}
								});
								moreCol.anim.start({opacity:1});
								if (smallGallery.anim) smallGallery.anim.cancel();
								smallGallery.anim = new Fx.Morph(smallGallery, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear
								});
								smallGallery.anim.start({opacity:1});
							}
						});
						cont.anim.start({width:galleryWidth,height:galleryHeight});
						if (bigGallery.anim) bigGallery.anim.cancel();
						bigGallery.anim = new Fx.Morph(bigGallery, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.linear
						});
						bigGallery.anim.start({opacity:0});
					}
				});
				moreCol.anim.start({opacity:0});
			}
			return false;
		});*/
	});
}
/*function disperseHome(){
	$$('.home-content').each(function(obj){
		var gallery = obj.getElement('.box-gallery');
		var cont = obj.getElement('.box-gallery .shadow-in');
		var back = obj.getElement('.link-back');
		var galleryWidth = gallery.getSize().x;
		var galleryHeight = gallery.getSize().y;
		var galleryFullWidth = 730;
		var galleryFullHeight = 530;
		var duration = 300;
		var smallGallery = obj.getElement('.small-gallery');
		var bigGallery = obj.getElement('.gallery').setStyles({opacity:0});

		var parentCol = obj.getElement('.parent-col');
		var moreCol = obj.getElement('.more-col');
		
		var moreColTop = moreCol.getPosition(obj).y;
		var moreColLeft = moreCol.getPosition(obj).x;
		
		var parentColTop = parentCol.getPosition(obj).y + parentCol.getSize().y;
		var parentColLeft = parentCol.getPosition(obj).x;
		gallery.addEvent('click',function(e){
			if (!gallery.hasClass('active')) {
				gallery.addClass('active');
				if (!moreCol.hasClass('absolute')) moreCol.addClass('absolute').setStyles({top:moreColTop,left:moreColLeft});
				
				if (smallGallery.anim) smallGallery.anim.cancel();
				smallGallery.anim = new Fx.Morph(smallGallery, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear
				});
				smallGallery.anim.start({opacity:0});
				
				if (moreCol.anim) moreCol.anim.cancel();
				moreCol.anim = new Fx.Morph(moreCol, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear,
					onComplete:function(){
						moreCol.setStyles({top:parentColTop,left:parentColLeft})
						if (cont.anim) cont.anim.cancel();
						cont.anim = new Fx.Morph(cont, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.easeOut,
							onComplete:function(){
								if (moreCol.anim) moreCol.anim.cancel();
								moreCol.anim = new Fx.Morph(moreCol, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear
								});
								moreCol.anim.start({opacity:1});
							}
						});
						cont.anim.start({width:galleryFullWidth,height:galleryFullHeight});
						if (bigGallery.anim) bigGallery.anim.cancel();
						bigGallery.anim = new Fx.Morph(bigGallery, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.linear
						});
						bigGallery.anim.start({opacity:1});
					}
				});
				moreCol.anim.start({opacity:0});
			}
			return false;
		});
		back.addEvent('click',function(e){
			if (gallery.hasClass('active')) {
				if (moreCol.anim) moreCol.anim.cancel();
				moreCol.anim = new Fx.Morph(moreCol, {
					link: 'ignore',
					duration: duration,
					transition: Fx.Transitions.linear,
					onComplete:function(){
						moreCol.setStyles({top:moreColTop,left:moreColLeft});
						if (cont.anim) cont.anim.cancel();
						cont.anim = new Fx.Morph(cont, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.easeOut,
							onComplete:function(){
								if (moreCol.anim) moreCol.anim.cancel();
								moreCol.anim = new Fx.Morph(moreCol, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear,
									onComplete:function(){gallery.removeClass('active');}
								});
								moreCol.anim.start({opacity:1});
								if (smallGallery.anim) smallGallery.anim.cancel();
								smallGallery.anim = new Fx.Morph(smallGallery, {
									link: 'ignore',
									duration: duration,
									transition: Fx.Transitions.linear
								});
								smallGallery.anim.start({opacity:1});
							}
						});
						cont.anim.start({width:galleryWidth,height:galleryHeight});
						if (bigGallery.anim) bigGallery.anim.cancel();
						bigGallery.anim = new Fx.Morph(bigGallery, {
							link: 'ignore',
							duration: duration,
							transition: Fx.Transitions.linear
						});
						bigGallery.anim.start({opacity:0});
					}
				});
				moreCol.anim.start({opacity:0});
			}
			return false;
		});
	});
}*/
function animateElement(el,param,duration,gal,galEval,easingParam){
	if (el.anim) el.anim.cancel();
	el.anim = new Fx.Morph(el, {
		link: 'ignore',
		duration: duration,
		transition: easingParam ? easingParam : Fx.Transitions.linear,
		onComplete:function(){
			if (gal) {
				if (gal == 'eval') setTimeout(function(){eval(galEval)},10);
				else setTimeout(function(){eval('gal.'+galEval)},10);
			}
		}
	});
	el.anim.start(param);
}

/* fade gallery class */
slideGallery = new Class({
	Implements : [Options, Events],
	options: {
		duration: 500,
		wrap:'.wrap',
		list: '.list',
		opacity:false,
		cloneEls: 2,
		listOfSlides: '.list > li',
		before: false,
		nextBtn: '.next',
		prevBtn: '.prev',
		event: 'click'
	},
	// create class
	initialize: function(element, options){
		var self = this;
		this.setOptions(options);
		this.element = element;
		this.wrap = this.element.getElement(this.options.wrap);
		this.list = this.element.getElement(this.options.list);
		this.els = element.getElements(this.options.listOfSlides);
		this.count = this.els.length;
		for (var i=0;i<this.count;i++){
			if (i<this.options.cloneEls) {
				this.list.grab($(this.els[i].clone()));
				this.list.grab($(this.els[this.count-i-1].clone()),'top');
			}
		}
		this.els = element.getElements(this.options.listOfSlides);
		if (this.options.nextBtn) this.nextBtn = this.element.getElement(this.options.nextBtn);
		if (this.options.prevBtn) this.prevBtn = this.element.getElement(this.options.prevBtn);
		this.active = this.options.cloneEls;
		this.calcParams();
		this.els.each(function(obj,ind){
			if (ind == self.active) {
				if (self.options.opacity) obj.setStyles({opacity:1});
			}
			else {
				if (self.options.opacity) obj.setStyles({opacity:0});
			}
		});
		if (this.options.nextBtn) this.initEvent(this, this.nextBtn,true);
		if (this.options.prevBtn) this.initEvent(this, this.prevBtn,false);
	},
	calcParams: function(){
		var self = this;
		this.mas = [];
		this.sum = 0;
		this.max = this.count-1;
		this.width = 0;
		this.els.each(function(obj){self.mas.push(self.width);self.width += obj.getSize().x;self.sum+= obj.getSize().x;});
		this.finish = this.sum-this.wrap.getSize().x;
		for (var i=0;i<this.count;i++){
			if (this.mas[i]>=this.finish) {
				this.max = i;
				break;
			}
		}
		this.list.setStyles({marginLeft: -(this.mas[this.active])});
	},
	scrollElement: function(self,f){
		if (this.animate) this.animate.cancel();
		this.animate = new Fx.Morph(this.list, {
			link: 'ignore',
			duration: this.options.duration,
			transition: Fx.Transitions.linear
		});
		this.animate.start({marginLeft: f ? -this.finish : -(this.mas[this.active])});
		this.els.each(function(obj,ind){
			if (ind == self.active) {
				if (self.options.opacity) {
					if (obj.animate) obj.animate.cancel();
					obj.animate = new Fx.Morph(obj, {
						link: 'ignore',
						duration: self.options.duration,
						transition: Fx.Transitions.linear
					});
					obj.animate.start({opacity:1});
				}
			}
			else {
				if (self.options.opacity) {
					if (obj.animate) obj.animate.cancel();
					obj.animate = new Fx.Morph(obj, {
						link: 'ignore',
						duration: self.options.duration,
						transition: Fx.Transitions.linear
					});
					obj.animate.start({opacity:0});
				}
			}
		});
	},
	initEvent: function($this, addEventEl, dir){
		addEventEl.addEvent($this.options.event, function(){
			if (!$this.options.before || ($$($this.options.before)[0] && $$($this.options.before)[0].hasClass('active'))){
				if (dir) $this.nextStep();
				else $this.prevStep();
				return false;
			}
		});
	},
	nextStep:function(){
		var self = this;
		var f = false;
		this.active++;
		if (this.active > this.count+this.options.cloneEls) {
			this.list.setStyles({marginLeft:-this.mas[this.options.cloneEls]});
			this.active = this.options.cloneEls+1;
			if (self.options.opacity){
				this.els.each(function(obj,ind){
					if (ind == self.active-1) obj.setStyles({opacity:1});
					else obj.setStyles({opacity:0});
				});
			}
		}
		this.scrollElement(this,f);
	},
	prevStep: function(){
		var self = this;
		var f = false;
		this.active--;
		if (this.active < this.options.cloneEls-1) {
			this.list.setStyles({marginLeft:-this.mas[this.count+this.options.cloneEls-1]});
			this.active = this.count+this.options.cloneEls-2;
			if (self.options.opacity){
				this.els.each(function(obj,ind){
					if (ind == self.active+1) obj.setStyles({opacity:1});
					else obj.setStyles({opacity:0});
				});
			}
		}
		this.scrollElement(this,f);
	}
});
/* lightbox plugin */
var initLightbox = new Class({
	options: {
		duration: 300,
		closer:'.close',
		event: 'click',
		opacity:0.7,
		faderBg:'#000',
		holder: 'wrapper',
		fader:'fader'
	},
	// create class
	initialize: function(element, options){
		var r  = document.createElement("div");
		this.setOptions(options);
		this.opener = element;
		this.popup = $(this.opener.getProperty('href'));
		if (this.popup) this.getElements();
		this.initEvent(this, this.opener,true);
		if (this.closer) this.initEvent(this, this.closer);
		if (this.fader) this.initEvent(this, this.fader);

	},
	initFader: function(){
		if ($(this.options.fader)) {
			this.fader = $(this.options.fader);
		} else {
			this.fader = document.createElement("div");
			this.fader.id = this.options.fader;
			$$('body')[0].grab(this.fader);
			this.fader = $(this.options.fader);
			this.fader.setStyles({
				width:'100%',
				height:'100%',
				opacity:this.options.opacity,
				backgroundColor:this.options.faderBg,
				display:'none',
				position:'fixed',
				left:0,
				top:0,
				zIndex:998
			});
		}
	},
	getElements: function(){
		this.holder = $(this.options.holder);
		this.initFader();
		this.closer = this.popup.getElement(this.options.closer);
		this.path = this.opener.getProperty('title');
	},
	initEvent: function($this, addEventEl,flag){
		addEventEl.addEvent($this.options.event, function(){
			if (flag) $this.openPopup($this);
			else $this.closePopup($this);
			return false;
		});
	},
	openPopup: function($this){
		this.popup.setStyles({opacity:0,display:'block'});
		this.fader.setStyles({opacity:0,display:'block'});
		var fade = new Fx.Morph(this.fader, {
			link: 'ignore',
			duration: this.options.duration,
			transition: Fx.Transitions.linear,
			onComplete:function(){
				var anim = new Fx.Morph($this.popup, {
					link: 'ignore',
					duration: $this.options.duration,
					transition: Fx.Transitions.linear
				});
				anim.start({opacity: 1});
			}
		});
		fade.start({opacity: this.options.opacity});
	},
	closePopup: function($this){
		var anim = new Fx.Morph(this.popup, {
			link: 'ignore',
			duration: this.options.duration,
			transition: Fx.Transitions.linear,
			onComplete:function(){
				$this.popup.setStyles({display:'none'});
				var fade = new Fx.Morph($this.fader, {
					link: 'ignore',
					duration: $this.options.duration,
					transition: Fx.Transitions.linear,
					onComplete:function(){
						$this.fader.setStyles({display:'none'});
					}
				});
				fade.start({opacity: 0});
			}
		});
		anim.start({opacity: 0});
	},
	// add options and events
	Implements : [Options, Events]
});
var VSA_scrollAreas = new Array();
var VSA_default_imagesPath = "images";
var VSA_default_btnUpImage = "button-up.gif";
var VSA_default_btnDownImage = "button-down.gif";
var VSA_default_scrollStep = 5;
var VSA_default_wheelSensitivity = 10;
var VSA_default_scrollbarPosition = 'right';//'left','right','inline';
var VSA_default_scrollButtonHeight = 0;
var VSA_default_scrollbarWidth = 11;
var VSA_resizeTimer = 2000;
var VSA_touchFlag = isTouchDevice(); // true/false - move scroll with scrollable body

if (window.addEventListener) window.addEventListener("load", VSA_initScrollbars, false);
else if (window.attachEvent) window.attachEvent("onload", VSA_initScrollbars);

function VSA_initScrollbars() {
	if(!document.body.children) return;
	var scrollElements = VSA_getElements("vscrollable", "DIV", document, "class");
	for (var i=0; i<scrollElements.length; i++)
	{
		VSA_scrollAreas[i] = new VScrollArea(i, scrollElements[i]);
	}
}

function isTouchDevice() {
	try {
		document.createEvent("TouchEvent");
		return true;
	} catch (e) {
		return false;
	}
}

function touchHandler(event) {
	var touches = event.changedTouches, first = touches[0], type = "";
	switch(event.type) {
		case "touchstart": type = "mousedown"; break;
		case "touchmove":  type = "mousemove"; break;
		case "touchend":   type = "mouseup"; break;
		default: return;
	}
	var simulatedEvent = document.createEvent("MouseEvent");
	simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0/*left*/, null);
	first.target.dispatchEvent(simulatedEvent);
	event.preventDefault();
}

function VScrollArea(index, elem) //constructor
{
	this.index = index;
	this.element = elem;

	var attr = this.element.getAttribute("imagesPath");
	this.imagesPath = attr ? attr : VSA_default_imagesPath;

	attr = this.element.getAttribute("btnUpImage");
	this.btnUpImage = attr ? attr : VSA_default_btnUpImage;

	attr = this.element.getAttribute("btnDownImage");
	this.btnDownImage = attr ? attr : VSA_default_btnDownImage;

	attr = Number(this.element.getAttribute("scrollStep"));
	this.scrollStep = attr ? attr : VSA_default_scrollStep;

	attr = Number(this.element.getAttribute("wheelSensitivity"));
	this.wheelSensitivity = attr ? attr : VSA_default_wheelSensitivity;

	attr = this.element.getAttribute("scrollbarPosition");
	this.scrollbarPosition = attr ? attr : VSA_default_scrollbarPosition;
	
	attr = this.element.getAttribute("scrollButtonHeight");
	this.scrollButtonHeight = attr ? attr : VSA_default_scrollButtonHeight;

	attr = this.element.getAttribute("scrollbarWidth");
	this.scrollbarWidth = attr ? attr : VSA_default_scrollbarWidth;

	this.scrolling = false;

	this.iOffsetY = 0;
	this.scrollHeight = 0;
	this.scrollContent = null;
	this.scrollbar = null;
	this.scrollup = null;
	this.scrolldown = null;
	this.scrollslider = null;
	this.scroll = null;
	this.enableScrollbar = false;
	this.scrollFactor = 1;
	this.scrollingLimit = 0;
	this.topPosition = 0;

	//functions declaration
	this.init = VSA_init;
	this.scrollUp = VSA_scrollUp;
	this.scrollDown = VSA_scrollDown;
	this.createScrollBar = VSA_createScrollBar;
	this.scrollIt = VSA_scrollIt;

	this.init();
}

function VSA_init() {
	this.scrollContent = document.createElement("DIV");
	this.scrollContent.style.position = "absolute";
	this.scrollContent.style.overflow = "hidden";
	this.scrollContent.style.width = this.element.offsetWidth + "px";
	this.scrollContent.style.height = this.element.offsetHeight + "px";

	while(this.element.childNodes.length) this.scrollContent.appendChild(this.element.childNodes[0]);

	this.element.style.overflow = "hidden";
	this.element.style.display = "block";
	this.element.style.visibility = "visible";
	this.element.style.position = "relative";
	this.element.appendChild(this.scrollContent);

	this.scrollContent.className = 'scroll-content';

	this.element.index = this.index;
	this.element.over = false;
	
	var _this = this;

	if(document.all && !window.opera) {
		this.element.onmouseenter = function(){_this.element.over = true;};
		this.element.onmouseleave = function(){_this.element.over = false;}
	} else {
		this.element.onmouseover = function(){_this.element.over = true;};
		this.element.onmouseout = function(){_this.element.over = false;}
	}

	if (document.all)
	{
		this.element.onscroll = VSA_handleOnScroll;
		this.element.onresize = VSA_handleResize;
	}
	else
	{
		window.onresize = VSA_handleResize;
	}
	
	this.createScrollBar();
	
	if (window.addEventListener) {
		/* DOMMouseScroll is for mozilla. */
		this.element.addEventListener('DOMMouseScroll', VSA_handleMouseWheel, false);
	}
	/* IE/Opera. */
	this.element.onmousewheel = document.onmousewheel = VSA_handleMouseWheel;

	// move content by touch
	if(VSA_touchFlag) {
		_this.scrollContent.onmousedown = function(e) {
			var startY = e.pageY-getRealTop(_this.scrollContent);
			var origTop = _this.scrollContent.scrollTop;
			_this.scrollContent.onmousemove = function(e) {
				var moveY = e.pageY-getRealTop(_this.scrollContent);
				var iNewY = origTop-(moveY-startY);
				if(iNewY < 0) iNewY = 0;
				if(iNewY > _this.scrollContent.scrollHeight) iNewY = _this.scrollContent.scrollHeight;
				_this.scrollContent.scrollTop = iNewY;
				_this.scrollslider.style.top =  1 / _this.scrollFactor * Math.abs(_this.scrollContent.scrollTop) + _this.scrollButtonHeight + "px";
			}
		}
		_this.scrollContent.onmouseup = function(e) {
			_this.scrollContent.onmousemove = null;
		}
		this.scrollContent.addEventListener("touchstart", touchHandler, true);
		this.scrollContent.addEventListener("touchmove", touchHandler, true);
		this.scrollContent.addEventListener("touchend", touchHandler, true);
	}
}

function VSA_createScrollBar()
{
	if (this.scrollbar != null)
	{
		this.scrollPos = $(this.scrollslider).getStyle('top');
		this.element.removeChild(this.scrollbar);
		this.scrollbar = null;
	}
	
	if (this.scrollContent.scrollHeight <= this.scrollContent.offsetHeight)
		this.enableScrollbar = false;
	else if (this.element.offsetHeight > 2*this.scrollButtonHeight)
		this.enableScrollbar = true;
	else
		this.enableScrollbar = false;

	if (this.scrollContent.scrollHeight - Math.abs(this.scrollContent.scrollTop) < this.element.offsetHeight)
		this.scrollContent.style.top = 0;

	if (this.enableScrollbar)
	{
		this.scrollbar = document.createElement("DIV");
		this.element.appendChild(this.scrollbar);
		this.scrollbar.style.position = "absolute";
		this.scrollbar.style.top = "0px";
		this.scrollbar.style.height = this.element.offsetHeight+"px";
		this.scrollbar.style.width = this.scrollbarWidth + "px";

		this.scrollbar.className = 'vscroll-bar';

		if(this.scrollbarWidth != this.scrollbar.offsetWidth)
		{
			this.scrollbarWidth = this.scrollbar.offsetHeight;
		}
		
		this.scrollbarWidth = this.scrollbar.offsetWidth;

		if(this.scrollbarPosition == 'left')
		{
			this.scrollContent.style.left = this.scrollbarWidth + 5 + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}
		else if(this.scrollbarPosition == 'right')
		{
			this.scrollbar.style.left = this.element.offsetWidth - this.scrollbarWidth  + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}

		//create scroll up button
		this.scrollup = document.createElement("DIV");
		this.scrollup.index = this.index;
		this.scrollup.onmousedown = VSA_handleBtnUpMouseDown;
		this.scrollup.onmouseup = VSA_handleBtnUpMouseUp;
		this.scrollup.onmouseout = VSA_handleBtnUpMouseOut;
		
		if(VSA_touchFlag) {
			this.scrollup.addEventListener("touchstart", touchHandler, true);
			this.scrollup.addEventListener("touchend", touchHandler, true);
		}
		
		this.scrollup.style.position = "absolute";
		this.scrollup.style.top = "0px";
		this.scrollup.style.left = "0px";
		this.scrollup.style.height = this.scrollButtonHeight + "px";
		this.scrollup.style.width = this.scrollbarWidth + "px";
		
		this.scrollup.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnUpImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrollup);

		this.scrollup.className = 'vscroll-up';

		if(this.scrollButtonHeight != this.scrollup.offsetHeight)
		{
			this.scrollButtonHeight = this.scrollup.offsetHeight;
		}
		
		//create scroll down button
		this.scrolldown = document.createElement("DIV");
		this.scrolldown.index = this.index;
		this.scrolldown.onmousedown = VSA_handleBtnDownMouseDown;
		this.scrolldown.onmouseup = VSA_handleBtnDownMouseUp;
		this.scrolldown.onmouseout = VSA_handleBtnDownMouseOut;
		
		if(VSA_touchFlag) {
			this.scrolldown.addEventListener("touchstart", touchHandler, true);
			this.scrolldown.addEventListener("touchend", touchHandler, true);
		}
		
		this.scrolldown.style.position = "absolute";
		this.scrolldown.style.left = "0px";
		this.scrolldown.style.top =  this.scrollbar.offsetHeight - this.scrollButtonHeight + "px";
		this.scrolldown.style.width = this.scrollbarWidth + "px";
		this.scrolldown.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnDownImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrolldown);

		this.scrolldown.className = 'vscroll-down';

		//create scroll
		this.scroll = document.createElement("DIV");
		this.scroll.index = this.index;
		this.scroll.style.position = "absolute";
		this.scroll.style.zIndex = 0;
		this.scroll.style.textAlign = "center";
		this.scroll.style.top = this.scrollButtonHeight + "px";
		this.scroll.style.left = "0px";
		this.scroll.style.width = this.scrollbarWidth + "px";
		
		var h = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight;
		this.scroll.style.height = ((h > 0) ? h : 0) + "px";
		
		this.scroll.innerHTML = '';
		this.scroll.onclick = VSA_handleScrollbarClick;
		this.scrollbar.appendChild(this.scroll);
		this.scroll.style.overflow = "hidden";

		this.scroll.className = "vscroll-line";

		//create slider
		this.scrollslider = document.createElement("DIV");
		this.scrollslider.index = this.index;
		this.scrollslider.style.position = "absolute";
		this.scrollslider.style.zIndex = 100;
		this.scrollslider.style.textAlign = "center";
		this.scrollslider.innerHTML = '<div class="vsub-slider" id="vscrollslider' + this.index + '" style="padding:0;margin:0;"><div class="scroll-bar-top"></div><div class="scroll-bar-bottom"></div></div>';
		this.scrollbar.appendChild(this.scrollslider);
		
		this.subscrollslider = document.getElementById("vscrollslider"+this.index);
		this.subscrollsliderH = Math.round((this.scrollContent.offsetHeight/this.scrollContent.scrollHeight)*(this.scrollbar.offsetHeight - 2*this.scrollButtonHeight)) - 5;
		this.subscrollslider.style.height = this.subscrollsliderH + "px";
		
		this.scrollslider.className = "vscroll-slider";
		
		this.scrollHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight;
		this.scrollFactor = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight)/this.scrollHeight;
		this.topPosition = getRealTop(this.scrollbar) + this.scrollButtonHeight;
		/* this.scrollbarHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight; */
		this.scrollslider.style.top = this.subscrollsliderH + this.scrollPos < this.scroll.offsetHeight ? this.scrollPos : this.scrollButtonHeight + "px";
		this.scrollslider.style.left = "0px";
		this.scrollslider.style.width = "100%";
		this.scrollslider.onmousedown = VSA_handleSliderMouseDown;
		if(VSA_touchFlag) {
			this.scrollslider.addEventListener("touchstart", touchHandler, true);
		}
		if (document.all)
			this.scrollslider.onmouseup = VSA_handleSliderMouseUp;
	}
	else
		this.scrollContent.style.width = this.element.offsetWidth + "px";
}

function VSA_handleBtnUpMouseDown()
{
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollUp();
}

function VSA_handleBtnUpMouseUp()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnUpMouseOut()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseDown()
{
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollDown();
}

function VSA_handleBtnDownMouseUp()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseOut()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_scrollIt()
{
	this.scrollContent.scrollTop = this.scrollFactor * ((this.scrollslider.offsetTop + this.scrollslider.offsetHeight/2) - this.scrollButtonHeight - this.scrollslider.offsetHeight/2);
}

function VSA_scrollUp()
{
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;
	if ( this.scrollContent.scrollTop - this.scrollStep > 0)
	{
		this.scrollContent.scrollTop -= this.scrollStep;
		this.scrollslider.style.top = 1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";
	}
	else
	{
		this.scrollContent.scrollTop = "0";
		this.scrollslider.style.top = this.scrollButtonHeight + "px";
		return;
	}
	setTimeout("VSA_Ext_scrollUp(" + this.index + ")", 30);
}

function VSA_Ext_scrollUp(index)
{
	VSA_scrollAreas[index].scrollUp();
}

function VSA_scrollDown()
{
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;


	this.scrollContent.scrollTop += this.scrollStep;
	this.scrollslider.style.top =  1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";

	if (this.scrollContent.scrollTop >= (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight))
	{
		this.scrollContent.scrollTop = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight);
		this.scrollslider.style.top = this.scrollbar.offsetHeight - this.scrollButtonHeight - this.scrollslider.offsetHeight + "px";
		return;
	}

	setTimeout("VSA_Ext_scrollDown(" + this.index + ")", 30);
}

function VSA_Ext_scrollDown(index)
{
	VSA_scrollAreas[index].scrollDown();
}

function VSA_handleMouseMove(evt)
{
	var sa = VSA_scrollAreas[((document.all && !window.opera) ? this.index : document.documentElement.scrollAreaIndex)];
	var posy = 0;
	if (!evt) var evt = window.event;
	
	if (evt.pageY)
		posy = evt.pageY;
	else if (evt.clientY)
		posy = evt.clientY;
			
		if (document.all && !window.opera)
		{
			if(!document.addEventListener) {
				posy += document.documentElement.scrollTop;
			}
		}

	var iNewY = posy - sa.iOffsetY - getRealTop(sa.scrollbar) - sa.scrollButtonHeight;
		iNewY += sa.scrollButtonHeight;
		
	if (iNewY < sa.scrollButtonHeight)
		iNewY = sa.scrollButtonHeight;
	if (iNewY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight)
		iNewY = (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight;

	sa.scrollslider.style.top = iNewY + "px";

	sa.scrollIt();
}

function VSA_handleSliderMouseDown(evt)
{
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onselectstart = function() { return false; }
		document.onmousedown = function() { return false; }
	}

	var sa = VSA_scrollAreas[this.index];
	if (document.all && !window.opera)
	{
		sa.scrollslider.setCapture()
		sa.iOffsetY = event.offsetY;
		sa.scrollslider.onmousemove = VSA_handleMouseMove;
		if(VSA_touchFlag) {
			sa.scrollslider.addEventListener("touchmove", touchHandler, true);
		}
	}
	else
	{
		if(window.opera)
		{
			sa.iOffsetY = event.offsetY;
		}
		else
		{
			sa.iOffsetY = evt.layerY;
		}
		document.documentElement.scrollAreaIndex = sa.index;
		document.documentElement.addEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.addEventListener("mouseup", VSA_handleSliderMouseUp, true);
		if(VSA_touchFlag) {
			document.documentElement.addEventListener("touchmove", touchHandler, true);
			document.documentElement.addEventListener("touchend", touchHandler, true);
		}
	}
	return false;
}

function VSA_handleSliderMouseUp()
{
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onmousedown = null;
		document.onselectstart = null;
	}

	if (document.all && !window.opera)
	{
		var sa = VSA_scrollAreas[this.index];
		sa.scrollslider.onmousemove = null;
		sa.scrollslider.releaseCapture();
		sa.scrollIt();
	}
	else
	{
		var sa = VSA_scrollAreas[document.documentElement.scrollAreaIndex];
		document.documentElement.removeEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.removeEventListener("mouseup", VSA_handleSliderMouseUp, true);
		if(VSA_touchFlag) {
			document.documentElement.removeEventListener("touchmove", touchHandler, true);
			document.documentElement.removeEventListener("touchend", touchHandler, true);
		}
		sa.scrollIt();
	}
	return false;
}

function VSA_handleResize()
{
	if (VSA_resizeTimer)
	{
		clearTimeout(VSA_resizeTimer);
		VSA_resizeTimer = 0;
	}
	VSA_resizeTimer = setTimeout("VSA_performResizeEvent()", 100);
}

function VSA_performResizeEvent()
{
	for (var i=0; i<VSA_scrollAreas.length; i++)
		VSA_scrollAreas[i].createScrollBar();
}
function VSA_handleMouseWheel(event){
	if (this.index != null) {
		var sa = VSA_scrollAreas[this.index];
		if (sa.scrollbar == null) return;
		sa.scrolling = true;
		sa.scrollingLimit = sa.wheelSensitivity;

		var delta = 0;
		if (!event) /* For IE. */
			event = window.event;
		if (event.wheelDelta) { /* IE/Opera. */
			delta = event.wheelDelta/120;
			/*if (window.opera) delta = -delta;*/
		} else if (event.detail) { /* Mozilla case. */
			delta = -event.detail/3;
		}

		if (delta && sa.element.over) {
			if (delta > 0) {
				sa.scrollUp();
			} else {
				sa.scrollDown();
			}
			if (event.preventDefault) {
				event.preventDefault();
			}
			event.returnValue = false;
		}
	}
}

function VSA_handleSelectStart()
{
	event.returnValue = false;
}

function VSA_handleScrollbarClick(evt)
{
	var sa = VSA_scrollAreas[this.index];
	var offsetY = (document.all ? event.offsetY : evt.layerY);

	if (offsetY < (sa.scrollButtonHeight + sa.scrollslider.offsetHeight/2))
		sa.scrollslider.style.top = sa.scrollButtonHeight + "px";
	else if (offsetY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight))
		sa.scrollslider.style.top = sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight + "px";
	else
	{
		sa.scrollslider.style.top = offsetY + sa.scrollButtonHeight - sa.scrollslider.offsetHeight/2 + "px";
	}
	sa.scrollIt();
}

function VSA_handleOnScroll()
{
	//event.srcElement.doScroll("pageUp");
}

//--- common functions ----

function VSA_getElements(attrValue, tagName, ownerNode, attrName) //get Elements By Attribute Name
{
	if (!tagName) tagName = "*";
	if (!ownerNode) ownerNode = document;
	if (!attrName) attrName = "name";
	var result = [];
	var nl = ownerNode.getElementsByTagName(tagName);
	for (var i=0; i<nl.length; i++)
	{
	//	if (nl.item(i).getAttribute(attrName) == attrValue)
//		result.push(nl.item(i));
		if (nl.item(i).className.indexOf(attrValue) != -1)
		result.push(nl.item(i));
	}
	return result;
}

function getRealTop(obj) {
	if (obj.getBoundingClientRect) {
		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
		var clientTop = document.documentElement.clientTop || document.body.clientTop || 0;
		return Math.round(obj.getBoundingClientRect().top + scrollTop - clientTop);
	} else {
		var posTop = 0;
		while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
		return posTop;
	}
}
