library.prototype.default_link="/ajax";
var getHost=new tools.Url().host;
var search;
var tag;
Class({
	name:"Clock",
	constructor:function(){},
	public:{
		clockElement:false,
		reloadTime:1000,
		init:function(){
			if(this.clockElement){
				with(this.timer){
					bind("timer",this.reload);
					start();
				}
			}
		}
	},
	private:{
		timer:"~new tools.Timer(this.reloadTime)~",
		reload:function(){
			with(new Date()){
				var seconds=getSeconds();
				var minute=getMinutes();
				var hour=getHours();
				var date=getDate();
				var month=getMonth();
				var year=getFullYear();
				this.clockElement.html(
					"<span id='hour'>"+hour+"</span>"+
					"<span id='seconds'>"+(seconds%2 ? ":" : "&nbsp;")+"</span>"+
					"<span id='minute'>"+(minute/10>=1 ? minute : ("0"+minute))+", </span>"+
					"<span id='date'>"+date+" </span>"+
					"<span id='month'>"+this.mountsName[month]+" </span>"+
					"<span id='year'>"+year+"</span>"
				);
			}
		},
		mountsName:["января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"]
	}
});
var Menu=Class({
	name:"Menu",
	implements:[tools.browser],
	constructor:function(){
		this.menu();
	},
	private:{
		menu0PositionX:"0px",
		menu0PositionY:"-55px",
		menu:function(){
			$("div.menu_level0_block,div.menu_item_submenu").hover(this.menu_hoverOn,this.menu_hoverOff);
			$("div.menu_level_block").classHover("menu_level_block_hover");
		},
		menu_hoverOn:function(e){
			var $$=$(e.currentTarget);
			var parents=$("div.menu_level0_block");
			var fromSubmenu=$$.hasClass("menu_item_submenu");
			var childbox=$$.find("> div.menu_item_child");
			var children=childbox.find("> div.menu_level_block");
			var index=!fromSubmenu ? $("div.menu_level0_block").index(e.currentTarget) : -1;
			var position=$$.position();
			var width=$$.width();
			var height=fromSubmenu ? $$.height() : $("div.menu_level0_block").height();
			var top=-999;
			var left=-999;
			if(children.length>0){
				if(index<=Math.ceil(parents.length/2)){
					top=(!fromSubmenu ? position.top+height : -999);
					left=(!fromSubmenu ? position.left : -999);
				}
				else{
					top=(!fromSubmenu ? position.top+height : -999);
					left=(!fromSubmenu ? position.left+width-childbox.outerWidth() : -999);
					childbox.find("div.menu_triangle").css({
						left:"auto",
						right:0
					});
				}
				childbox.css({
					display:"block",
					top:top,
					left:left
				});
				childbox.find("> div").css({
					opacity:.9
				});
				if(this.IE6 || this.IE7){
					children.each(function(index,element){
						element=$(element);
						if(element.width()>width){
							width=element.width();
						}
					});
					children.width(width);
				}
			}
		},
		menu_hoverOff:function(e){
			var $$=$(e.currentTarget);
			var fromSubmenu=$$.hasClass("menu_item_submenu");
			var childbox=$$.find("> div.menu_item_child");
			var children=childbox.find("> div.menu_level_block");
			var index=!fromSubmenu ? $("div.menu_level0_block").index(e.currentTarget) : -1;
			if(children.length>0){
				childbox.hide();
			}
		}
	}
});
var Main=Class({
	name:"Main",
	implements:[tools.browser],
	constructor:function(){
		$(document).ready(this.init);
	},
	private:{
		init:function(){
			var url=new tools.Url();
			this.image();
			new Menu();
			with(new Clock()){
				clockElement=$("#clock");
				init();
			}
			if(this.IE8){
				$("div.menu2_level_block:last-child").css("border-bottom","0px none");
			}
			$("input.submit").classHover("submit_hover");
			$("#search").submit(this.search);
			if($("#search_plugin input.input[type=text][name=query]").val()){
				if($("#search_plugin input.input[type=text][name=query]").val().match(/.{3,}/)){
					search=$("#search_plugin input.input[type=text][name=query]").val();
				}
			}
			if(url.query){
				if(url.query.match(/tag=(.+)/i)){
					tag=url.query.match(/tag=(.+)/i)[1];
				}
			}
			SEARCH_reload=this.searchPage;
			NEWS_plugin_2_reload=this.newsPage;
			FAQ_plugin_reload=this.faqPage;
			if ($("#content_index").length > 0){
				swfobject.embedSWF("/files/banner/lor_baner.swf", "ms_banner_holder", "586", "400", "9.0.0");
			}
		},
		searchPage:function(r,page){
			$("#search_plugin").replaceWith(r.html);
		},
		newsPage:function(r,page){
			$("#content").html(r.html);
		},
		faqPage:function(r,page){
			$("div.FAQ").html(r.html);
		},
		image:function(){
			with(new ui.fview($("#content"))){
				init();
				mode_switch=false;
			}
			with(new ui.fview($("#index_feedback"))){
				init();
				mode_switch=false;
			}
			with(new ui.fview($("#partners"))){
				init();
				mode_switch=false;
			}
			if($("#content a[href*='youtube']")[0]){
				with(new ui.fview($("nothing"))){
					flashSelector="#content a[href*='youtube.com']";
					init();
				} 
			}
			$("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});
				}
			});
		},
		search:function(e){
			var url;
			with(url=tools.Url()){
				file="search";
				query="query="+$("input.input[type=text][name=query]").val();
				if($("input.input[type=text][name=query]").val().match(/.{3,}/)){
					go();
				}
			}
			return false;
		}
	}
});
