var timer;
jQuery(document).ready(function($) {

	$('.inputs').bind('focus', Function("if(this.value==this.defaultValue) this.value='';"));
	$('.inputs').bind('blur', Function("if(this.value=='') this.value=this.defaultValue; "));
	
	
	timer = setTimeout(Cloud, 5000);
	function Cloud() {
		var rnd = Math.floor(Math.random() * (6 - 1 + 1)) + 1; 
		$crel = $('#mainproto').attr('rel');
		if ( $crel == rnd ) { rnd = Math.floor(Math.random() * (6 - 1 + 1)) + 1; }
		var imgbkg = '/assets/images/backgrounds/'+rnd+'.jpg';
		$("#mainproto").stop().css({opacity:'0.1'});
		$("#mainproto").css({backgroundImage:'url('+imgbkg+')'});
		$('#mainproto').attr('rel',rnd);
		$("#mainproto").animate({opacity:'1'},500);
		timer = setTimeout(Cloud, 9000);
	}



	
	
$('.ca1').click(function(){
	$('#pc2').fadeOut(400);
	$('#pc1').fadeIn(800);
});
$('.ca2').click(function(){
	$('#pc1').fadeOut(400);
	$('#pc2').fadeIn(800);
});

$('.thumb').click(function(){
	$src = $(this).attr('rel');
	$('#mainphoto').attr({'src':$src});
});


$('.divlilink').click(function(){
	if ( $(this).attr('class') != 'divlilink active' )
	{
		$(this).addClass('active');
	}
	else
	{
		$(this).removeClass('active');
	}
	$(this).next().slideToggle(700);
});


});



function ValidateForm()
{
	$valid = 1;
	$email = $('input[name$="Email"]').val();
	$tel = $('input[name$="Tel"]').val();
	$name = $('input[name$="Name"]').val();
	$mess = $('textarea[name$="Message"]').val();
	$captcha = $('input[name$="vericode"]').val();
	//if ( strlen($tel) < 1 )	{ $('input[name$="Tel"]').addClass('error_bg'); $valid = 0; }
	if ( strlen($name) < 1 )	{ $('input[name$="Name"]').addClass('error_bg'); $valid = 0; }
	//if ( strlen($email) < 1 )	{ $('input[name$="Email"]').addClass('error_bg'); $valid = 0; }
	if ( strlen($mess) < 1 )	{ $('textarea[name$="Message"]').addClass('error_bg'); $valid = 0; }
	if ( strlen($captcha) < 1 )	{ $('input[name$="vericode"]').addClass('error_bg'); $valid = 0; }
	if ( $valid == 1 )
	{
		var theform = document.getElementById('feedback');
		theform.submit();
		return true;
	}
	else
	{
		return false;
	}
}

/* PHP Analogicus */
function strlen( mixed_var ) {   return mixed_var.length; }
// Преобразует строку в нижний регистр
function strtolower( mixed_var ) {    return mixed_var.toLowerCase();   }
// Преобразует строку в верхний регистр
function strtoupper( mixed_var ) {   return mixed_var.toUpperCase();   }
// возвращает символ находящийся на позиции pos от начала слова. Аналог $string{pos}
function letter_posion(string, position) {   return string.charAt(position);   }
// Возвращает позицию первого вхождения подстроки needle в строку haystack.
function strpos( haystack, needle, offset ) {
   if(offset) offset = offset ;
   else offset = 0 ;
   return haystack.indexOf(needle, offset);
}
// Возвращает массив строк, полученных разбиением строки string с использованием separator в качестве разделителя.
function explode(separator, string, limit) {
   return string.split (seperator , limit);
}
 /* // PHP Analogicus */

function isValidEmailAddress(emailAddress)
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function testKey(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
  return /\w/.test(key);
}
function testFIO(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
  return /^[a-zА-Яа-я]+$/i.test(key);
}
function testKeyD(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
 return /[\d\.]/.test(key);
}
function testKeyTel(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {  return true;}
  key = String.fromCharCode(key);
 return /[0+ .123456789 ()\-]/.test(key);
}


