var ADS = function()
{	
	var _FLASH = Flash;
	var _old_height = null;
	
	var types = {};
	types["5"] = {
		id: "5",
		path: "/ads/372x250/",
		width: "372",
		height: "250",
		container: "#ads-content"
	};
	types["4"] = {
		id: "4",
		path: "/ads/flutuantes/",
		width: "",
		height: "",
		container: "#banner-flutuante"
	};
	types["1"] = {
		id: "1",
		path: "/ads/150x296/",
		width: "150",
		height: "296",
		container: "#ads-column-1"
	};
	types["2"] = {
		id: "2",
		path: "/ads/150x296/",
		width: "150",
		height: "296",
		container: "#ads-column-2"
	};
	types["3"] = {
		id: "3",
		path: "/ads/800x80/",
		width: "800",
		height: "",
		container: "#ads-topo"
	};
	
	return {
		
		init: function()
		{
			var $self = this;
			$("a.for-ads").each(function(){
				$self.create(this);
			});
		},
		
		create: function(a)
		{
			var $a = $(a);
			var $rel = $a.attr("rel").split(",");
			
			var _clicktag = $a.attr("href");
			var _type = types[$rel[0]];
			var _src = _type.path + $rel[1];
			var _container = _type.container;
			
			var _width = "100%";
			if(_type.width != null && _type.width != "")
			{
				_width = _type.width + "px";
			}
			
			var _height = "100%";
			if(_type.height != null && _type.height != "")
			{
				_height = _type.height + "px";
			}
			
			var __params = [];
			if($rel.length > 2)
			{
				__params = $rel[2].split("&");
			}
			
			_params = {'flashvars': {'clicktag': _clicktag}};
			for(var i=0; i<__params.length; i++)
			{
				var p = __params[i].split("=");
				_params[p[0]] = p[1];
			}
			
			var $banner = new _FLASH(_src, "banner-" + _type.id, _width, _height, _params);
			$banner.writeIn( $(_container).get(0) );
		},
		
		hideBanner: function()
		{
			$(types["4"].container).hide().remove();
		},
		
		expandBanner: function(h)
		{
			var $banner = $(types["3"].container);

			_old_height = $banner.height();

			$banner.height(h).addClass("expanded");
		},
		
		expandBannerClose: function()
		{
			var $banner = $(types["3"].container);

			$banner.height(_old_height).removeClass("expanded");

			_old_height = $banner.height();
		}
		
	};
	
}();

var someBanner = ADS.hideBanner;
var hideBannerFlutuante = ADS.hideBanner;
var expandBanner = ADS.expandBanner;
var expandBannerClose = ADS.expandBannerClose;

$(function(){

	ADS.init();
	
});