// ------------------------------
// Resizer
// ------------------------------
// Recolocamiento de capas pixbox
// ------------------------------

var Resizer = function(contexto, widthMin, widthMax, heightMin, heightMax){

	// Tipado fuerte
	ObjectUtils.strict([Object, Number, Number, Number, Number], arguments);
	
	// Variables privadas
	var _ct = this;
	var _seccion;
	var _banner;
	var _contenido;
	var _openWidth	= false;
	var _openHeight = false;
	var _widthMin;
	var _widthMax;
	var _heightMin;
	var _heightMax;
	var _finalHeight = 0;
	
	// Constructor
	_widthMin = widthMin;
	_widthMax = widthMax;
	_heightMin = heightMin;
	_heightMax = heightMax;
	createReferences(contexto);
	
	// Métodos privados
	function createReferences(contexto){
		_seccion = contexto;
		_banner = _seccion.find("#seccion_banner");
		_contenido = _seccion.find("#seccion_contenido");
	}
	
	// Métodos públicos
	this.resizeWidth = function(open){
		if (open) {
			_openWidth = true;
			
			if ($.browser.mozilla){
				// sin animaciones
				_banner.hide();
				_contenido.css({width: _widthMax+"px"});
				_seccion.css({ backgroundImage: "none", backgroundColor: "#ffffff" });
				if (_openHeight) _ct.resizeHeight(true);
			} else {
				// con animaciones
				_banner.fadeOut("fast", function(){
					_contenido.animate({ width: _widthMax+"px"}, "normal", function(){
						_seccion.css({ backgroundImage: "none", backgroundColor: "#ffffff" });
						if (_openHeight) _ct.resizeHeight(true);
					});
				});				
			}
			
		} else {
			if (_openHeight) this.resizeHeight(false);
			else {
				_openWidth = false;
				_seccion.css({ backgroundImage: "url(css/css_img/seccion_background.jpg)", backgroundColor: "transparent" });
				// con animaciones siempre porque se supone que se ha cerrado el flash
				_contenido.animate({ width: _widthMin+"px"}, "normal", function(){
					_banner.fadeIn("slow");
				});
			}
		}
	}

	this.resizeHeight = function(open, newHeight){
		_finalHeight = (arguments.length==2)? newHeight : (_finalHeight!=0)? _finalHeight : (open)? _heightMax : _heightMin;
		if (open){
			_openHeight = true;
			if (!_openWidth) this.resizeWidth(true);
			else {
			
				if ($.browser.mozilla){
					// sin animaciones
					_seccion.stop();
					_seccion.css({height: _finalHeight+"px"});
					_contenido.css({height: _finalHeight+"px"});
				} else {
					// con animaciones
					_seccion.animate({height: _finalHeight+"px"}, "normal");
					_contenido.animate({height: _finalHeight+"px"}, "normal");			
				}
				
				_finalHeight = 0;
			}
		} else {
			_openHeight = false;
			_contenido.css({height: _finalHeight+"px"});
			_seccion.animate({height: _finalHeight+"px"}, "normal", function(){
				if (_openWidth) _ct.resizeWidth(false);
			});
			_finalHeight = 0;
		}
	}
	
	this.resizeMoviles = function(){
		_finalHeight = _heightMin;
		_openHeight = false;
		_contenido.css({height: _finalHeight+"px"});
		_seccion.animate({height: _finalHeight+"px"}, "normal");
		_seccion.css({ backgroundImage: "none", backgroundColor: "#ffffff" });
		_finalHeight = 0;
	}
	
};