function execute_a(){
		if (((this.href.search(/www.express-catering.com.ua/) == 7) || (this.href.search(/express-catering.com.ua/) == 7)) && ((this.href.search(/www.express-catering.com.ua\/menu/) != 7) && (this.href.search(/express-catering.com.ua\/menu/) != 7)) && ((this.href.search(/www.express-catering.com.ua\/graphics/) != 7) && (this.href.search(/express-catering.com.ua\/graphics/) != 7)) && ((this.href.search(/www.express-catering.com.ua\/price_list/) != 7) && (this.href.search(/express-catering.com.ua\/price_list/) != 7))) {
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			$.historyLoad('');
			$.historyLoad(hash);
			return false;
		} else {
			location.replace(this.href);
			return true;
		}
}

var sections = new Array('order', 'rent', 'services', 'about', 'home');

function init_links() {
	$("a").not("#point_left, #point_right, .our_work_block a, .b_close, .map_title, .global").click(execute_a);
}

$(document).ready(function () {
	$.historyInit(callback);
	//$("div.tram2-wrapper").css({width: ($("div.tram2 div.wagon2").length * 763)+ 2000 + "px"});
	//$("div.tram2").animate({scrollLeft: $(".wagon2.selected").prevAll().length * 763}, 1);
	$("div.tram2-wrapper").css({width: ($("div.tram2 div.wagon2").length * 763)+ 2000 + "px"});
	//$("div.tram2").animate({scrollLeft: $(".wagon2.selected").prevAll().length * 763}, 1);
	$("div.tram2").animate({scrollLeft: 5 * 763}, 1);
	$("div.tram2").animate({scrollLeft: 4 * 763 + 80}, 12000);

	init_links();

	$("#point_right").click(function () {
		var hash = window.location.href;
		hash = hash.replace(/^.*#/, '');
		hash = hash.split('.');
		var nextHash = '';
		var i=0;
		var sections = new Array('order', 'rent', 'services', 'about', 'home');
		for(i=0; i<=sections.length; i++) {
			if(sections[i] == hash[0]) {
				if(i != 4) {
					nextHash = sections[i+1];
					break;
				} else if (hash[0] == 'sitemap') {
					nextHash = 'order';
				} else {
					nextHash = sections[4];
					break;
				}
			}
		}
		$.historyLoad(nextHash);	
		moveGoodsByArrow ('right');

		return false;
	});

	$("#point_left").click(function () {
		var hash = window.location.href;
		hash = hash.replace(/^.*#/, '');
		hash = hash.split('.');
		var nextHash = '';
		var i=0;
		var sections = new Array('order', 'rent', 'services', 'about', 'home');
		for(i=0; i<=(sections.length-1); i++) {
			if(sections[i] == hash[0]) {
			 	if(i != 0) {
					nextHash = sections[i-1];
					break;
				} else if (hash[0] == 'sitemap') {
					nextHash = 'order';
				} else {
					nextHash = sections[0];
					break;
				}
			}
		}
		$.historyLoad(nextHash);	
		moveGoodsByArrow ('left');
		
		return false;
	});
});


function callback(hash)
{	
	if(hash != '') {
		var hashArray = hash.split('.');
		var albumId;
		if(hashArray[0] == 'rent' && hashArray[1] !== undefined) {
			var url = "/index_ajax.php?Section=" + hashArray[0] + "&AlbumID=" + hashArray[1];
		} else if(hashArray[0] == 'our_works' && hashArray[1] !== undefined) {
			var url = "/index_ajax.php?Section=" + hashArray[0] + "&AlbumID=" + hashArray[1];
		} else {
			var url = "/index_ajax.php?Section=" + hashArray[0];	
		}
		$.ajax({
			url: url, 
			success: function(data)
			{
				hashArray = hash.split('.');	

				if(hash != 'home') {
					var root_comment = data.match(/<!--\d+-->/);
					function getdigits (s) {
					   var test = s.toString();
					   return test.replace (/[^\d]/g, "");
					}
					var root = getdigits(root_comment);
					$("div.tram2").stop(true);
					if (hashArray[0] == 'sitemap') {
						$("div.tram2").animate({scrollLeft: 100}, 1000);
					} else {
						$("div.tram2").animate({scrollLeft: $("div.tram2 #" + root).prevAll().length * 763 + 100}, 1000);
					}
					
					$("#container_block").html(data);

					Photo = new Image;
					Photo.src = "/graphics/sections_photos/" + root + ".png";
	
					$(Photo).bind('load', function () {
						$("#baby").attr("src", Photo.src);
						$("#baby").css("width", Photo.width);
						$("#baby").css("height", Photo.height);
					});
				} else {
					var root_comment = data.match(/<!--\d+-->/);
					function getdigits (s) {
					   var test = s.toString();
					   return test.replace (/[^\d]/g, "");
					}
					var root = getdigits(root_comment);

					$("div.tram2").stop(true);
					$("div.tram2").animate({scrollLeft: 4 * 763 + 80}, 1000);

					$("#container_block").html(data);

					Photo = new Image;
					Photo.src = "/graphics/sections_photos/" + root + ".png";
	
					$(Photo).bind('load', function () {
						$("#baby").attr("src", Photo.src);
						$("#baby").css("width", Photo.width);
						$("#baby").css("height", Photo.height);
					});
				}
				
				$(".our_work_block a").click(function () {
					if ($.browser.msie) {
						currentWindowHeight = document.documentElement.clientHeight;
					} else {
						currentWindowHeight = window.innerHeight;
					}
					if (currentWindowHeight > 660) {
						currentBodyHeight = $(window).height();
						$(".modal").css({height: currentBodyHeight + "px"});
						$(".modal").css({display: "block"});
						$(".modal").animate({opacity: '0.9'}, 500);
						//$(this).attr("target", "_blank");
						preloadImage ($(this).attr("href"), $(this).children("img").attr("title"));
						return false;
					} else {
						return true;
					}
				});

				//обработка отправленного заказа
				$("#order_form").submit(function() {
					$("#form_info").text('');
					var form_error = "Заполните все обязательные поля!";
					var form_success = "Ваш заказ был успешно отправлен! Скоро с Вами свяжется наш менеджер.";

					var event_type = $("input[name='event_type']").val();
					var place = $("input[name='place']").val();
					var date = $("input[name='date']").val();
					var guests = $("input[name='guests']").val();
					var budget = $("input[name='budget']").val();
					var wishes = $("input[name='wishes']").val();
					var company = $("input[name='company']").val();
					var name = $("input[name='name']").val();
					var phone = $("input[name='phone']").val();
					var mobile = $("input[name='mobile']").val();
					var email = $("input[name='email']").val();
					var submit = $("input[name='submit']").val();

					var dataString = 'event_type=' + event_type + '&place=' + place + '&date=' + date + '&guests=' + guests + '&budget=' + budget + '&wishes=' + wishes + '&company=' + company + '&name=' + name + '&phone=' + phone + '&mobile=' + mobile + '&email=' + email + '&submit=' + submit;

					$.ajax({  
					  type: "POST",  
					  url: $("#order_form").attr("action"),  
					  data: dataString,  
					  success: function(response) {
					  if(response == '0') {
					    $("#form_info").text(form_error);						
					  } else {
					    $("#form_info").text(form_success);
					    $("#order_form input").val('');  
				    	event_type = '';
					place = '';
					date = '';
					guests = '';
					budget = '';
					wishes = '';
					company = '';
					name = '';
					phone = '';
					mobile = '';
					email = '';
					submit = '';
					  }
					  }  
					});  

					return false;
				});

				//обработка запроса по форме обратной связи
				$("#contact_form").submit(function() {
					$("#form_info").text('');
					var form_error = "Заполните все обязательные поля!";
					var form_success = "Ваше письмо было успешно отправлено!";

					var subject = $("input[name='subject']").val();
					var message = $("textarea[name='message']").val();
					var name = $("input[name='name']").val();
					var phone = $("input[name='phone']").val();
					var email = $("input[name='email']").val();
					var code = $("input[name='code']").val();
					var submit = $("input[name='submit']").val();

					var dataString = 'subject=' + subject + '&message=' + message + '&name=' + name + '&phone=' + phone + '&email=' + email + '&code=' + code +  '&submit=' + submit;

					$.ajax({  
					  type: "POST",  
					  url: $("#contact_form").attr("action"),  
					  data: dataString,  
					  success: function(response) {
					  if(response == '0') {
					    $("#form_info").text(form_error);						
					  } else if (response == '1') {
					    $("#form_info").text(form_success);
					    $("#contact_form input, #contact_form textarea").val('');  
					  } else {
					    $("#form_info").text(response);
					  }
				    	subject = '';
					message = '';
					name = '';
					phone = '';
					mobile = '';
					email = '';
					submit = '';
					  }
					   
					});  

					return false;
				});

				init_links();
		    	//$("a").not(".b_close, #point_left, #point_right, .our_work_block a").click(execute_a);
				}
			});
		//init_links();
	} else {
		window.location.hash = 'home';
	}
}
