
	$(document).ready(function(){
		
		//поисковая форма
		$("#sitesearch-form").submit(function(){
			var text = $("#sitesearch-form [name='text']");
			text.val('"' + text.val() + '"');
		});
		
		$.datepicker.regional['ru'] = {
			closeText: 'Закрыть',
			prevText: '&#x3c;Пред',
			nextText: 'След&#x3e;',
			currentText: 'Сегодня',
			monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
			'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
			monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
			'Июл','Авг','Сен','Окт','Ноя','Дек'],
			dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
			dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
			dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
			weekHeader: 'Не',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['ru']);
		
	});
	
	function MessageBox(options) //options: title, content, width, height, element_selector
	{		
		if (!options.title) options.title = "";
		if (!options.content) options.content = "";
		var element = '<div class="message-box" title="'+ options.title +'">'+ options.content +'</div>';
		
		if (!options.width) options.width = 400;
		if (!options.height) options.height = 200;
		if (options.element_selector)
			element = options.element_selector;

		$(element).dialog({
			modal: true,
			width: options.width,
			height: options.height,
			close: function(event, ui) {
				$(this).dialog("destroy");
			},
			buttons: {
				Ok: function() {
					$(this).dialog("destroy");
				}
			}
		});
	}

	function SubmitLiteSearch()
	{
		document.getElementById("search_text").value =	document.getElementById("real_search_text").value;
		document.forms["lite_search"].submit();
		return false;
	}
	
	function format_number(number)
	{
		var result = "";
		number = parseInt(number).toString();
		for (var i=number.length-1, j=0;i>=0;i--,j++)
		{
			if (j % 3 == 0) {
				result = " " + result;
			}
			result = number[i] + result;
		}
		return result;
	}
	
	function SubmitLiteSearchByEnter(e)
	{
		if (e.which == 13) {
			SubmitLiteSearch();
		}
	}
	
	function NormalizeUrl(url)
	{
		re = new RegExp("[\/]{2,}", "g");
		return url.replace(re, "/"); 
	}
	
	function DropMenu()
	{
		this.container = "";
		//this.hide_timer = null;
		
		this.Init = function(options)
		{
			var obj = this;
			this.container = options.container;
			$(this.container + " .title").click(function(){
				obj.ShowMenu();
			});
		};

		/*this.StartTimer = function()
		{
			var obj = this;
			this.hide_timer = setTimeout(function(){ obj.HideMenu(); }, 400);
		};

		this.ClearTimer = function()
		{
			if(typeof this.hide_timer == "number") {
				clearTimeout(this.hide_timer);
				//delete this.hide_timer;
				this.hide_timer = null;
			}
		};*/

		this.ShowMenu = function()
		{
			var obj = this;
			$(this.container + " .items").show().position({
				of: $(this.container + " .title"),
				my: "left top",
				at: "left top",
				offset: 0
			});
			$(this.container + " .items").mouseleave(function(){
				//obj.StartTimer();
				obj.HideMenu();
			});
			/*$(this.container + " .items").mouseenter(function(){
				obj.ClearTimer();
			});*/
		};

		this.HideMenu = function()
		{
			$(this.container + " .items").hide();
			//this.ClearTimer();
		};

	}
	
	var JsUrl = {
			
		jsurl_params : [],
		current_hash : false,
		
		watch_timer : null,		
		onUrlChange : null,
		
		getLocationHash : function()
		{
			return location.hash.substring(1, location.hash.length);
		},
		
		ParseHash : function(address)
		{
			var hash = (address) ? address : this.getLocationHash();
			this.current_hash = hash;
			this.jsurl_params = (hash == "") ? [] : hash.split("/", 10);
		},
		
		GetParam : function(num)
		{
			if (this.current_hash === false || this.current_hash != this.getLocationHash()) this.ParseHash();
			return (this.jsurl_params[num]) ?  this.jsurl_params[num] : "";
		},
		
		StartUrlWatch : function()
		{
			var o = this;
			this.watch_timer = setInterval(function() {o.UrlWatch();}, 200);
		},		
		StopUrlWatch : function()
		{
			if(typeof this.watch_timer == "number") {
				clearInterval(this.watch_timer); 
				delete this.watch_timer;
			}
		},
		UrlWatch : function()
		{
			if (this.current_hash !== this.getLocationHash()) {
				this.ParseHash();
				if (this.onUrlChange != null)
					this.onUrlChange.method.call(this.onUrlChange.object);
			}
		}
	}
