function ResizerClass()
{

	this.resizeObject = null;
	this.resizeObjectType = null;

	this._init = function(o) 
	{
		var owner = this;
		var o = jQuery(o);
		
		var params = {
			containment: '.headerin'
		}

		if(o.attr('id')=='logo')
		{
			jQuery.extend(
				params, 
				{
					alsoResize: '#logo img',
					aspectRatio: true
				}
			);
			owner.resizeObjectType = 'logo_size';
		}
		else if(o.hasClass('slogan'))
		{
			owner.resizeObjectType = 'slogan_size';
		}
		else if(o.attr('id')=='header')
		{
			this.headerCustomHeightEventListener();
			return;
		}
		else 
		{
			return;
		}
		
		jQuery(o).resizable(
			jQuery.extend(
				params,
				{
					start: function()
					{
						owner.resizeObject = o;
					},
					stop: function(event, ui) 
					{
						if(!owner.resizeObject) owner.resizeObject = jQuery(findEventOwner(event));
						if(!owner.resizeObject) return;
						if(!loadedJSON) return;
						
						connectingShow();
						var o = owner.resizeObject;
						var d = owner.resizeObjectType + '_x=' + o.width() + '&' + owner.resizeObjectType + '_y=' + o.height();
						$.ajax({
							type: "POST",
							url: "/ll/common/_ajax_save_header_options",
							data: d,
							success: function( out ){
								loadedJSON = true;
								if(owner.resizeObjectType=='logo_size')
								{
									var i=jQuery('#logo img');
									i.attr({src:i.attr('src').split('?').shift() + '?' + new Date().getTime()});
								}
								owner.resizeObject = null;
								connectingHide();
							}
						});	
					}
				}
			)
		);
	}
	
	/*
	*	Need for header resize
	*/
	this.headerCustomHeightEventListener = function()
	{
		var stick = jQuery('.height-icon');
		var owner = this;

		stick.mousedown(function(){
			owner.resizeObject = this;
			var eFixed = new Array;
			jQuery('#header .ui-draggable').each(function(){
				var p = {
					el		: jQuery(this),
					height	: jQuery(this).height(),
					top		: jQuery(this).position().top,
					bottom	: jQuery(this).position().top + jQuery(this).height()
				}
				eFixed[eFixed.length] = p;
			});
			
			jQuery(document).mousemove(function(e){
				var m = Drag.__mouseXY(e);
				var um = jQuery('#userMenuWrap').height();
				
				var h = (m[1]-um);
				//stick.css({top:h+'px'});
				jQuery('#header .headerin').css({height:h+'px'});

				if(h%3) for(x in eFixed){
					
					if(eFixed[x].bottom > h){
						eFixed[x].bottom = h;
						eFixed[x].top = h - eFixed[x].height;
						eFixed[x].el.css({top:(h - eFixed[x].height) + 'px'});
					}
					if(eFixed[x].top <= 0){
						eFixed[x].top = 0;
						eFixed[x].bottom = eFixed[x].height;
						eFixed[x].el.css({top:'0px'});
					}
				};
			}).mouseup(function(){
				jQuery(document).unbind('mousemove');
				jQuery(document).unbind('mouseup');
				
				if(!loadedJSON) return;
				//if(!owner.resizeObject) return;
				connectingShow();
				
				Drag.__savePositionsFromTemplate();

				owner.resizeObject = null;
				rebindAll();
			});
			
		});
		
	}
}


var Resizer=new Object;

// .... lunched from cpanel.js:244
function ResizerStart(o)
{
	Resizer = new ResizerClass();
	Resizer._init(o);
}
