library.prototype.default_link="/ajax";
var getHost=new tools.Url().host;
var Menu=Class({
	name:"Menu",
	implements:[tools.browser],
	constructor:function(){
		this.menu0();
		this.menu();
	},
	private:{
		menu0PositionX:"0px",
		menu0PositionY:"-55px",
		menu0:function(){
			$("div.menu_level0").hover(this.menu0_hoverOn,this.menu0_hoverOff);
			$("div.menu_level0").click(this.menu0_click);
			$("div.menu_now").unbind("click",this.menu0_click);
			$("div.menu_now").trigger("mouseenter");
			$("div.menu_now").unbind("mouseenter", this.menu0_hoverOn);
			$("div.menu_now").unbind("mouseleave", this.menu0_hoverOff);
		},
		menu0_hoverOn:function(e){
			var $$=$(e.currentTarget);
			var position;
			if(this.IE){
				$$.css({
					"background-position-y" : this.menu0PositionY
				});
			}
			else{
				var position=$$.css("background-position").match(/-?[0-9]+(px|%)/ig);
				if(position){
					this.menu0PositionX=position[0];
				}
				$$.css({
					"background-position" : this.menu0PositionX+" "+this.menu0PositionY
				});
			}
		},
		menu0_hoverOff:function(e){
			var $$=$(e.currentTarget);
			if(this.IE){
				$$.css({
					"background-position-y" : "0px"
				});
			}
			else{
				$$.css({
					"background-position" : this.menu0PositionX+" 0px"
				});
			}
		},
		menu0_click:function(e){
			window.location=$(e.currentTarget).find("> a").attr("href");
		},
		menu:function(){
			$("div.menu_level0,div.menu_item_submenu").hover(this.menu_hoverOn,this.menu_hoverOff);
			if(this.IE8){
				$("div.menu_item_submenu").each(function(){
					var $$=$(this);
					$$.bind({
						mouseenter:function(){
							var timer=new tools.Timer(1,1);
							timer.bind("timer",function(){
								$$.parents("div.menu_item_child").find("> div").css({ opacity:.9 });
							});
							$$.parents("div.menu_item_child").find("> div").css({ opacity:.91 });
							if(!$(this).hasClass("now-submenu")){
								$$.addClass("menu_item_child_hover");
							}
							timer.start();
						},
						mouseleave:function(){
							if(!$(this).hasClass("now-submenu")){
								$$.removeClass("menu_item_child_hover");
							}
						}
					});
				});
			}
			else{
				$("div.menu_item_submenu").each(function(){
					if(!$(this).hasClass("now-submenu")){
						$(this).classHover("menu_item_child_hover");
					}
				});
			}
			$("div.now-submenu").addClass("menu_item_child_hover");
			$("div.now-submenu").unbind("click",this.menu_click);
		},
		menu_hoverOn:function(e){
			var parents=$("div.menu_level0");
			var $$=$(e.currentTarget);
			var fromSubmenu=$$.hasClass("menu_item_submenu");
			var childbox=$$.find("> div.menu_item_child");
			var child=childbox.find("> div.submenu_inbox > div.menu_item_submenu");
			var index=!fromSubmenu ? $("div.menu_level0").index(this) : $("div.menu_level0").index( $$.parents("div.menu_level0").get(0) );
			var position=$$.position();
			var width=$$.width();
			var height=fromSubmenu ? $$.height() : $("div.menu_level0").height();
			var top;
			var left;
			if(child.length>0){
				if(index<=Math.ceil(parents.length/2)){
					top=fromSubmenu ?
						position.top-20 :
						position.top+height-6;
					left=fromSubmenu ?
						position.left+$$.parent().width()-2 :
						-Math.round((childbox.width()-$$.width())/2)-9;
				}
				else{
					top=fromSubmenu ?
						position.top-20 :
						position.top+height-6;
					left=fromSubmenu ?
						position.left-$$.parent().width()+2 :
						-Math.round((childbox.width()-$$.width())/2);
				}
				childbox.show();
				childbox.css({
					top : top,
					left : left
				});
				if(!this.IE||this.IE9){
					childbox.css({
						opacity : !fromSubmenu ? .9 : 1
					});
				}
				if(!fromSubmenu){
					$("<div>&nbsp;</div>").css({
						"font-size":"0px",
						position:"absolute",
						width:childbox.width(),
						height:10,
						top:-5
					}).prependTo(childbox[0]);
				}
				if(this.IE){
					if(!fromSubmenu){
						if(!childbox.find("div.menu-fix")[0]){
							$("<div class='menu-fix'>&nbsp;</div>").css({
								"font-size":"0px",
								position:"absolute",
								"background-color":"#30302f",
								width:childbox.width(),
								height:9
							}).prependTo(childbox[0]);
							$("<div class='menu-fix'>&nbsp;</div>").css({
								"font-size":"0px",
								position:"absolute",
								"background-color":"#30302f",
								bottom:0,
								width:childbox.width(),
								height:9
							}).appendTo(childbox[0]);
						}
						childbox.css({
							backgroundColor:"transparent"
						});
					}
				}
				if((this.IEMask^this.IE6Id^this.IE9Id) & this.currentIEId){
					childbox.find("div").css({ opacity:.9 });
				}
				if(this.IE6){
					(function(childbox){
						var width=130;
						var item=childbox.find("> div.submenu_inbox > div.menu_item_submenu");
						for(var i=0;i<item.length;i++){
							if($(item[i]).width()>width){
								width=$(item[i]).width();
							}
						}
						item.width(width);
						childbox.find("> div.submenu_inbox").width(width);
					})(childbox);
				}
			}
			if(fromSubmenu){
				$$.find("div.submenu_arrow").remove();
			}
		},
		menu_hoverOff:function(e){
			var $$=$(e.currentTarget);
			var childbox=$$.find("> div.menu_item_child");
			var child=childbox.find("> div.submenu_inbox > div.menu_item_submenu");
			var fromSubmenu=$$.hasClass("menu_item_submenu");
			var index=!fromSubmenu ? $("div.menu_level0").index(this) : $("div.menu_level0").index( $$.parents("div.menu_level0").get(0) );
			if(child.length>0){
				childbox.hide();
			}
		},
		menu_click:function(e){
			window.location=$(e.currentTarget).find("> a").attr("href");
		}
	}
});
var Main=Class({
	name:"Main",
	implements:[tools.browser],
	constructor:function(){
		$(document).ready(this.init);
	},
	private:{
		init:function(){
			this.image();
			new Menu();
			if(!this.IE6){
				$("#left_arr,#right_arr").classHover("arr_hover");
			}
			else{
				$("#left_arr").bind({
					mouseenter:function(){
						this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=http://"+getHost+"/styles/standart/img/left_arr2.png)";
					},
					mouseleave:function(){
						this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=http://"+getHost+"/styles/standart/img/left_arr1.png)";
					}
				});
				$("#right_arr").bind({
					mouseenter:function(){
						this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=http://"+getHost+"/styles/standart/img/right_arr2.png)";
					},
					mouseleave:function(){
						this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=http://"+getHost+"/styles/standart/img/right_arr1.png)";
					}
				});
			}
			var order_window=new order_site();
			$("#temper").click(function(e){
				e.preventDefault();
				order_window.open();
			});
			order_window.bind("OK",this.sendOrder);
			NEWS_plugin_1_reload=NEWS_plugin_2_reload=this.newsReload;
		},
		image:function(){
			with(new ui.fview($("#content"))){
				init();
				mode_switch=false;
			}
			$("a[href$=png], a[href$=jpg], a[href$=jpeg], a[href$=gif]").find("img").bind({
				mouseenter:function(){
					$(this).css({opacity:.85});
				},
				mouseleave:function(){
					$(this).css({opacity:1});
				}
			});
		},
		newsReload:function(r,page){
			$("#content").html(r.html);
		},
		sendOrder:function(e,o,a,windowOrder){
			if(windowOrder.validate){
				windowOrder.winJquery.hide();
				$.ajj({
					type 	: "email2",
					name	: $("#order_window_name").val(),
					email	: $("#order_window_email").val(),
					tel		: $("#order_window_phone").val(),
					org		: $("#order_window_org").val(),
					sphere	: $("#order_window_sphere").val(),
					text		: $("#order_window_description").val()
				}, function(r){
					var timer=new tools.Timer(5000,1);
					$("#order_window_name")[0].validate.val = "";
					$("#order_window_email")[0].validate.val = "";
					$("#order_window_phone")[0].validate.val = "";
					try{
						$("#order_window_org")[0].validate.val = "";
						$("#order_window_sphere")[0].validate.val = "";
					}
					catch(err){}
					$("#order_window_description")[0].validate.val = "";
					$("#order_window_name,#order_window_email,#order_window_phone,#order_window_org,#order_window_sphere,#order_window_description").val("");
					timer.bind("timerComplete",function(){
						return (function(){
							$("#succ_order").remove();
							this.shadowRemove();
						}).call(windowOrder);
					});
					$("<div id='succ_order' style='position:absolute;width:828px;z-index:1001;padding:10px;background-color:#000;top:250px;'>"+
					LANG.tmp12+
					"</div>")
					.css({
						opacity:.75,
						"text-align" : "center",
						left:parseInt($(window).scrollLeft()+Math.abs(Math.round(($(window).width()/2)-(828/2)))),
						color:"#fff"
					})
					.appendTo("body");
					timer.start();
				},
				function(r){
					windowOrder.shadowRemove();
				});
			}
		}
	}
});
var order_site=Class({
	name:"order_site",
	parent:ui.window_decorator,
	constructor:function(){
		this.Super();
		if(this.winJquery){
			$("div.order_window_close").classHover("order_window_close_hover");
			$("div.order_window_ok").classHover("order_window_ok_hover");
			$("#order_line").css("opacity","0.5");
			$("input.order_window_input").classFocus("hover_input");
			$("textarea.order_window_textarea").classFocus("hover_textarea");
			$("#organization").click(this.organization);
			$("#private_person").click(this.private_person);
			$("#order_window_name")[0].validate={
				regexp : /.{2,}/,
				alert : LANG.tmp4,
				val : "",
				first : LANG.tmp5,
				"class" : "alert_input"
			}
			$("#order_window_org")[0].validate={}
			$("#order_window_sphere")[0].validate={}
			$("#order_window_phone")[0].validate={
				regexp : /.{2,}/,
				alert : LANG.tmp6,
				val : "",
				first : LANG.tmp7,
				"class" : "alert_input"
			}
			$("#order_window_email")[0].validate={
				regexp : /^[-._a-z0-9]+@(?:[a-z0-9][-a-z0-9]+\.)+[a-z]{2,6}$/i,
				alert : LANG.tmp8,
				val : "",
				first : LANG.tmp9,
				"class" : "alert_input"
			}
			$("#order_window_description")[0].validate={
				regexp : /.{2,}/,
				alert : LANG.tmp10,
				val : "",
				first : LANG.tmp11,
				"class" : "alert_textarea"
			}
			this.validate_exec=this.winJquery.find("div.order_window_box").validate(this._validate);
		}
	},
	public:{
		cssClass:"order_window",
		ok:function(){
			var array = [];
			var object = {};
			this.winJquery.find("input[type=text], input[type=checkbox]:checked, input[type=radio]:checked, textarea, select").each(function(){
				array.push($(this).val() );
				object[$(this).attr("id")] = $(this).val();
			});
			this.validate_exec();
			this.dispatch("OK",[object,array,this]);
		}
	},
	protected:{
		html:
		"<div class='{class} window'>"+
			"<div class='{class}_header'>"+LANG.order_site+"</div>"+
			"<div class='{class}_close close'>&nbsp;</div>"+
			"<div class='{class}_box'>"+
			"<div style='text-align:right;margin-right:15px;'>"+LANG.tmp1+"</div>"+
				"<br/><div class='{class}_line'><label class='{class}_label'>"+LANG.name+"</label><input type='text' class='{class}_input' id='{class}_name'/></div>"+
				"<div class='{class}_line' id='order_line'><label class='{class}_label'>"+LANG.organization+"</label><input type='text' class='{class}_input' readonly='readonly' id='{class}_org'/></div>"+
				"<div class='{class}_line'><label class='{class}_label'>"+LANG.tmp2+"</label><input type='text' class='{class}_input' id='{class}_sphere'/></div>"+
				"<div class='{class}_line'><label class='{class}_label'>"+LANG.telefon+"</label><input type='text' class='{class}_input' id='{class}_phone'/></div>"+
				"<div class='{class}_line'><label class='{class}_label'>"+LANG.email+"</label><input type='text' class='{class}_input' id='{class}_email'/></div>"+
				"<div class='{class}_line'><label class='{class}_label'>"+LANG.work+"</label><textarea class='{class}_textarea' id='{class}_description'></textarea></div>"+
			"</div>"+
			"<div class='{class}_ok ok'>"+LANG.send+"</div>"+
		"</div>"
	},
	private:{
		organization:function(e){
			var $$=$(e.currentTarget);
			if(!$$.hasClass("order_type")){
				$$.css({
					"opacity":1,
					"font-weight":"bold",
					"text-decoration":"none"
				});
				$("span.order_type").css({
// 					"opacity":.5,
					"font-weight":"normal",
					"text-decoration":"underline"
				});
				$("#order_line").css("opacity",1);
				$("#order_window_org").removeAttr("readonly");
				$("span.order_type").removeClass("order_type");
				$$.addClass("order_type");
				$("#order_window_org")[0].validate={
					regexp : /.{2,}/,
					alert : LANG.tmp3,
					val : "",
					first : "",
					"class" : "alert_input"
				}
				$("#order_window_org").unbind("focusin keyup");
				$("#order_window_org").focusin(function(){
					$(this).val(validate.val);
					$(this).removeClass(validate["class"]);
				});
				$("#order_window_org").keyup(function(){
					this.validate.val=$(this).val();
				});
			}
		},
		private_person:function(e){
			var $$=$(e.currentTarget);
			if(!$$.hasClass("order_type")){
				$$.css({
					"font-weight":"bold",
					"text-decoration":"none"
				});
				$("span.order_type").css({
					"font-weight":"normal",
					"text-decoration":"underline"
				});
				$("#order_line").css("opacity",.5);
				$("#order_window_org").attr("readonly","readonly");
				$("span.order_type").removeClass("order_type");
				$$.addClass("order_type");
				$("#order_window_org")[0].validate={}
				$("#order_window_org").unbind("focusin keyup");
				$("#order_window_org").removeClass("alert_input").val("");
			}
		},
		validate:false,
		_validate:function(){
			this.validate=true;
		},
		validate_exec:null
	}
});
