(function($){
	$.fn.orderbox = function(options){
		var $mainelement = $(this);
		// настройки по умолчанию
		var options = $.extend({
			handler: '', // дирректория ajax-обработчика
			action: 'order', // действие, передаваемое обработчику
			loader: '/template/ico/loader.gif' //изображение загрузчика
		},options);

		$('div.edit',this).click(function(){
				var element = $(this).parent('div');
				if($('>ul',element).height() > 150) {$('>ul',element).height(150); $('>ul',element).width($('>ul',element).width()+10);}
				$('>ul li',element).hover(function(){
					if($(this).attr('rec_id')!='search') $(this).css('background-color', '#749a2c').attr('selected', 'selected');
				}, function(){
					if($(this).attr('rec_id')!='search') $(this).css('background-color', 'transparent').removeAttr('selected');
				});
				$(element).hover(function(){
				}, function(){
					/*$('ul li input',this).val('');
					$('ul li',this).show();
					$('ul',element).hide(); 
					$('div.jScrollPaneContainer',element).hide(); 
					$('ul',element).jScrollPaneRemove();*/
				});
				$('>ul',element).show();
				$('>div.jScrollPaneContainer',element).show();
				$('>ul',element).jScrollPane({scrollbarMargin: 0, showArrows: true});
				$('ul input',element).trigger("focus");
		});

		/*$('ul input',this).keypress(function (e){
			$ul = $(this).parent('li').parent('ul');
			switch(e.keyCode){
				case 38://UP
					if($("li[selected = 'selected']",$ul).length){
						$thisUL = $("li[selected = 'selected']",$ul);
						$prevUL = $thisUL.prev();
						if($prevUL.attr('rec_id')!='search'){
							$thisUL.css('background-color', 'transparent').removeAttr('selected');
							$prevUL.css('background-color', '#749a2c').attr('selected', 'selected');
						}
					}else{
						$thisUL = $('li:first',$ul);
						if($thisUL.attr('rec_id')=='search') $thisUL = $thisUL.next();
						$thisUL.css('background-color', '#749a2c').attr('selected', 'selected');
					}
				break;
				case 40://DOWN
					if($("li[selected = 'selected']",$ul).length){
						$thisUL = $("li[selected = 'selected']",$ul);
						$nextUL = $thisUL.next();
						if($nextUL.attr('rec_id')!='search'){
							$thisUL.css('background-color', 'transparent').removeAttr('selected');
							$nextUL.css('background-color', '#749a2c').attr('selected', 'selected');
						}
					}else{
						$thisUL = $('li:first',$ul);
						if($thisUL.attr('rec_id')=='search') $thisUL = $thisUL.next();
						$thisUL.css('background-color', '#749a2c').attr('selected', 'selected');
					}
				break;
			}
		});*/

		$('>ul li',this).click(function(){
				var element = $(this).parent('ul').parent('div').parent('div');
				if($(this).attr('rec_id')!='search'){
					var modal = $('<div></div>').appendTo(document.body);
					modal.css({height: $(document).height(),width: '100%',background: 'url('+options.loader+') center center no-repeat #000',position: 'absolute',top: 0,left: 0,opacity: 0.5,filter: 'Alpha(Opacity=50)',zIndex: 2000});
					$.post( options.handler, { action: options.action, id1: $('>div.edit',element).attr('rec_id'), id2: $(this).attr('rec_id'), parent_id: $('>div.edit',element).attr('parent_id'), page: $('>div.edit',element).attr('page') }, function(data){$('#content_admin').html(data.content); modal.remove(); init();}, "json");
				}
		});

		$('>ul li input',this).keyup(function(){
				var element = $(this).parent('li').parent('ul').parent('div').parent('div');
				var search = $(this).val();
				$.each($('ul li',element), function(){
					var str = $(this).text();
					var reg = new RegExp(search.toLowerCase(), "i");
					var result = reg.test(str.toLowerCase());
					if(!result && $(this).attr('rec_id')!='search' && $(this).attr('rec_id')!=0) $(this).hide();
					else $(this).show();
				});
				$('ul',element).jScrollPane({scrollbarMargin: 0, showArrows: true});
		});
	};
})(jQuery);

(function($){
	$.fn.multibox = function(options){
		var element = $(this);
		var selected = '';
		// настройки по умолчанию
		var options = $.extend({
			action: 'order', // действие, передаваемое обработчику
			loader: '/template/ico/loader.gif' //изображение загрузчика
		},options);

		$('>ul li',element).hover(
			function(){
				if($(this).attr('type')!=1) $(this).css('backgroundColor', '#749a2c');
			},
			function(){
				if($(this).attr('type')!=1) $(this).css('backgroundColor', 'transparent');
			}
		);

		$('>ul li',element).click(
			function (){
				if($(this).attr('type')==0){ $(this).css('backgroundColor', '#749a2c'); $(this).attr('type',1); }
				else{ $(this).css('backgroundColor', 'transparent'); $(this).attr('type',0); }
				selected = '';
				$.each($("li[type=1]",element), function(){ selected += $(this).attr('rec_id')+'|'; });
				$('>input',element).val(selected);
			}
		);

		element.jScrollPane({scrollbarMargin: 0, showArrows: true});
		element.parent('div').css({position: 'relative', marginBottom: '14px'});

	};
})(jQuery);

(function($){
	$.fn.checkbox = function(options){
		var element = $(this);
		var selected = '';
		// настройки по умолчанию
		var options = $.extend({
			check: '/template/ico/on.gif', // стоит галочка
			uncheck: '/template/ico/off.gif' // не стоит галочка
		},options);

		$('>ul li img',element).click(
			function (){
				if($(this).parent('li').attr('rel')==0){ $(this).parent('li').attr('rel',1); $(this).attr('src',options.check); }
				else{ $(this).parent('li').attr('rel',0); $(this).attr('src',options.uncheck); }
				selected = '';
				$.each($("li[rel=1]",element), function(){ selected += $(this).attr('val')+'|'; });
				$('>input',element).val(selected);
                if($('>input',element).valid() == 1) 1;
			}
		);
	};
})(jQuery);


function listbox(obj){
	jQuery(function($){
		$('ul', obj).css('margin-bottom','-'+$(this).height()+'px');
		$('ul li',obj).click(function(){$(this).parent('ul').siblings('div').text($(this).text()); $('input',$(this).parent('ul').parent('div')).val($(this).attr('rel')); $(this).parent('ul').siblings('div').css('background','url(/template/ico/select.gif) top right no-repeat #749a2c'); $(this).parent('ul').hide(); if($('input',$(this).parent('ul').parent('div')).valid() == 1) 1;});
		$('ul li',obj).hover(function(){$(this).css('background-color', '#749a2c');}, function(){$(this).css('background-color', 'transparent');});
		obj.hover(function(){}, function(){$('div',this).css('background','url(/template/ico/select.gif) top right no-repeat #749a2c'); $('ul',this).hide();});
		$('div',obj).click(function(){
            var $div = $(this).parent('div');
			if($('ul',$div).width() < $(this).width()) $('ul',$div).width($(this).width()-2);
			if($('ul',$div).height() > 200) $('ul',$div).height(200);
			$(this).css('background','url(/template/ico/select_s.gif) top right no-repeat #749a2c');
			$('ul',$div).show();
		});
	});
}

function info(obj, speed){
		obj.hover(
			function(){$('div',this).show();},
			function(){$('div',this).hide();}
		);
}