var left = (document.documentElement.clientWidth || document.body.clientWidth) < 800 ? "0px" : "50%";
var margin = (document.documentElement.clientWidth || document.body.clientWidth) < 800 ? "0px" : "-425px";

$(document).ready(function() {
	
	
	$("div.main").css("left", left);
	$("div.main").css("margin-left", margin);
	
	var url = document.location;
	var mas = url + "";
	var help = mas.split("/");
	var base_url = help[0] + "//" + help[2] + "/";
	
	if(help[3] == "pin3" || help[3] == "pin4" || help[3] == "pin5" || help[3] == "cryptokey")
	{
		$("#matrix").animate({"height": "show"}, "slow");
		$("span.sub_menu_spanlink").css("color", "#888888");
		$("span.sub_menu_spanlink").css("background-image", "url('/images/menu_disc_active.gif')");
	}
	
	$("span.sub_menu_spanlink").hover(function() {
		if($("#matrix").css("display") == "none")
		{
			$(this).css("color", "#888888");
			$(this).css("background-image", "url('/images/cursor_active.jpg')");
		}
	}, function() {
		if($("#matrix").css("display") == "none")
		{
			$(this).css("color", "#F27B12");
			$(this).css("background-image", "url('/images/sub_cursor_not_active.jpg')");
		}
	});
	
	$("span.sub_menu_spanlink").click(function() {
		if($("#matrix").css("display") == "none")
		{
			$("#matrix").animate({"height": "show"}, "slow");
			$(this).css("color", "#888888");
			$(this).css("background-image", "url('/images/sub_cursor_active.jpg')");
		}
		else
		{
			$("#matrix").animate({"height": "hide", "paddingBottom": 0}, "slow");
			$(this).css("color", "#F27B12");
			$(this).css("background-image", "url('/images/cursor_not_active.jpg')");
		}
	});
	
	$("#matrix_click").click(function() {
		$("span.sub_menu_spanlink").click();
	});
	
	$("#matrix_click_img").click(function() {
		$("span.sub_menu_spanlink").click();
	});
	
	$("#matrix_click").hover(function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	}, function() {
		$(this).css("color", "#888888");
		$(this).css("text-decoration", "none");
	});
	
	$("#pressure_click").click(function() {
		window.location.href = base_url + "pinlaser/";
	});
	
	$("#pressure_click").hover(function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	}, function() {
		$(this).css("color", "#888888");
		$(this).css("text-decoration", "none");
	});
	
	$("#fiscode_click").click(function() {
		window.location.href = base_url + "pinfiscode/";
	});
	
	$("#fiscode_click").hover(function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	}, function() {
		$(this).css("color", "#888888");
		$(this).css("text-decoration", "none");
	});
	
	$("#printer_video").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("#printer_video").click(function() {
		window.open(base_url + 'VideoMF4000.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#noprinter_video").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("text-decoration", "none");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("#noprinter_video").click(function() {
		window.open(base_url + 'VideoMF4000.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#noprinter_video2").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("text-decoration", "none");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("#noprinter_video2").click(function() {
		window.open('http://www.welltecuk.com/files/movies/postmate3/postmate3.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("span.video_span").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("span.video_span").click(function() {
		if($(this).attr("id") != "inline_video95")
		{
			window.open('http://www.welltecuk.com/files/movies/mf4300/MF4300.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
		}
	});
	
	$("#inline_video95").click(function() {
		window.open('http://www.welltecuk.com/files/movies/MF9500/MF9500.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("span.offline_video_span").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("#wages_offline_video_1").click(function() {
		window.open('http://www.welltecuk.com/files/movies/officemate2d/officemate2d.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#wages_offline_video_1").hover(function() {
		$(this).css("cursor", "pointer");
	});
	
	$("#offline_video_1").click(function() {
		window.open('http://www.welltecuk.com/files/movies/officemate2d/officemate2d.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#offline_video_2").click(function() {
		window.open('http://www.welltecuk.com/files/movies/postmate5/postmate5.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	
	$("#offline_video_3").click(function() {
		window.open('http://www.welltecuk.com/files/movies/postmate3/postmate3.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#offline_video_4").click(function() {
		window.open('http://www.welltecuk.com/files/movies/postmate6/postmate6.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("#offline_video_5").click(function() {
		window.open('http://www.welltecuk.com/files/movies/postmate6hd/postmate6hd.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	$("div.enter_button").click(function() {
		window.location.href = base_url + "about/";
	});
	
	$("span.integrate_span_1").hover(function() {
		$(this).css("color", "#888888");
		$(this).css("cursor", "pointer");
	}, function() {
		$(this).css("color", "#F27B12");
		$(this).css("text-decoration", "underline");
	});
	
	$("span.integrate_span_1").click(function() {
		window.open('http://www.welltecuk.com/files/movies/officemate2d/officemate2d.swf','','scrollbars=no, menubar=no, height=260, width=320, resizable=no, toolbar=no, location=no, status=no, left=400, top=300');
	});
	
	function customs_reset()
	{
		$("#company").val("");
		$("#face").val("");
		$("#phone").val("");
		$("#md2").val("");
		$("#md3").val("");
		$("#md6").val("");
		$("#md8").val("");
		$("#cmr6").val("");
		$("#cmr12").val("");
		$("#comm").val("");
	}
	
	customs_reset();
	
	$("#clear").click(function() {
		customs_reset();
	});
	
	$("#send").click(function() {
		if($.trim($("#company").val()) == "")
		{
			alert("Вы не ввели название организации");
		}
		else
		{
			if($.trim($("#face").val()) == "")
			{
				alert("Вы не ввели имя контактного лица");
			}
			else
			{
				if($.trim($("#phone").val()) == "")
				{
					alert("Вы не ввели номер телефона");
				}
				else
				{
					if($.trim($("#md2").val()) == "" && $.trim($("#md3").val()) == "" && $.trim($("#md6").val()) == "" && $.trim($("#md8").val()) == "" && $.trim($("#cmr6").val()) == "" && $.trim($("#cmr12").val()) == "")
					{
						alert("Вы не выбрали заказ");
					}
					else
					{
						var name_company = "Название компании";
						var name_face = "Контактное лицо";
						var name_phone = "Телефон";
						var name_comm = "Комментарии";
						var name_num = "Колличество бланков";
						var name_md = "МД";
						var name_subject = "Заказ бланков";
						$.post(base_url + "pub/page/", {"company": encodeURI($.trim($("#company").val())), "face": encodeURI($.trim($("#face").val())), "phone": $.trim($("#phone").val()), "md2": $.trim($("#md2").val()), "md3": $.trim($("#md3").val()), "md6": $.trim($("#md6").val()), "md8": $.trim($("#md8").val()), "cmr6": $.trim($("#cmr6").val()), "cmr12": $.trim($("#cmr12").val()), "comm": $.trim($("#comm").val()), "name_company": encodeURI(name_company), "name_face": encodeURI(name_face), "name_phone": encodeURI(name_phone), "name_comm": encodeURI(name_comm), "name_num": encodeURI(name_num), "name_md": encodeURI(name_md), "name_subject": encodeURI(name_subject)}, order_result);
					}
				}
			}
		}
	});
	
	function order_result(data)
	{
		if($.trim(data) == "send")
		{
			alert("Ваш запрос успешно отправлен");
			customs_reset();
		}
		else
		{
			alert("Ошибка при отправлении. Попробуйте еще раз");
		}
	}

});
