var html;
$(document).ready(function() {
	$('#request_img').click(function() {
		$('#request_slide').slideToggle('slow');
		$('.arrow').toggleClass('up');
	});
	$('.arrow').click(function() {
		$('#request_slide').slideToggle('slow');
		$(this).toggleClass('up');
		return false;
	});
	$('#left_menu img').click(function() {
		var id = $(this).attr('alt');
		$('#'+id).slideToggle('slow');
		$('#'+id).removeClass();
	});
	$('#topMenu img').mouseover(function() {
		var alt = $(this).attr('alt');
		$(this).attr('src','/images/menu/'+alt+'_hover.jpg');
	});
	$('#topMenu img').mouseout(function() {
		var alt = $(this).attr('alt');
		$(this).attr('src','/images/menu/'+alt+'.jpg');
	});
	$('#left_menu img').mouseover(function() {
		var alt = $(this).attr('alt');
		$(this).attr('src','/images/left/'+alt+'_hover.jpg');
	});
	$('#left_menu img').mouseout (function() {
		var alt = $(this).attr('alt');
		$(this).attr('src','/images/left/'+alt+'.jpg');
	});
	/*$('#menu ul>li').mouseover(function() {
		var title = $(this).attr('title');
		top(title);	
	})*/
	
	$('#shadow').live('click',function() {
		$(this).hide();
		$('#gallery_ajax').hide();
	})
});
function menu_top(id) {
	$('#topMenu ul ul').addClass('none');
	$('#menu ul ul').addClass('none');
	$('#top_'+id).removeClass();
	$('#top_'+id).show();
}
function map(ids) {
	$('#ajax_map').css('display','none');
	$.get('../ajax.php',{mode:'getHole',ids:ids},
	function(response) {
		$('#ajax_map').html(response).fadeIn('slow');
		});
}
function hide_map(ids) {
	$('#'+ids).fadeOut('slow');
}
function display(ids) {
	$('#'+ids).css('display','block');
}
/* === GALLERY === */
function open_gallery(T_Code,Code) {
	scrollTo(0,0);
	$.get('../ajax.php',{mode:'getGallery',T_Code:T_Code,Code:Code},
	function(response) {
		$('#shadow').show();
		$('#gallery_ajax').html(response).fadeIn("slow");
	});
}
function replace_img(T_Code,Code) {
	$('#main_img').attr("src","/Pages/images/B/"+T_Code+"_"+Code+".jpg");
}
function gallery_small(pos,T_Code) {
	$(".small_fotos").hide();
	$.get('../ajax.php',{mode:'getImages',pos:pos,T_Code:T_Code},
	function(response) {
		$(".small_fotos").html(response).show();
	});
}
function close_gallery() {
	$('#shadow').hide();
	$('body').css("overflow","visible");
	$('#gallery_ajax').fadeOut('slow');
}

/* == REQUEST GO_GO_GO == */

var reg_mail = new RegExp("^([A-Za-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$");
var reg_phone = new RegExp("^([0-9])*$");
var reg_def = new RegExp("()*");
function request() {
	var text = $("input:text",this.form);
	var form_value = '';
	text.each(function() {
		form_value += this.value+' <br/>';
	});
	valid = check('request_FIO',reg_def);
	valid += check('request_phone',reg_phone);
	valid += check('request_email',reg_mail);
	if (valid==3) {
		$('#request_info').html('Подождите идет отправка').fadeIn('slow');
		$.get('../ajax.php',{mode:'my_mail',Letter: form_value, EMail: $('#request_email').get(0).value, FIO : $('#request_FIO').get(0).value},
			function(response) {
				$('#request_info').html(response).fadeIn('slow');
		});
	}
}

function check(id,regex) {
	if ($('#'+id).get(0).value != '' && $('#'+id).get(0).value!='Не верная информация' && regex.test($('#'+id).get(0).value)) {
		$('#'+id).removeClass('noValid');
		return 1;
	}
	else {
		$('#'+id).addClass('noValid');
		$('#'+id).get(0).value = 'Проверьте введенные данные';
		$('#'+id).click(function() {
			if(this.value='Проверьте введенные данные') this.value='';
		});
		return 0;
	}
}

function my_mail() {
	valid = check('contact_FIO',reg_def);
	valid += check('contact_email',reg_mail);
	valid += check('contact_note',reg_def);
	if(valid==3) {
		Note = 'Вопрос: ' + $('textarea',this.form).get(0).value;
		if($('#contact_number').get(0).value!='') Note += '<br/> Телефон:'+$('#contact_number').get(0).value;
		$("#info").html('Подождите идет отправка данных ...').fadeIn('slow');
		$.get('../ajax.php', {mode:'my_mail',Letter:Note,EMail:$('#contact_email').get(0).value,FIO: $('#contact_FIO').get(0).value},
		function (response) {
			$("#info").html(response).fadeIn('slow');
		});
	}
}

function preload(images) {
    if (typeof document.body == "undefined") return;
    try {
        var div = document.createElement("div");
        var s = div.style;
        s.position = "absolute";
        s.top = s.left = 0;
        s.visibility = "hidden";
        document.body.appendChild(div);
		for (var i = 0; i < images.length; i++) div.innerHTML += "<img src=\"" + images[i] + "\" style='position:absolute;left:0;top:0;z-index:1;'/>";
    } catch(e) {
		return false;
    }
}
