$(document).ready(function(){
	var _boxs = $("div.box").not('.popup'), _zIndex = 0,
		_main = $('#main');
	
	_boxs.each(function(){
		$(this).css('zIndex',_zIndex);
		_zIndex++;
		$(this).mousedown(function(){
			_zIndex++;
			$(this).css('zIndex',_zIndex);
		});
	});
	
//	_boxs.draggable({
//		handle:'div.heading-c',
//		cancel:'a.btn-close',
//		containment:['auto',260,'auto',_main.height()],
//		start:function(){_boxs.disableSelection();},
//		stop:function(){_boxs.enableSelection();}
//	});
	
	// online-list
	var _active = false;
	$('#online-list li.item').each(function(){
		$(this).find('div.item-holder').click(function(){
			if (_active)
				if (_active.get(0) != $(this).parent().get(0)) _active.removeClass('active');
			if (!$(this).parent().hasClass('active')) {
				$(this).parent().addClass('active');
				_active = $(this).parent();
			} else {
				$(this).parent().removeClass('active');
				_active = false;
			}
			return false;
		});
	});
	
	$('body').mousedown(function(e){
		if(!e) e = window.event;
		var _target = (e.target || e.srcElement);
		if (!$(_target).is($('#nav'))) {
			if (!$(_target).parents('#online-list li.item').length && _active) {
				_active.removeClass('active');
				_active = false;
			}
		}
	});
});

jQuery.fn.extend({ 
        enableSelection : function() { 
                this.each(function() { 
                        this.onselectstart = function() {}; 
                        this.unselectable = "off"; 
                        jQuery(this).css('-moz-user-select', 'auto'); 
                }); 
        } 
}); 

