;	(function($){

$.volux = {

	go:
		function () {
			$('html').attr('id', 'js')
		;	$.getScript($.volux.data.jsHost+'plugin/xLazyLoader.js', function(){
				if (!$.volux.data.DEBUG) {
					$.xLazyLoader({
						js: [
							$.volux.data.jsHost+'volux/debug.js'
						]
					,	name: 'debug'
					,	load: $.volux.logic.go
					})
				} else {
					$.xLazyLoader({
						js: [
							$.volux.data.jsHost+'volux/debug.js'
						]
					,	css: [
							$.volux.data.cssHost+'debug.css'
						]
					,	name: 'debug'
					,	load: function(){
							$.log('debug start')
						;	$.volux.logic.go()
						}
					})
				}
			})
		}

,	logTimers:
		function () {
			if (!$.volux.data.DEBUG) {
				return false
			}
			$.each($.volux.timers, function(key, val){
				if (key !== 'last') {
					$.log(key+': '+val)
				}
			})
		}


,	loadLogin:
		function() {
			$.log('Загрузка формы логина');
			if ($.volux.login) {
				$.volux.login.load()
			;	return true
			}
			$.xLazyLoader('destroy','dialog');
		;	$.xLazyLoader({
				css: [
						$.volux.data.cssHost + 'ui/'+$.volux.data.uiTheme+'jquery-ui.css'
					,	$.volux.data.cssHost + 'login.css'
				]
			,	js: [
						$.volux.data.jsHost+'ui/current.min.js'
					,	$.volux.data.jsHost+'volux/login.js'
					,	$.volux.data.jsHost+'md5.js'
				]
			,	name: 'dialog'
			,	load: function(){
					$.volux.login.load()
				}
			});
		}


,	infobox:
		function(head, message) {
			if ($('#infobox').length) {
				$('#infobox').attr({title:head}).find('p').html(message).end().dialog('open')
			;	return true
			}
		;	$.xLazyLoader('destroy','dialog');
		;	$.xLazyLoader({
				css: $.volux.data.cssHost + 'ui/'+$.volux.data.uiTheme+'jquery-ui.css'
			,	js:  $.volux.data.jsHost+'ui/current.min.js'
			,	name: 'dialog'
			,	load: function(){
					$('<div id="infobox" title="'+head+'"><p>'+message+'</p></div>')
					.appendTo('body').dialog({
						modal: false
					,	resizable: true
					,	height: 350
					,	width: 400
					,	close: function() {
							$.volux.dialog.close('#infobox')
						}
					})
				}
			})
		}


,	ask:
		function(message, callback) {
			if (!$('#ask').length) {
				$('<div id="ask" title="Вопрос"><p></p></div>')
				.appendTo('body')
			}
			$.xLazyLoader('destroy','dialog');
		;	$.xLazyLoader({
				css: $.volux.data.cssHost + 'ui/'+$.volux.data.uiTheme+'jquery-ui.css'
			,	js:  $.volux.data.jsHost+'ui/current.min.js'
			,	name: 'dialog'
			,	load: function(){
					$('#ask')
					.find('p')
						.html(message)
						.end()
					.dialog({
						modal: true
					,	resizable: false
					,	height: 150
					,	width: 280
					,	close: function() {
							$.volux.dialog.close('#ask')
						}
					,	buttons: {
							'Yes': function() {
								callback()
							;	$.volux.dialog.close('#ask')
							}
						,	'No': function() {
								$.volux.dialog.close('#ask')
							}
						}
					});
				}
			});
		}

,	alert:
		function(message) {
			if (!$('#alert').length) {
				$('<div id="alert" title="Внимание!"><p></p></div>')
				.appendTo('body')
			}
			$.xLazyLoader('destroy','dialog');
		;	$.xLazyLoader({
				css: $.volux.data.cssHost + 'ui/'+$.volux.data.uiTheme+'jquery-ui.css'
			,	js:  $.volux.data.jsHost+'ui/current.min.js'
			,	name: 'dialog'
			,	load: function(){
					$('#alert')
					.find('p')
						.html(message)
						.end()
					.dialog({
						modal: true
					,	resizable: false
					,	close: function() {
							$.volux.dialog.close('#alert')
						}
					,	height: 120
					,	width: 240
					,	buttons: {
							'Ok': function() {
								$.volux.dialog.close('#alert')
							}
						}
					});
				}
			});
		}

,	dialog: {

		close:
			function(id) {
				$(id).dialog('destroy').remove()
			;	$.log('div '+id+' remove from body')
			}

	}

,	logOut:
		function(){
			$.volux.ask('Вы уверены?', function() {
				location.href = '/logout.php'
			})
		}


,	goHome:
		function() {
			location.href = '/'
		}


,	waitIndicator:
		function(item) {
			jQuery().ajaxStart(function() {jQuery(item).show()})
		;	jQuery().ajaxStop(function() {jQuery(item).hide()})
		}


,	blur:
		function() {
			$('a').bind('focus', function() {
				this.blur()
			});
		}


,	getToken:
		function(id) {
			$.get('/token.php', function(txt){
				$(id).append('<input type="hidden" name="token" value="'+txt+'" />')
			})
		;	return $(id)
		}


,	clearForId:
		function(str) {
			var s = new String(str)
		;	return s.replace('\/', '_').replace('-', '_').replace('\.', '_')
		}


,	encodeString:
		function(s) {
			return escape(s).replace(new RegExp('\\+','g'), '%2B')
		}

,	preloadImages: // $.volux.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");
		function() {
			for(var i = 0; i<arguments.length; i++) {
				$("<img>").attr("src", arguments[i])
			}
		}

,	dummyCallback:
		function(){
		}

}
;	$.volux.logic = {

	go:
		function() {
		}
}

;	$.fn.voluxSecuredForm = function() {
		return $.volux.getToken(this)
	}

// @example $('#nav').hoverClass('hover')
;	$.fn.hoverClass = function(cssClass) {
	return this.each(function(){
		$(this).hover(
			function(){ $(this).addClass(cssClass) }
		,	function(){ $(this).removeClass(cssClass) }
		)
	})
}

})(jQuery);