document.observe('dom:loaded', function(){
	Browser = Prototype.Browser;
	var ua = navigator.userAgent.toLowerCase();
	Browser.IE = !Browser.Opera && ua.indexOf("msie") > -1 && window.attachEvent;
	Browser.IE7 = !Browser.Opera && ua.indexOf("msie 7") > -1;
	Browser.IE6 = Browser.IE && !Browser.IE7;
	
	var gbg = $('gbg');
	var gplace = $('gplace');
	var gfeedback = $('gfeedback');
	var gimage = $('gimage');
	var gtext = $('gtext');
	var gform = $('gform');
	var wait_ico = 'url(/pics/i/wait.gif)';
	$$('a[class="lightview"]').each(function(element){
		element.onclick = function(){
			if (element.rel != 'form'){
				aform = gplace;
				toShow(element,642,429);
			}else{
				aform = gfeedback;
				toShowForm(element,390,357);
			};
			return false;
		};
	});
	$$('.gclose').each(function(element){
		element.onclick = function(){
			toHide(aform);
		};
	});
	gbg.onclick = function(){
		toHide(aform);
	};
	/*функция показа - галерея*/
	function toShow(ge,gw,gh){
		gplace.setStyle({
			'background-image': wait_ico
		});
		if (gimage.src != ge.href){
			gimage.src = ge.href;
		};
		gimage.setStyle({
			opacity: 0.0
		});
		var gwx = gw/-2;
		var ghx = gh/-2;
		gbg.setStyle({
			opacity: 0.0
		});
		if (Browser.IE6){
			xx = document.documentElement.scrollTop+((document.documentElement.clientHeight-gh)/2)-ghx;
			gplace.setStyle({
				'top': xx+'px'
			});
		};
		new Effect.Morph(gbg, {
			style: 'width: 100%;',
			delay: 0,
			duration: 0
		});
		new Effect.Opacity(gbg,{
			to: 0.7,
			delay: 0.0,
			duration: 0.5
		});
		gtext.innerHTML = ge.title;
		new Effect.Morph(gplace,{
			style: 'width:'+gw+'px; margin-left:'+gwx+'px;',
			delay: 0.5,
			duration: 0.5
		});
		new Effect.Morph(gplace,{
			style: 'height:'+gh+'px; margin-top:'+ghx+'px;',
			delay: 1.0,
			duration: 0.3
		});
		if (gimage.src != ge.href){
			gimage.observe('loaded', function(){
				new Effect.Opacity(gimage,{
					to: 1.0,
					delay: 1.3,
					duration: 0.3
				});
			});
		}else{
			new Effect.Opacity(gimage,{
				to: 1.0,
				delay: 1.3,
				duration: 0.3
			});
		};
	};
	/*---*/
	/*функция показа - форма*/
	function toShowForm(ge,gw,gh){
		var gwx = gw/-2;
		var ghx = gh/-2;
		gbg.setStyle({
			opacity: 0.0
		});
		if (Browser.IE6){
			xx = document.documentElement.scrollTop+((document.documentElement.clientHeight-gh)/2)-ghx;
			gfeedback.setStyle({
				'top': xx+'px'
			});
		};
		new Effect.Morph(gbg, {
			style: 'width: 100%;',
			delay: 0,
			duration: 0
		});
		new Effect.Opacity(gbg,{
			to: 0.7,
			delay: 0.0,
			duration: 0.5
		});
		gfeedback.setStyle({
			'background-image': wait_ico
		});
		gform.setStyle({
			opacity: 0.0
		});
		new Effect.Morph(gfeedback,{
			style: 'width:'+gw+'px; margin-left:'+gwx+'px;',
			delay: 0.5,
			duration: 0.5
		});
		new Effect.Morph(gfeedback,{
			style: 'height:'+gh+'px; margin-top:'+ghx+'px;',
			delay: 1.0,
			duration: 0.3
		});
		new Effect.Opacity(gform,{
			to: 1.0,
			delay: 1.3,
			duration: 0.3
		});
	};
	/*---*/
	/*функция скрытия*/
	function toHide(obj){
		obj.setStyle({
			'background-image': 'none'
		});
		if (obj == gplace){
			gimage.src = '/pics/i/blank.gif';
			new Effect.Opacity(gimage, {
				to: 0.0,
				duration: 0.3
			});
		};
		if (obj == gfeedback){
			new Effect.Opacity(gform, {
				to: 0.0,
				duration: 0.3
			});
		};
		new Effect.Morph(obj, {
			style: 'height: 1px; margin-top: 0px;',
			delay: 0.3,
			duration: 0.3
		});
		new Effect.Morph(obj, {
			style: 'width: 0px; margin-left: 0px;',
			delay: 0.6,
			duration: 0.5
		});
		if (!Browser.IE6){
			new Effect.Opacity(gbg,{
				to: 0.0,
				delay: 1.1,
				duration: 0.3
			});
		};
		new Effect.Morph(gbg, {
			style: 'width: 0px;',
			delay: 1.1,
			duration: 0
		});
	};
	/*---*/
});
function check_mail(email)
{ var re = new RegExp("^[\\w\\.-]+@[\\w\\.-]+\\.[A-Za-z]{2,}");
  return (re.test(email));
}
function rstr() {
	$('subm').style.display='';
	$('send2').style.display='none';
	$('c_name').value='';
	$('c_text').value='';
	$('c_email').value='';
}
function subm() {
var obj1 = $('gfeedback');
var gform = $('gform');
var gbg = $('gbg');
		obj1.setStyle({
			'background-image': 'none'
		});
		new Effect.Opacity(gform, {
				to: 0.0,
				duration: 0.3
			});

		new Effect.Morph(obj1, {
			style: 'height: 1px; margin-top: 0px;',
			delay: 0.3,
			duration: 0.3
		});
		new Effect.Morph(obj1, {
			style: 'width: 0px; margin-left: 0px;',
			delay: 0.6,
			duration: 0.5
		});
		if (!Browser.IE6){
			new Effect.Opacity(gbg,{
				to: 0.0,
				delay: 1.1,
				duration: 0.3
			});
		};
		new Effect.Morph(gbg, {
			style: 'width: 0px;',
			delay: 1.1,
			duration: 0
		});
		id = setTimeout("rstr()",3000);
}
function shownext() {
	$('send1').style.display='none';
	$('subm').style.display='none';
	$('send2').style.display='';
	id = setTimeout("subm()",20000);
}
function checkdata() {
	ok=0;
	if (document.contact_form.c_name.value=="") {
		document.contact_form.c_name.style.borderColor='#dd127b';
		document.contact_form.c_name.style.backgroundColor='#ffccff';
		document.contact_form.c_name.focus;
		document.getElementById('emsg').innerHTML='Введите имя!';
		
	} else {
		document.contact_form.c_name.style.borderColor='#9a9a9a';
		document.contact_form.c_name.style.backgroundColor='#fff';
		document.getElementById('emsg').innerHTML='';
		ok++;
	}
	if (!check_mail(document.contact_form.c_email.value)) {
		document.contact_form.c_email.style.borderColor='#dd127b';
		document.contact_form.c_email.style.backgroundColor='#ffccff';
		document.contact_form.c_email.focus;
		document.getElementById('emsg').innerHTML='Введите корректный адрес электронной почты!';
		
	} else {
		document.contact_form.c_email.style.borderColor='#9a9a9a';
		document.contact_form.c_email.style.backgroundColor='#fff';
		document.getElementById('emsg').innerHTML='';
		ok++;
	}
	if (document.contact_form.c_text.value=="") {
		document.contact_form.c_text.style.borderColor='#dd127b';
		document.contact_form.c_text.style.backgroundColor='#ffccff';
		document.contact_form.c_text.focus;
		$('emsg').innerHTML='Введите корректные данные!';
		
	} else {
		document.contact_form.c_text.style.borderColor='#9a9a9a';
		document.contact_form.c_text.style.backgroundColor='#fff';
		document.getElementById('emsg').innerHTML='';
		ok++;
	}
	if (ok==3) {
	//document.getElementById('send1').style.display='';
	var frm=$('contact_form');
	act = frm.action;
	var c_n=$('c_name');
	cn = c_n.value;
	var c_e=$('c_email');
	ce = c_e.value;
	var c_t=$('c_text');
	ct = c_t.value;	
	new Ajax.Updater('',act,
    {
      method: 'post',
      parameters: { c_name: cn, c_email:ce, c_text: ct},
      onComplete: shownext()
    });
	} else {
		$('emsg').innerHTML='Введите корректные данные!';
		return false;
	}
}
