AdvertiseYellow = function(params) {
	var _self = this;	
	var _params = params;
	var _currentPosition = 0;
	var _isBack = false;
	
	this.moveForward = function(){				
		_currentPosition--;
		_isBack = true;
		loadImage();
	};
	
	this.moveNext = function(){
		_currentPosition++;
		_isBack = false;
		loadImage();
	};
	
	this.close = function(){
		_self = null;
		_params = null;
		_currentPosition = null;
		
		YAHOO.util.Event.removeListener('button_forward', 'click');
		YAHOO.util.Event.removeListener('button_next', 'click');
		YAHOO.util.Event.removeListener('button_close', 'click');
		
		if (YAHOO.util.Dom.inDocument('advertiseYellow')){
			$Util.removeChildren('advertiseYellow');
			var obj = YAHOO.util.Dom.get('advertiseYellow');
			document.body.removeChild(obj);
		}
		
		if ($Util.IsIE()){			
			enableScroll();		
			YAHOO.util.Event.removeListener(window, 'scroll', positionFixedIE);	
		}
		
		
		
	};
	
	this.show = function(){
		var _divContainer, html;
		_divContainer = $Util.CreateHtmlElement({'elm':'div','id':'advertiseYellow'});
		
				
		html = "";
		if ($Util.IsIE()){
			html+= '<div class="bg" style="filter:alpha(opacity=60)" ><!-- --></div>'; 
		} else {
			html+= '<div class="bg" ><!-- --></div>';
		}
		html+= '<table class="data" id="dataAdvertiseYellow" align="center" cellpacing="0" cellpadding="0" border="0"><tr><td>';
		html+= '  <table cellspacing="0" cellpadding="0" align="center"><tr><td id="adv_container"><img src="img/gallery/loader.gif" /></td></tr></table>';
		html+= '  <div class="separator"><!-- --></div>';
		html+= '  <table cellspacing="0" cellpadding="0" align="center" class="paginator"><tr>';
		html+= '  <td class="labelData" id="labelData">Avisos</td>';
		html+= '  <td class="button_forward" id="button_forward" title="Anterior"></td>';
		if (_params.length > 1){
			html+= '  <td class="button_nextH" id="button_next" title="Siguiente"></td>';
		} else {
			html+= '  <td class="button_next" id="button_next" title="Siguiente"></td>';
		}
		html+= '  <td class="button_close" id="button_close" title="Cerrar"></td>';
		html+= '  </tr></table>';
		html+= '</td></tr></table>';	
				
		_divContainer.innerHTML = html;		
		document.body.appendChild(_divContainer);
		
		if ($Util.IsIE()){
			var widthScreen = YAHOO.util.Dom.getDocumentWidth();
			var heightScreen = YAHOO.util.Dom.getViewportHeight();
					
			YAHOO.util.Dom.setStyle('advertiseYellow', 'position', 'absolute');
			YAHOO.util.Dom.setStyle('advertiseYellow', 'width', widthScreen + 'px');
			YAHOO.util.Dom.setStyle('advertiseYellow', 'height', heightScreen + 'px');	
			
			heightScreen = YAHOO.util.Dom.getViewportHeight();
			
			YAHOO.util.Dom.setStyle('dataAdvertiseYellow', 'width', widthScreen + 'px');
			YAHOO.util.Dom.setStyle('dataAdvertiseYellow', 'height', heightScreen + 'px');
		}
		
		YAHOO.util.Event.addListener('button_forward', 'click', _self.moveForward);
		YAHOO.util.Event.addListener('button_next', 'click', _self.moveNext);
		YAHOO.util.Event.addListener('button_close', 'click', _self.close);
		_currentPosition = 0;
		loadImage();
		_divContainer = null;
		html = null;
		
		if ($Util.IsIE()){			
			
			YAHOO.util.Event.addListener(window, 'scroll', positionFixedIE);
			positionFixedIE();
			disableScroll();	
		}
		
	};	
	
	var disableScroll = function(){
		YAHOO.util.Dom.setStyle(document.body, 'overflow', 'hidden');
	};
	
	var enableScroll = function(){
		YAHOO.util.Dom.setStyle(document.body, 'overflow', '');
	};
	
	var loadImage = function(){
		if (_currentPosition < 0){
			_currentPosition = 0;
			return;
		}
		if ((_currentPosition + 1) > _params.length){
			_currentPosition = _params.length - 1;
			return;
		}
		YAHOO.util.Dom.get("adv_container").innerHTML = '<img src="img/gallery/loader.gif" />';
		
		
		var im = new Image();
		im.src = _params[_currentPosition] + "?r=" + ((Math.random() * 10000));
		im.id = 'imgAdvertiseYellow';
				
		YAHOO.util.Event.addListener(im, 'load', replaceImageAdv);
		
	};
	
	var replaceImageAdv = function(){				
		YAHOO.util.Event.removeListener('imgAdvertiseYellow', 'load');
		
		var widthScreen = YAHOO.util.Dom.getViewportWidth();
		var heightScreen = YAHOO.util.Dom.getViewportHeight() - 70;		
		
		var width = parseInt(this.width);
		var height = parseInt(this.height);
		var _width = 0; 
		var _height = 0;
		
		if (width > widthScreen && height > heightScreen){
			if (widthScreen > heightScreen){
				_height = heightScreen;
			} else {
				_width = widthScreen;
			}
		} else {
			/*
			if (width > widthScreen || height > heightScreen){
				if (width > height){
					_width = widthScreen;					
				} else {
					_height = heightScreen;					
				}
			} else {
				if (width > height){
					_width = width;
				} else {
					_height = height;
				}
			}
			*/
			
			if (width > widthScreen || height > heightScreen){
				if (width < widthScreen && height > heightScreen){
					_height = heightScreen;				
				} else if (width > widthScreen && height < heightScreen) {
					_width = width;
				} else {
					//alert("condicion no manejada.");
				}
			} else if (width < widthScreen && height < heightScreen){
				if (width < height){
					_width = width;
				} else {
					_height = height;
				}
				
			}
		}
			
		if (_width > 0){
			YAHOO.util.Dom.get("adv_container").innerHTML = '<img src="' + this.src + '" width="' + _width + 'px" style="border-color: #dbdbdb;border-width: 3px;border-style: solid;" />';
		} else {
			YAHOO.util.Dom.get("adv_container").innerHTML = '<img src="' + this.src + '" height="' + _height + 'px" style="border-color: #dbdbdb;border-width: 3px;border-style: solid;" />';
		}
		
		YAHOO.util.Dom.get("labelData").innerHTML = "Avisos " + (_currentPosition + 1) + " de " + _params.length;
		
		var _classForward = YAHOO.util.Dom.get('button_forward').className;
		var _classNext = YAHOO.util.Dom.get('button_next').className;
		
		if (_currentPosition == 0){
			YAHOO.util.Dom.replaceClass('button_forward', _classForward, 'button_forward');
		} else {
			YAHOO.util.Dom.replaceClass('button_forward', _classForward, 'button_forwardH');
		}
		if (_currentPosition > 0 || _currentPosition < (params.length - 1)){
			YAHOO.util.Dom.replaceClass('button_next', _classNext, 'button_nextH');
		} else {
			YAHOO.util.Dom.replaceClass('button_next', _classNext, 'button_next');
		}
		if (_currentPosition == (params.length - 1)){
			YAHOO.util.Dom.replaceClass('button_next', _classNext, 'button_next');
		}
		
		widthScreen = null;
		heightScreen = null;
		width = null;
		height = null;
		_width = null;
		_height = null;
		_classForward = null;
		_classNext = null;
		
	};
	var positionFixedIE = function(e){
		YAHOO.util.Dom.setStyle('advertiseYellow', 'top', YAHOO.util.Dom.getDocumentScrollTop() + 'px');
	};	
}





$Util = {
		Pix2Number : function (strPx) {
			var strNumero = strPx.replace("px", "");
			return parseInt(strNumero, 0);		
		},
		CreateHtmlElement : function(pObj) {
			if (!pObj.elm) { return false; }
			
			var htmlEl = document.createElement(pObj.elm);
			
			for (var cA in pObj) {
				switch (cA.toLowerCase()) {
					case 'elm':
					case 'tojsonstring':
						break;					
					case 'class':
						if (document.all) {
							htmlEl.setAttribute('className', pObj[cA]);
						}
						else {
							htmlEl.setAttribute(cA, pObj[cA]);
						}					
						break;
						
					case 'value':
						htmlEl.setAttribute('defaultValue', pObj[cA]);
						htmlEl.setAttribute(cA, pObj[cA]);
						break;
						
					default:
						htmlEl.setAttribute(cA, pObj[cA]);
						break;					
				}
			}
				
			return htmlEl;
		},		
		removeChildren: function(obj){
			if (obj === null || obj === undefined){
				return;
			}
			var _obj;
			if (typeof(obj) == 'object') {
				_obj = obj;
			} else {
				_obj = YAHOO.util.Dom.get(obj);
				if (_obj === null){
					return;
				}			
			}
					
			this.purge(_obj);
			while (_obj.firstChild) {
			  _obj.removeChild(_obj.firstChild);
			}
			_obj = null;
		},
		purge: function(d){
			var a = d.attributes, i, l, n;
		    if (a) {
		        l = a.length;
		        for (i = 0; i < l; i += 1) {
		            n = a[i].name;
		            if (typeof d[n] == 'function') {
		                d[n] = null;
		            }
		        }
		    }
		    a = d.childNodes;
		    if (a) {
		        l = a.length;
		        for (i = 0; i < l; i += 1) {
		            this.purge(d.childNodes[i]);
		        }
		    }
			a = null;
			i = null;
			l = null;
			n = null;		
		},
		IsIE : function() {
			return YAHOO.util.Event.isIE;
		},
		IsIE6: function() {
			var browser = navigator.appName;
			var result = false;
			if (browser == 'Microsoft Internet Explorer') {
				var version = navigator.appVersion;
				if (version.indexOf('MSIE 6') > 0 ) {
					result =  true;
				}
			} 
			browser = null;
			return result;
		}
	};