// JavaScript Document
var light = {src: '/i/l.swf'};
sIFR.activate(light);
sIFR.replace(light, {  
	selector: '#content.thanks p',
	wmode: 'transparent',
	css: {
		'.sIFR-root': {'color':'#000000', 'font-style':'italic'}
	}
});
$(document).ready(function () {
	si = $("input, textarea");
	si.focus(function () {
		$(this).removeClass("error");
		siv = $(this).val();
		if ($(this).val() == siv) 
			$(this).attr("value", "");
		}
	).blur(function () {
		if (!$(this).val()) 
			$(this).attr("value", siv);
		}
	);

	if($.browser.msie) {$("form li, h2, #order").hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});}

	$("form li").click(function() {
		t = $(this).parent();
		t.toggleClass("open");
		if(!$(this).hasClass("active")) {
			v = $(this).text();
			t.removeClass("open").find(".active").removeClass("active").end().next("input").attr("value", v);
			$(this).prependTo(t).addClass("active");
		};
	});

	O = $("#content");
	img = $("#ill");
	h2 = $("h2");
	sIFR.replace(light, {  
		selector: '#content p',
		wmode: 'transparent',
		css: {
			'.sIFR-root': {'color':'#666666', 'font-style':'italic', 'cursor':'default'},
			'a': {'color':'#d9d739', 'cursor':'pointer'},
			'a:hover': {'color':'#6fc32c', 'text-decoration':'underline', 'cursor':'pointer'}
		}
	});

	function imagesLoaded()	{
		$("h2:not(':first')").next().hide();
		$("#preload").fadeOut("normal");
	}
	objImage = new Image();
	objImage.src='/i/ill1.jpg';
	checkLoad = function() {
		if(!objImage.complete) {checkLoadT = setTimeout("checkLoad()",1000);}
		else {imagesLoaded();}
	}
	checkLoad();


	$(h2).click(function() {
		if(!$(this).hasClass("active")) {
			i = h2.index(this)+1;
	
			function imagesLoaded()	{
				img.fadeOut("normal", function() {$(img).removeClass().addClass("h"+i).fadeIn("normal");});
			}
			objImage = new Image();
			objImage.src='/i/ill'+i+'.jpg';
			checkLoad = function() {
				if(!objImage.complete) {checkLoadT = setTimeout("checkLoad()",10);}
				else {imagesLoaded();}
			}
			checkLoad();
	
			$("h2.active").removeClass("active"); 
			$(this).toggleClass("active");
			n = $(this).next();
			n.slideDown("normal", function() {$("p:visible, form:visible", O).not(n).slideUp("normal");});
		}
	});

	$("#order").click(function() {
		err=0;
		email = $("input[name='email']");
		$("input:not(:hidden)").each(function() {
			var atr = $(this).attr("value");
			if(/ваше имя|количество персон|дата|время|телефон/.test(atr)) {err=1; $(this).addClass("error");}
		});
		if(!(/^\w+[-_\.]*\w+@\w+-?\w+\.[a-z]{2,4}$/.test(email.attr("value")))) {err=1; email.addClass("error");}
		if(err==1) {return false;}
	});
});