var theTimeout = 200;

function LanguageInfo(){
    var n = navigator;
    this.UALanguage = n.language ? n.language : n.browserLanguage ? n.browserLanguage : null;
    this.userLanguage = n.userLanguage ? n.userLanguage : n.systemLanguage ? systemLanguage : null;
}

function pageload(hash) {
// alert("pageload: " + hash);
	if(hash !== undefined) {
		if($.browser.msie) {
			hash = encodeURIComponent(hash);
		}
		$("div#container_holder").animate({scrollTop: 0}, function () {
			$("div.contents:visible").not("#content_" + hash).hide();
			$("#content_" + hash).fadeIn(theTimeout*5, function() {
				document.title = document.title.substr(0, document.title.indexOf('|')) + '|' + $(this).find("h1").text();
			});
		});
		$("#content_" + hash + " img").each( function () {
			if ( ($(this).attr("src") == "") || ($(this).attr("src") == undefined) ) {
				$(this).attr("src", $(this).attr("alt")).load().removeAttr("alt");
			}
		});
	} else {
		hash = "home";
		$("div.contents:visible").not("#content_home").hide();
		$("#content_" + hash).fadeIn(theTimeout*5, function() {
				document.title = document.title.substr(0, document.title.indexOf('|')) + '|' + $(this).find("h1").text();
		});
	}
}


function Start_Barashik () {

	$("div#flash_container").fadeOut(theTimeout);
	
	$.historyInit(pageload, "");

	// Работаем с меню с сайта
	$("div#container_holder div.containers").show();
	$("div#rus div#menu div#menu_m li:not(:last)").append('<span id="menu_separator">&nbsp;|&nbsp;</span>');
	$("div#eng div#menu div#menu_m li:not(:last)").append('<span id="menu_separator">&nbsp;|&nbsp;</span>');
	$("div.containers").find("div#menu div#menu_m ul").each(function () {
//alert($(this).find("li:last").offset().left);
		$(this).css({marginLeft: (940 - ($(this).find("li:last").offset().left + $(this).find("li:last").width() - $(this).find("li:first").offset().left))/2 });
	});

// ABQIAAAAZ6kmWeHDVww3LI7PC8PDlhQIdAC-OSTfrH4JXV33Jx1LqQWihBRSAc_fIC9xDZ26A8CMycnVrQ-wfQ
	// Google map RUS
/*	$("div#content_contact").show();
	var myLatlng = new google.maps.LatLng(50.4212431105453,30.477268560028076);
	var myOptions = {
	  zoom: 15,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas_rus"), myOptions);
    var marker_rus = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Ресторан БАРАSHIK"
    });
	$("div#content_contact").hide();
*/	
	$("div#container_holder div.containers").hide();
	// Поработали с div#window_

	var oLanguage = new LanguageInfo();
//alert(oLanguage.UALanguage);
    if ((oLanguage.userLanguage == 'ru') || (oLanguage.UALanguage == 'ru') || (oLanguage.userLanguage == null)) {
		//$("div#container_holder div#rus").insertBefore("div.containers:first");
		$("div#container_holder div#rus div.contents:first").show();
		$("div#container_holder div#rus").fadeIn(theTimeout);
    } else {
		$("div#container_holder div#eng div.contents:first").show();
		$("div#container_holder div#eng").insertBefore("div.containers:first");
		$("div#container_holder div#eng").fadeIn(theTimeout);
//		$("div#eng div#menu div#menu_m ul").css({marginLeft: (940 - ($("div#eng div#menu div#menu_m li:last").offset().left + $("div#eng div#menu div#menu_m li:last").width() - $("div#eng div#menu div#menu_m li:first").offset().left))/2 });
    }

	// Работаем с блюдами
	$("div#content_dishes ul li").hide();
	$("div#content_dishes ul li").find("span:first").css({"width":"280px", "text-align":"left"}).next().css({"width":"120px"}).next().css({"width":"120px"});
	$("div#content_dishes ul li").hover(function () {
			var theHeight = 400 - $(this).height();
			$(this).animate({backgroundPosition:"(0 -" + theHeight + "px)"}, {duration: theTimeout});
		}, function () {
			$(this).animate({backgroundPosition:"(0 0)"}, {duration: theTimeout});
		}
	);

	// Кликаем по блюдам
	$("div#content_dishes ul span#title").click(function () {
//		$("div#content_dishes ul li:visible").toggle(theTimeout*2);
		$(this).parent().find("li").slideToggle(theTimeout*2);
	});

	var hash;

	// Кликаем по меню сайта
	$("a[rel='history']").click(function(){
//alert(this.href);
		hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});

	// Смена языка
	$("div.langs").click(function () {
		var newLang = $(this).attr("lang");

        $("div#container_holder div.containers:visible").fadeOut(theTimeout/2, function () {
	        $("div#container_holder").find("div#" + newLang).insertBefore("div#container_holder div.containers:first");
			$("div#container_holder").find("div#" + newLang).fadeIn(theTimeout, function() {
				pageload(hash);
			});
		});
    });

	// Вылетают кружки в логотипе
	$("div.containers div#logo_container div#logo").hover(
		function () {
			$(this).next().find("div").stop().css({opacity:1});
			$(this).next().find("div#vkusno_1").fadeIn(theTimeout, function () {
				$(this).next().fadeIn(theTimeout, function () {
					$(this).next().fadeIn(theTimeout, function () {
					});
				});
			});
		},
		function () {
			$(this).next().find("div").stop();
			$(this).next().find("div#vkusno_3").fadeOut(theTimeout, function () {
				$(this).prev().fadeOut(theTimeout, function () {
					$(this).prev().fadeOut(theTimeout, function () {
					});
				});
			});
		}
	);

	// Запускаем все слайд-шоу
	$('#photo_container_1_rus').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });
	$('#photo_container_1_eng').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });

	$('#photo_container_2_rus').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });
	$('#photo_container_2_eng').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });

	$('#photo_container_3_rus').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });
	$('#photo_container_3_eng').cycle({ fx: 'fade', speed: theTimeout*5, timeout: theTimeout*15, random: 1 });

	// Работаем с Музыкой
	var theMusicObj = '';
	if ( $("#music_def").length ) {
		theMusicObj = 'music_def';
	} else {
		if ( $("#music").length ) {
			theMusicObj = 'music';
		}
	}
	if (theMusicObj != '') {
		var so = new SWFObject("music/" + theMusicObj + ".swf","music","50","90","8","#FFFFFF");
		so.addParam("wmode", "transparent");
		so.write(theMusicObj);
	}

	// Предзагрузчик
	$("div#preloader").fadeOut(theTimeout*10);


	// Хочу еще что-то сообщить
	$(".want_more_message").click( function() {
		var theForm = $(this).parent();
			theForm.find("div.want_more_message").fadeOut(theTimeout/2, function() {	
			theForm.find("div.result_message").fadeOut(theTimeout/2, function() {
				theForm.find(".orderForms").fadeIn(theTimeout);
			});
		});
	});

	// Работаем с формами
	$("#orderForm_rus").validate({
		rules : {
			catering_date : { required : true },
			cname : { required : true, minlength: 2	},
			phone : { required : true, minlength: 7, digits: true }
		},
		messages : { 
			catering_date : { required : "Введіть дату" },
			cname : { required : "Введіть ваше им`я", minlength : "Введіть мінімум 2 символа" },
			phone : { required : "Введіть номер телефона",  minlength: "Введіть мінімум 7 цифр", digits: "Введіть тільки цифри" }
		},
		submitHandler: function(form) {
			$("#orderForm_rus").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_order.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#orderForm_eng").validate({
		rules : {
			catering_date : { required : true },
			cname : { required : true, minlength: 2	},
			phone : { required : true, minlength: 7, digits: true }
		},
		messages : {
			catering_date : { required : "Enter date" },
			cname : { required : "Enter your name", minlength : "It must have 2 chars at least" },
			phone : { required : "Enter phone number", minlength: "Enter at least 7 digits", digits: "Enter digits only" }
		},
		submitHandler: function(form) {
			$("#orderForm_eng").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_order.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#bookingForm_rus").validate({
		rules : {
			cname : { required : true, minlength: 2	},
			phone : { required : true, minlength: 7, digits: true },
			count : { required : true, digits: true },
			booking_date : { required : true }
		},
		messages : {
			cname : { required : "Введіть ваше ім`я", minlength : "Введіть мінімум 2 символа" },
			phone : { required : "Введіть номер телефона",  minlength: "Введіть мінімум 7 цифр", digits: "Введіть тілько цифри" },
			count : { required : "Введіть кількість гостей", digits: "Введіть тільки цифри" },
			booking_date : { required : "Введіть дату для бронювання" }
		},
		submitHandler: function(form) {
			$("#bookingForm_rus").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_booking.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#bookingForm_eng").validate({
		rules : {
			cname : { required : true, minlength: 2	},
			phone : { required : true, minlength: 7, digits: true },
			count : { required : true, digits: true },
			booking_date : { required : true }
		},
		messages : {
			cname : { required : "Enter your name", minlength : "It must have 2 chars at least" },
			phone : { required : "Enter phone number", minlength: "Enter at least 7 digits", digits: "Enter digits only" },
			count : { required : "Enter amount of guests", digits: "Enter digits only" },
			booking_date : { required : "Enter date for booking" }
		},
		submitHandler: function(form) {
			$("#bookingForm_eng").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_booking.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#contactForm_rus").validate({
		rules : {
			cname : { required : true, minlength: 2 },
			comments : { required : true }
		},
		messages : { 
			cname : { required : "Введіть ваше им`я", minlength : "Введіть мінімум 2 символа" },
			comments : { required : "Введіть текст повідомлення" }
		},
		submitHandler: function(form) {
			$("#contactForm_rus").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_contact.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#contactForm_eng").validate({
		rules : {
			cname : { required : true,  minlength: 2 },
			comments : { required : true }
		},
		messages : {
			cname : { required : "Enter your name", minlength : "It must have 2 chars at least" },
			comments : { required : "Enter message text" }
		},
		submitHandler: function(form) {
			$("#contactForm_eng").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_contact.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#vacanciesForm_rus").validate({
		rules : {
			cname : { required : true, minlength: 2 },
			phone : { required : true, minlength: 7 },
			comments : { required : true }
		},
		messages : { 
			cname : { required : "Введіть ваше ім`я", minlength : "Введіть мінімум 2 символа" },
			phone : { required : "Введіть ваш телефон", minlength : "Введіть мінімум 7 цифр" },
			comments : { required : "Введіть текст повідомлення" }
		},
		submitHandler: function(form) {
			$("#vacanciesForm_rus").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_contact.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});
	$("#vacanciesForm_eng").validate({
		rules : {
			cname : { required : true,  minlength: 2 },
			phone : { required : true,  minlength: 7 },
			comments : { required : true }
		},
		messages : {
			cname : { required : "Enter your name", minlength : "It must have 2 chars at least" },
			phone : { required : "Enter your phone", minlength : "It must have 7 digits at least" },
			comments : { required : "Enter message text" }
		},
		submitHandler: function(form) {
			$("#vacanciesForm_eng").fadeOut( function() {
				var theForm = $(this);
				var theFormContainer = theForm.parent();
				$("div#container_holder").animate({scrollTop: 0}, function () {
					$.post('send_contact.php', theForm.serialize()+'&ajax=1', function(data) {
						theFormContainer.find("div.result_message").fadeIn(theTimeout, function() {
							theFormContainer.find("div.want_more_message").fadeIn(theTimeout);
						});
					});
				});
			});
		}
	});


	// Прикрепляем Datepicker для ввода даты
	$("#booking_date_rus").datepicker({
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		monthNames: ['Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'],
		dayNamesMin: ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб']
	});
	$("#booking_date_eng").datepicker({
		dateFormat: 'dd.mm.yy',
		firstDay: 0,
		monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
	});
	$("#catering_date_rus").datepicker({
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		monthNames: ['Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'],
		dayNamesMin: ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб']
	});
	$("#catering_date_eng").datepicker({
		dateFormat: 'dd.mm.yy',
		firstDay: 0,
		monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
	});

}




$(document).ready(function(){
						   
var so = new SWFObject("media/clip.swf","clip","550","400","8","#FFFFFF");
so.addParam("wmode", "transparent");
so.write("flash_clip");

//Start_Barashik ();

});

