// start
biap = {}


Validator = function(params)
{
	var T = this;
	this.input = params.input
	this.type = params.type.toLowerCase();
	if(this[this.type])
	{
		this.input.onkeyup = function(e){T.check.call(T)}
		this.input.onpaste = function(e){T.check.call(T)}
		this.input.onchange = function(e){T.check.call(T)}
		this.check()
	}
}

Validator.prototype.check = function()
{
	var value = this[this.type](this.input.value)
	this.input.className = value ? '' : 'error';
	return value;
}

Validator.prototype.empty = function(value)
{
	value = value.replace(/(^ +| +$)/gi,'');
	return (value.length > 0);
}

Validator.prototype.phone = function(value)
{
	value = value.replace(/[-+ 	\(\)]+/gi,'');
	return (parseFloat(value) == value);
}

Validator.prototype.email = function(value)
{
	value = value.split('@')
	return (value.length == 2 && this.alias(value[0]) && this.domain(value[1]));
}

Validator.prototype.alias = function(value)
{
	return !!value.match(/^[^;|><\\\&\/ 	\(\)\[\]\{\}:*?,+="@]+$/i);
}

Validator.prototype.domain = function(value)
{
	return !!value.match(/^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i);
}


// video
biap.video = function(params)
{
	document.body.className += ' hide_flash'
	var T = this
	for(var i in params)
		this[i]=params[i];
	this.insertInto = this.insertInto || document.body;
	this.domElement=jso.cE('div',{className:'video'},[
		jso.cE('div',{className:'videoOverlay'}),
		this.videoContainer = jso.cE('div',{className:'videoContainer'},[
			jso.cE('p',{className:'videoClose',onclick:function(){T.closeVideo.call(T)}},[i18n.close]),
			this.videoMain = jso.cE('div',{className:'videoMain'},[jso.cE('div',{id:'videoVideo'})])
		])
	])
	this.videoContainer.style.width = this.width + 'px';
	this.videoContainer.style.height = this.height + 70 + 'px';
	this.videoMain.style.width = this.width + 'px';
	this.videoMain.style.height = this.height+20;
	this.insertInto.appendChild(this.domElement)
	this.recalcVideo.call(this)
	swfobject.embedSWF
	(
		'/images/mediaplayer.swf',
		'videoVideo',
		this.width,
		this.height+20,
		"9.0.115",
		'/images/expressInstall.swf',
		{
			file:this.src,
			width:this.width,
			height:this.height+20,
			usefullscreen:false,
			bufferlength:5,
			autostart:true
		}
	);
	this.active = true;
	jso.aE(window,'resize',function(){if(T.active)T.recalcVideo.call(T);})
}

biap.video.prototype.closeVideo = function()
{
	if(this.domElement.parentNode)
		this.domElement.parentNode.removeChild(this.domElement);
	this.active = false;
	document.body.className = document.body.className.replace(/ ?hide_flash/ig,'')
}
biap.video.prototype.recalcVideo = function()
{
	var html = document.body.parentNode
	this.overlayWidth=(html.clientWidth > html.scrollWidth ? html.clientWidth : html.scrollWidth)
	this.overlayHeight=(html.clientHeight > html.scrollHeight ? html.clientHeight : html.scrollHeight)
	this.domElement.style.width=this.overlayWidth+'px'
	this.domElement.style.height=this.overlayHeight+'px'
	this.videoContainer.style.left = Math.ceil((this.overlayWidth - this.width) / 2) + 'px';

	var top = (html.clientHeight - this.height - 70)
	if(top > 0)
		top = top / 2;
	top = top + html.scrollTop > 10 ? top + html.scrollTop : 10;

	this.videoContainer.style.top = Math.ceil(top) + 'px';
}



biap.start = function()
{
	var images = jso.gAV('a',document,'rel','lightbox')
	if(images)
	{
		myBox = new jso.myBox()
		for(var i in images)
			myBox.addImage.call
			(
				myBox,
				{
					domAnachor:images[i]
				}
			);
	}
	var domForm = jso.gI('contact')
	if(domForm)
	{
		var oName = new Validator({input:jso.gI('name'),type:'empty'})
		var oEmail = new Validator({input:jso.gI('email'),type:'email'})
		var oPhone = new Validator({input:jso.gI('phone'),type:'phone'})
		domForm.onsubmit = function()
		{
			if(!oName.check.call(oName) || !oEmail.check.call(oEmail) || !oPhone.check.call(oPhone))
			{
				alert(i18n.formError);
				return false;
			}
			return true;
		}
	}
}

jso.aE(window,'load',biap.start)