﻿
	var imagesSRC = [],
	    mailregsxp = /^[0-9a-z_\.\-]+@[0-9a-z_\.\-]+\.[a-z]{2,6}$/i;

$(document).ready(function () {

	$('#faq div.faqInfo a').click(function () {
		var subject = 're: ' + $(this).parent().parent().find('div.faqSubject').text();
		
		var form = document.getElementById('requestQuest');
		if (form) {
			form.subject.value = subject;
			form.name.focus();
		}
		return false;
	});
	
	var galryBox = $('#galary'), loader = $('#loader');

	if ( document.getElementById('topGalary').className == 'main' ) {
		galryBox.jqFancyTransitions({
			width: 1600,
			height: 300,
			strips: 32,
			effect: 'zipper',
			direction: 'left',
			delay: 5000
		});
	} else if ( document.getElementById('galary').getElementsByTagName('img').length > 1 ) {
		galryBox.jqFancyTransitions({
			width: 1600,
			height: 190,
			strips: 32,
			effect: 'zipper',
			direction: 'left',
			delay: 5000
		});
	}
	var listMenuItem = $('#menu > ul > li'), rel = [], images = {};

	for (var i = 0, li = listMenuItem.length; i < li; i++) {


		rel[i] = listMenuItem[i].firstChild.rel;

		if ( listMenuItem[i].getElementsByTagName('ul').length > 0 ) {

			$( listMenuItem[i] ).hover(
				function () { this.className = 'hasSubMenu' },
				function () { this.className = ''; }
			);
		
		}
		
		if ( rel[i].length > 0 ) {
			
			addHandler(rel[i]);
		
		}
	
	}
	
	function addHandler(src) {
		var change = false;
		$( listMenuItem[i] ).hover(
			function () {
				var image = images[src] = new Image;
				image.src = src;
				$.PauseOn(galryBox[0]);
				loader.show();
				if (image.complete) {
					$.showNewImage(galryBox[0], src);
					change = true;
					loader.hide();
				} else {
					$(image).unbind().bind('load', function () {
						$.showNewImage(galryBox[0], src);
						change = true;
						loader.hide();
					});
				}
			},
			function () { 

				$.showDefaultImage(galryBox[0], change);

			}
		);
	}

	var about = $('#about');
	
	$('#moreAbout').click(function () {
		
		about.find('div.tclmn1').animate({ width: '290px', paddingRight: '42px' }, 'slow' );
		about.css('height', 'auto')
		this.style.display = 'none';
		return false;
	});
	
	$('#orderForm').submit(function (e) {
		
		if ( $.trim(this['Name'].value).length < 1 ) {
			if ( confirm( 'Укажите Ф.И.О.' ) ) { this['Name'].focus(); }
			return false;
		}
		
		if ( $.trim(this['Phone'].value).length < 1 ) {
			if ( confirm( 'Укажите Ваш контактный телефон' ) ) { this['Phone'].focus(); }
			return false;
		}
		if ( $.trim( this['Email'].value ).length < 1 ) {
			if ( confirm( 'Укажите e-mail' ) ) { this['Email'].focus(); }
			return false;
		}
		if ( $.trim(this['Email'].value).match(mailregsxp) == null ) {
			if ( confirm('Укажите свой e-mail правильно!\nпример: example@mail.ru') ) { this['Email'].focus(); }
			return false;
		}
		if ( $.trim(this['City'].value).length < 1 ) {
			if ( confirm( 'Укажите Ваш город' ) ) { this['City'].focus(); }
			return false;
		}
		if ( this['Where'].selectedIndex == 0 ) {
			if ( confirm( 'Укажите откуда Вы о нас узнали' ) ) { this['Where'].focus(); }
			return false;
		}
		if ( this['Where'].selectedIndex == 6 ) {
			if ( $.trim(this['Other'].value).length < 1 ) {
				if ( confirm( 'Укажите другой источник откуда Вы о нас узнали' ) ) { this['Other'].focus(); }
				return false;
			}
		}
		if ( $.trim(this['q'].value).length < 1 ) {
			if ( confirm( 'Введите код с картинки' ) ) { this['q'].focus(); }
			return false;
		}
		

	});
	
	try {
		$().piroBox({
			my_speed: 400, //animation speed
			bg_alpha: 0.1, //background opacity
			slideShow : true, // true == slideshow on, false == slideshow off
			slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
			close_all : '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox
		});
	} catch(e) { return true; }

});
