/*
	modified by claudio@castelcd.com.br to support animations in menus without current items
*/

var SlideList = new Class({
	Implements:[Options,Events],
	
	options:{
		transition:Fx.Transitions.Sine.easeInOut,
		duration: 500,
		wait: false,
		onClick: $empty
	},

	initialize: function(menu, options) {
		this.setOptions(options);
		
		this.menu = $(menu), this.current = this.menu.getElement('li.current');
		
		$$(this.menu.getElements('li')).addEvents({
			'mouseover':this.moveBg.bind(this),
			'mouseout':this.moveBg.bind(this,false),
			'click':this.clickItem.bind(this)
		});
				
		this.back = new Element('li',{
			'class':'background',
			morph:this.options
		}).adopt(new Element('div',{'class':'left'})).inject(this.menu);
		if(this.current) {
			this.setCurrent(this.current);
		} else {
			//this.setCurrent(this.menu);
		}
	},
	
	setCurrent: function(el, effect){
		this.back.setStyles({left: (el.offsetLeft), width: (el.offsetWidth)});
		(effect) ? this.back.get('morph').start({'opacity':[0,1]}) : this.back.setStyle('opacity',1);
		this.current = el;
	},

	clickItem: function(event) {
		var item = $(event.target);
		this.setCurrent(item, true);
		this.fireEvent('onClick',[new Event(event), item]);
	},

	moveBg: function(to){
		if(!this.current) {
			this.back.setStyle('opacity',1);
		}
		if(to){
			to = $(to.target);
		}else{
			if(!this.current) {
				this.back.get('morph').start({'opacity':[1,0]}) 
				return;
			}
			to = this.current;
		}
		this.back.get('morph').start({
			left: to.offsetLeft,
			width: to.offsetWidth
		});
	}
});



function trySmoothScrollingTo(anchor) {
	if ($(anchor)) {
		var doc = document.getDocument();
		var fx = new Fx.Scroll(doc, {duration: 900});
		var el = document.id(anchor) || doc.getElement('a[name=' + anchor + ']');
		fx.toElement(el);
	}
}

/* http://davidwalsh.name/jquery-hover-mootools  */
Element.implement({
	'hover': function(fn1,fn2) {
		return this.addEvents({
			'mouseenter': function(e) {
				fn1.attempt(e,this);
			},
			'mouseleave': function(e) {
				fn2.attempt(e,this);
			}
		})
	}
});

/* http://davidwalsh.name/array-shuffling-mootools */
Array.implement({
	shuffle: function() {
		//destination array
		for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
		return this;
	}
});
	
/*
	created by claudio@castelcd.com.br
*/
var MenuSegmentos = new Class({
	Implements:[Options,Events],	
	
	options:{
		transition:Fx.Transitions.Sine.easeInOut,
		duration: 300,
		wait: false
	},
	
	initialize: function(menu, options) {
		this.setOptions(options);
		
		this.menu = $(menu);
		this.current = this.menu.getElement('li a.active');
		if (!this.current) return false;
		
		$$(this.menu.getElements('li a')).addEvents({
			'mouseover':this.moveBg.bind(this),
			'mouseout':this.moveBg.bind(this)
		});
		$$(this.menu.getElements('li a')).set('morph', this.options);
	},
	
	moveBg: function(to){
		if (!to.target) return false;
		if (to.target.tagName.toUpperCase() != "A") {
			//console.debug("---");
			return false;			
		}
		var type = to.type.toLowerCase();
		
		if (to.target.id == this.current.id) {
			return false;
		}
		if (type == "mouseover") {
			config = {
			    'background-position': ["0 0"],
			    'padding-top': [5,12]
			};
		} else {
			config = {
			    'background-position': ["0 -15"],
			    'padding-top': [12, 5]
			};		
		}
		to.target.morph(config);					
	}
});


var CCDSlideShowFromRS = new Class({
	Implements:[Options,Events],
	
	options:{
		//onSlideDisplay: 	$empty(html),
		//afterDisplay: 	$empty(),
		//itemToHTML: 		$empty(item),
		rs: [],
		ipp: 1, //itens per page
		startPage: 1, //pagina inicial (1 se o html ja carrega com itens, "random" para aleatoria)
		intervalo: 5000,
		primeiroIntervalo: null,
		fx: {
			transition:Fx.Transitions.Sine.easeInOut,
			duration: 700,
			wait: false
		}
	},

	initialize: function(container, options) {
		this.setOptions(options);
		this.container = document.id(container);
		this.container.set('morph', this.options.fx);
		this.maxPages = (this.options.rs.length / this.options.ipp).ceil();
		this.page = (this.options.startPage == "random")
					? $random(1, this.maxPages) 
					: this.options.startPage
	    dbug.log('CCDSlideShowFromRS initialized'); 
		this.nextSlide.delay(this.options.primeiroIntervalo || this.options.intervalo, this);	    
	},
	
	nextSlide: function() {
		dbug.log("nextSlide");
		var html = '', idx = 0;

		//calcula pagina de slide linearmente com retorno a 1a
		this.page++;
		if (this.page > this.maxPages) this.page = 1;
		
		for (var i=0; i<this.options.ipp; i++) {
			idx = ((this.page-1) * this.options.ipp) + i;
			//dbug.log("#"+idx);
			if ($chk(this.options.rs[idx])) {
				html+= this.options.itemToHTML(this.options.rs[idx]);
			}
		}
		this.html = html;	
		this.fireEvent('onSlideDisplay', html);			  		
	}
});

/*
Script: CCDCenterIcon.js
	Shows an icon centered over a container with FX
	
	container usually an <a> tag
	container style must be { display: block;  position: relative; }
	centerElement usually an <img> tag
	ie6 has some issues yet

	Author: claudio@castelcd.com.br
*/
var CCDCenterIcon = new Class({
	Implements: [Options],
	options: {
		width: 16,
		height: 16,		
		forceRelative: false,		
		useFX: false,
		fxOpacity: 0.8, //applied when useFx==true
		fxOptions: {
			transition:Fx.Transitions.Sine.easeInOut,
			duration: 500,
			wait: false
		},		
		hoverStyle: {
		    //border: '1px solid red',
		    position: 'absolute',
		    zIndex: '1000',
		    opacity: 0.8 //applied when useFx==false
		}
	},
	getAbsolutePosition: function() {
		var imageSize = this.centerElm.getSize();
		return {
			left: Math.round(Math.abs(imageSize.x-this.options.width)/2),
			top: Math.round(Math.abs(imageSize.y-this.options.height)/2) 
		};
	},
	setHoverStyle: function() {
		var pos = this.getAbsolutePosition();
		this.finalHoverStyle = $merge(
			this.options.hoverStyle, 
			{
				left: pos.left + 'px',
				top:  pos.top + 'px',
				width: this.options.width + 'px',
				height: this.options.height + 'px'
			}
		);		
		
		//fix for ie6 positioning bug
		if (Browser.Engine.trident4) {
			var cFloat = this.centerElm.getStyle("float");
			if (cFloat == "left" || cFloat == "right") {
				//this.options.hoverStyle.position = "relative";
				this.finalHoverStyle.marginLeft = "-" + (pos.left + this.options.width) + "px";
				this.finalHoverStyle.left = "0";
			}
		}		
		
		if (this.options.useFX) {
			this.finalHoverStyle.opacity = 0;
		} else {
			this.finalHoverStyle.display = "none";
		}
	},	
	setupHover: function() {
		//get the size again AFTER the image is loaded - for webkit and other browsers
		var event = (Browser.Engine.trident4)? "onload" : "load";
		this.centerElm.addEvent(event, function() { 
			if (this.hoverElm) {
				var pos = this.getAbsolutePosition();
				this.hoverElm.setStyles(pos);
			}
		}.bind(this));	
				
		this.setHoverStyle();
		
		//create the hover element
		this.hoverElm = new Element('span',	{styles: this.finalHoverStyle});
		this.container.grab(this.hoverElm, 'top');
		
		//if (Browser.Engine.trident4) Browser.fixPNG(this.hoverElm);		
		if (this.options.useFX) {
			this.hoverElm.set('morph', this.options.fxOptions);		
		}
		
		this.container.addEvents({
			'mouseenter': function(e) {
				dbug.log("hover in");
				if (this.options.useFX) {
					this.hoverElm.morph({'opacity': [0, this.options.fxOpacity]});				
				} else {
					this.hoverElm.setStyle("display", "block");
				}				
			}.bind(this),
			'mouseleave': function(e) {
				dbug.log("hover out");
				if (this.options.useFX) {
					this.hoverElm.morph({'opacity': [this.options.fxOpacity, 0]});				
				} else {
					this.hoverElm.setStyle("display", "none");
				}				
			}.bind(this)
		});
	},
	initialize: function(container, options){
		dbug.log("CCDCenterIcon initialize");
		this.container = $(container);		
		this.centerElm = this.container.getFirst();
		
		this.setOptions(options);
		
		if (this.options.forceRelative) {
			//set the container to { display: block;  position: relative; }
			this.container.setStyles({ 
					display: 'block',  
					position: 'relative'
			});		
		}
		this.setupHover();	
	}
});


/*
Script: ccd_accordion.js
	Accordion with multiple open options
	based on MultipleOpenAccordion.js from http://www.clientcide.com/wiki/cnet-libraries#license	

	License:
		MIT-style license.

	Authors:
		Aaron Newton
*/

var MultipleOpenAccordionCCD = new Class({
	Implements: [Options, Events, Chain],
	options: {
		togglers: [],
		elements: [],
		openAll: false,
		firstElementsOpen: [0],
		fixedHeight: false,
		fixedWidth: false,
		height: true,
		opacity: true,
		width: false
//	onActive: $empty,
//	onBackground: $empty
	},
	togglers: [],
	elements: [],
	initialize: function(options){
		var args = Array.link(arguments, {options: Object.type, elements: Array.type});
		this.setOptions(args.options);
		elements = $$(this.options.elements);
		$$(this.options.togglers).each(function(toggler, idx){
			this.addSection(toggler, elements[idx], idx);
		}, this);
		
		var id_atual = ($("id_to_open"))? $("id_to_open").innerHTML : "";
		var idx_atual = this.togglers.indexOf($(this.options.anchor_prefixo + id_atual));
		dbug.log('id_atual ' + id_atual);
		dbug.log('idx_atual ' + idx_atual);

		if (idx_atual > 0) {
			var abrir_itens = [];
			abrir_itens.push(idx_atual);
			this.options.firstElementsOpen = abrir_itens;			
		}
		if (this.togglers.length) {
			if (this.options.openAll) this.showAll();
			else this.toggleSections(this.options.firstElementsOpen, false, true);
		}
		this.openSections = this.showSections.bind(this);
		this.closeSections = this.hideSections.bind(this);
	},
	addSection: function(toggler, element){
		//dbug.log("addSection ");
		toggler = document.id(toggler);
		element = document.id(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		this.togglers.include(toggler);
		this.elements.include(element);
		var idx = this.togglers.indexOf(toggler);
		toggler.addEvent('click', this.toggleSection.bind(this, idx));
		var mode;
		if (this.options.height && this.options.width) mode = "both";
		else mode = (this.options.height)?"vertical":"horizontal";
		element.store('reveal', new Fx.Reveal(element, {
			transitionOpacity: this.options.opacity,
			duration: 200,
			mode: mode,
			heightOverride: this.options.fixedHeight,
			widthOverride: this.options.fixedWidth
		}));
		return this;
	},
	onComplete: function(idx, callChain){
		if (has_console) console.debug("complete accordion item" + idx);
		this.handleIcon(idx);
		this.fireEvent(this.elements[idx].isDisplayed()?'onActive':'onBackground', [this.togglers[idx], this.elements[idx]]);
		this.callChain();
		return this;
	},
	showSection: function(idx, useFx){
		this.toggleSection(idx, useFx, true);
	},
	hideSection: function(idx, useFx){
		this.toggleSection(idx, useFx, false);
	},
	handleIcon: function(idx) {
		var show = this.elements[idx].isDisplayed();
		if (has_console) console.debug("handleIcon accordion" + show + ": " + idx);
		var span_icone = this.togglers[idx].getElements("a.collapse_icon");		
		if (show) {
			span_icone.addClass("collapse_aberto");
		} else {
			span_icone.removeClass("collapse_aberto");			
		}
	},
	toggleSection: function(idx, useFx, show, callChain){
		var method = show?'reveal':$defined(show)?'dissolve':'toggle';
		callChain = $pick(callChain, true);
		var el = this.elements[idx];
		if(has_console) {
			console.debug("toggle section " + show + ": " + idx);
		}	
		
		if ($pick(useFx, true)) {
			this.handleIcon(idx);
			el.retrieve('reveal')[method]().chain(
				this.onComplete.bind(this, [idx, callChain])
			);
		} else {
			if (method == "toggle") el.togglek();
			else el[method == "reveal"?'show':'hide']();
			this.onComplete(idx, callChain);
		}
		return this;
	},
	toggleAll: function(useFx, show){
		var method = show?'reveal':$chk(show)?'disolve':'toggle';
		var last = this.elements.getLast();
		this.elements.each(function(el, idx){
			this.toggleSection(idx, useFx, show, el == last);
		}, this);
		return this;
	},
	toggleSections: function(sections, useFx, show) {
		//if(has_console) { 	console.debug("toggleSections "); 	}		
		last = sections.getLast();
		this.elements.each(function(el,idx){
			this.toggleSection(idx, useFx, sections.contains(idx)?show:!show, idx == last);
		}, this);
		return this;
	},
	showSections: function(sections, useFx){
		sections.each(function(i){
			this.showSection(i, useFx);
		}, this);
	},
	hideSections: function(sections, useFx){
		sections.each(function(i){
			this.hideSection(i, useFx);
		}, this);
	},
	showAll: function(useFx){
		return this.toggleAll(useFx, true);
	},
	hideAll: function(useFx){
		return this.toggleAll(useFx, false);
	}
});

/*
 e24PNGFix
	- MooTools version required: 1.2.2
	Changelog:
		- 1.0: First release
		- added bg displacement code  by CLF july/2009
*/
/*Based on the fixPNG module from MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006-2007 Valerio Proietti, <http://mad4milk.net>, MIT Style License.||Clientcide Copyright (c) 2006-2008, http://www.clientcide.com/wiki/cnet-libraries#license*/
/* Copyright: equipo24 S.L.N.E <http://equipo24.com/> - Distributed under MIT License - Keep this message! */
$extend(Browser, {
	fixPNG: function(el) {
		if (Browser.Engine.trident){
			//el = document.id(el);
			//alert(el.outerHTML);
			var w = el.getStyle('width');
			var h = el.getStyle('height');

			var imgURL = el.getStyle('background');
			if (!imgURL) imgURL = el.getStyle('background-image');

			//bg displacement handling
			var posx = el.getStyle('background-position-x');
			var posy = el.getStyle('background-position-y');

			if (imgURL.test(/\((.+)\)/)){
				el.setStyle('background', '');

				var subEl = new Element('div', {
					'style': 'width: ' + w + ';' + 'height: ' + h + ';' + 
					"filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src=" + imgURL.match(/\((.+)\)/)[1] + ");"
				});
					
				//bg displacement handling
				if( (Math.abs(parseInt(posx)) > 0) || (Math.abs(parseInt(posy)) > 0) ) {
					subEl.setStyle('position', "absolute");
					subEl.setStyle('width', "1000px");					
					subEl.setStyle('height', "1000px");					
					if (Math.abs(parseInt(posx)) > 0) {
						//alert("X: " + posx);
						subEl.setStyle('left', posx);
					}
					if (Math.abs(parseInt(posy)) > 0) {
						//alert("Y: " + posy);
						subEl.setStyle('top', posy);
					}					
				}
				el.grab(subEl);
			};
		}
	}
});

//if (Browser.Engine.trident) window.addEvent('domready', function(){alert("inicializando PNG"); $$('div.fixpng').each(Browser.fixPNG)});



var CCDPeriodicRequest = new Class({
	Implements:[Options],
	
	options:{
		intervalo: 5000,
		transition:Fx.Transitions.Sine.easeInOut,
		duration: 700,
		wait: false
	},

	initialize: function(container, options) {
		this.setOptions(options);
		this.container = document.id(container);
		this.container.set('morph', this.options);

		this.rh = new Request.HTML({
			url: this.options.url,
			evalScripts: false,
		 	onComplete: this.loaded.bind(this)
		});
	    dbug.log('CCDPeriodicRequest initialized'); 		
		this.load.delay(this.options.intervalo, this);
	},
	
	load: function() {
	    dbug.log('CCDPeriodicRequest load'); 		
		this.rh.send();
		//this.load.delay(this.options.intervalo, this);
	},
	
	loaded: function(par, par2, html) {
	    dbug.log('CCDPeriodicRequest loaded'); 		
		this.container.get('morph').start({'opacity':[1,0]}).chain(function() {
			document.id(this.container).empty().set('html', html || "erro");	
			divs = document.id(this.container).getElements("div.img_destaque");
			if (divs.length == 3) {
				divs.each(function(el, idx) {
					el.set('morph', this.options);	
					el.setStyle('opacity',0);					
				}.bind(this));
				this.container.setStyle('opacity',1);
				divs[0].get('morph').start({'opacity':[0,1]});
				var d1 = function() { 
					divs[1].get('morph').start({'opacity':[0,1]});		
					var d2 = function() { 
						divs[2].get('morph').start({'opacity':[0,1]});					
						this.load.delay(this.options.intervalo, this);								
					}.bind(this);
			        d2.delay(250);			
				}.bind(this);
		        d1.delay(250);
			} else {
				this.container.get('morph').start({'opacity':[0,1]});
				this.load.delay(this.options.intervalo, this);		
			}				
		}.bind(this));
	}
});

/*
	Class:    	ScrollSpy
	Author:   	David Walsh
	Website:    http://davidwalsh.name/js/scrollspy
	Version:  	1.0.0
	Date:     	5/19/2009
	Built For:  MooTools 1.2.2
*/

/* scroll spy plugin / class */
var ScrollFollow = new Class({
	
	/* implements */
	Implements: [Options,Events],

	/* options */
	options: {
		min: 0,
		mode: 'vertical',
		max: 0,
		container: window,
		onEnter: $empty,
		onLeave: $empty,
		onTick: $empty
	},
	
	/* initialization */
	initialize: function(follower, options) {
		/* set options */
		
		this.float_el = follower;
		this.options.min = this.float_el.getOffsets().y;
		this.setOptions(options);
			
		this.setOptions(options);
		this.container = $(this.options.container);
		this.enters = this.leaves = 0;
		this.max = this.options.max;
		
		/* fix max */
		if(this.max == 0) 
		{ 
			var ss = this.container.getScrollSize();
			this.max = this.options.mode == 'vertical' ? ss.y : ss.x;
		}
		
		this.float_el.set('tween', {
			transition:Fx.Transitions.Sine.easeInOut,
			duration: 500,
			wait: false,
			onClick: $empty
		});
				
		/* make it happen */
		this.addListener();
	},
	
	update: function(escopo, position) {
	    dbug.log('update ' + escopo); 
	    
	    offsetH = Math.max(0, position.y - this.options.min);
	    current_max = this.options.max;
	    
	    //ff3 bug?
	    if (escopo == "leave") current_max = Math.max(0, current_max - this.options.min);
	    
	    offsetH = Math.min(offsetH, current_max);
	    dbug.log('offsetH ' + offsetH);     

		this.float_el.tween('top', offsetH);  
	},
		
	/* a method that does whatever you want */
	addListener: function() {
		/* state trackers */
		this.inside = false;
		this.container.addEvent('scroll',function() {
			/* if it has reached the level */
			var position = this.container.getScroll();
			var xy = this.options.mode == 'vertical' ? position.y : position.x;
			/* if we reach the minimum and are still below the max... */
			if(xy >= this.options.min && xy <= this.max) {
					/* trigger Enter event if necessary */
					if(!this.inside) {
						/* record as inside */
						this.inside = true;
						this.enters++;
						/* fire enter event */
						this.update('enter',position);						
					}
					/* trigger the "tick", always */
					this.update('tick',position);
			}
			else {
				/* trigger leave */
				if(this.inside) 
				{
					this.inside = false;
					this.leaves++;
					this.update('leave',position);
				}
			}
		}.bind(this));
	}
});



var CCDCarrossel = new Class({
	Extends: SimpleSlideShow,
	Implements: [Class.ToElement],
	Binds: ['makeSlide'],
	options: {					
		sliderWidth: 999999,
		//clf
		dynamicLoad: false
	},
	initialize: function(container, options){
		dbug.log("initialize");
		this.setOptions(options);
		this.container = document.id(container);
		this.element = new Element('div').wraps(this.container).setStyles({
			width: this.container.getSize().x,
			overflow: 'hidden',
			position: 'relative'
		});
		this.container.setStyles({
			width: this.options.sliderWidth,
			position: 'relative'
		});
		
		
		//this.parent(options);
		var slides = this.options.slides;
		this.makeSlides(slides);
		this.setCounters();
		this.setUpNav();
		this.now = this.options.startIndex;
		
		if ((!Browser.Engine.gecko) && (this.slides.length > 1)) {
			//this.startIndexOriginal = this.now;
			//this.now = (this.now+1) % this.slides.length ;
		}
		
		//ccd clf
		carNavContainer = document.id(this.options.prevLink).getParent();
		if (carNavContainer) {
			var disp = (this.slides.length > 1)? "block" : "none";
			$(carNavContainer).getChildren().each(function(child){ child.setStyle("display", disp) });
		}
		
		carParent = this.container.getParent().getParent();
		dbug.log("carParent");
		dbug.log(carParent);		
		if ((this.options.dynamicLoad) && (carParent)) {
			els = carParent.getElements("div.car_loading");
			if ($chk(els[0])) this.loadingDiv = els[0];
		}			
			
		//corrige bug (primeira transicao ocorre sem efeito em browsers nao gecko)
		if (!Browser.Engine.gecko) {
			this.fx = this.fx || new Fx.Tween(this.container, {
				property: 'left'
			});
			this.fx.start(-this.slides[this.now].getPosition(this.container).x);			
		}

		dbug.log("ini end " + this.now);
		if (this.slides.length > 0) this.show(this.now);

	},
	makeSlides: function(slides) {
		this.slides = [];
		slides.each(this.makeSlide);
		
		//clf - carrega slides vazios dinamicamente
		if (this.options.dynamicLoad) {
			this.slides_loaded = [];
			slides.each(function(s, idx) {
				this.slides_loaded[idx] = (s.getElements("div").length > 0);
			}.bind(this));
			dbug.log(this.slides_loaded);
		}
		
	},
	makeSlide: function(slide) {
		if (slide.retrieve('slideSetup')) return;
		slide.store('slideSetup', true);
		slide.show();
		var s = new Element('div', {
			styles: {
				'float': 'left',
				width: document.id(this).getSize().x
			}
		}).wraps(slide);
		this.parent(s);
		this.slides.erase(slide);
		this.setCounters();
		s.show();
		s.inject(this.container);
	},
	show: function(index) {
		dbug.log("show " + index);
		if (!this.container) return;
		this.fx = this.fx || new Fx.Tween(this.container, {
			property: 'left'
		});
		if (this.showing) return this.chain(this.show.bind(this, index));
		var now = this.now;

		var s = this.slides[index]; //saving bytes
		if (s) {
			dbug.log(this.now + " x  " + index);
			if (this.now != index) {
				dbug.log("fx start " + this.now + " " + -s.getPosition(this.container).x);
				this.fx.start(-s.getPosition(this.container).x).chain(function(){
					s.addClass(this.options.currentSlideClass);
					this.showing = false;
					this.disableLinks();
					this.callChain();
					this.ajaxLoad(index);					
				}.bind(this));
			}
			this.now = index;
			this.setCounters();
		}
	},
	//clf
	disableLinks: function(now){
		now = $pick(now, this.now);
		dbug.log("disable links " + now);
		var prev = document.id(this.options.prevLink);
		var next = document.id(this.options.nextLink);
		var dlc = this.options.disabledLinkClass;
		if (now > 0) {
			if (prev) prev.removeClass(dlc);
			if (now === this.slides.length-1 && next) next.addClass(dlc);
			else if (next) next.removeClass(dlc)
		}	else { //now is zero
			if (this.slides.length > 0 && next) next.removeClass(dlc);
			if (prev) prev.addClass(dlc);
		}
	},	
	ajaxLoad: function(index) {
		dbug.log("ajaxload " + index);
		if ((this.options.dynamicLoad) && (!this.slides_loaded[index])) {
			url = this.options.ajaxPageUrl + (index + 1);
			dbug.log(url);
			el_to_update =  $(this.slides[index].getElement("div"));
			
			var div_loading = new Element('div', {'class': "car_loading"});
			new Element(
				'img',
				{src: this.options.ajaxLoadingImg}
			).inject(div_loading);
			div_loading.inject(el_to_update)
			dbug.log(el_to_update.innerHTML);
			
			this.ajaxRequest = new Request.HTML({
				url: url,
				data: this.options.ajaxData,
			 	update: el_to_update,
			 	/*
			  	useWaiter: true,
			  	waiterOptions: {
			    	fxOptions: {duration: 400},
			    	baseHref: asset_path + "img/",
				  	useIframeShim: false,			    	
				  	injectWhere: 'inside',			    	
	    			img: {
						src: 'loading_barra3.gif',
						styles: {
							width: 24,
							height: 24
						},
						'class': 'waiterImg'
					}
			  	},*/
			  	onComplete: function() { 
			  		dbug.log("complete");
  					//this.loadingDiv.setStyle("display", "none");
  					//this.slides[index].setStyle("display", "block");
			  		this.slides[index].getElements("div.materia_resumida").each(hover_materia_resumida);
			  		this.slides_loaded[index] = true;
					this.fireEvent('onSlideDisplay', index);			  		
			  		//this.ajaxRequest.waiter.stop();				  		
			  	}.bind(this)				  	
			});
			this.ajaxRequest.send();
		} else {
			this.fireEvent('onSlideDisplay', index);
		}
	}
});




/*
Script: Clientcide.js
	The Clientcide namespace.

License:
	http://www.clientcide.com/wiki/cnet-libraries#license
*/
var Clientcide = {
	version: '2.1.0',
	setAssetLocation: function(baseHref) {
		var clean = function(str){
			return str.replace(/\/\//g, '/');
		};
		if (window.StickyWin && StickyWin.UI) {
			StickyWin.UI.implement({
				options: {
					baseHref: clean(baseHref + '/stickyWinHTML/')
				}
			});
			if (StickyWin.Alert) {
				StickyWin.Alert.implement({
					options: {
						baseHref: baseHref + "/simple.error.popup"
					}
				});
			}
			if (StickyWin.UI.Pointy) {
				StickyWin.UI.Pointy.implement({
					options: {
						baseHref: clean(baseHref + '/PointyTip/')
					}
				});
			}
		}
		if (window.TagMaker) {
			TagMaker.implement({
			    options: {
			        baseHref: clean(baseHref + '/tips/')
			    }
			});
		}
		if (window.ProductPicker) {
			ProductPicker.implement({
			    options:{
			        baseHref: clean(baseHref + '/Picker')
			    }
			});
		}

		if (window.Autocompleter) {
			Autocompleter.Base.implement({
					options: {
						baseHref: clean(baseHref + '/autocompleter/')
					}
			});
		}

		if (window.Lightbox) {
			Lightbox.implement({
			    options: {
			        assetBaseUrl: clean(baseHref + '/slimbox/')
			    }
			});
		}

		if (window.Waiter) {
			Waiter.implement({
				options: {
					baseHref: clean(baseHref + '/waiter/')
				}
			});
		}
	},
	preLoadCss: function(){
		if (window.StickyWin && StickyWin.ui) StickyWin.ui();
		if (window.StickyWin && StickyWin.pointy) StickyWin.pointy();
		Clientcide.preloaded = true;
		return true;
	},
	preloaded: false
};
(function(){
	if (!window.addEvent) return;
	var preload = function(){
		if (window.dbug) dbug.log('preloading clientcide css');
		if (!Clientcide.preloaded) Clientcide.preLoadCss();
	};
	window.addEvent('domready', preload);
	window.addEvent('load', preload);
})();
setCNETAssetBaseHref = Clientcide.setAssetLocation;



/*
Script: IframeShim.js
	Defines IframeShim, a class for obscuring select lists and flash objects in IE.

	License:
		MIT-style license.

	Authors:
		Aaron Newton
*/

var IframeShim = new Class({

	Implements: [Options, Events, Class.Occlude],

	options: {
		className: 'iframeShim',
		display: false,
		zIndex: null,
		margin: 0,
		offset: {x: 0, y: 0},
		browsers: (Browser.Engine.trident4 || (Browser.Engine.gecko && !Browser.Engine.gecko19 && Browser.Platform.mac))
	},

	property: 'IframeShim',

	initialize: function(element, options){
		this.element = document.id(element);
		if (this.occlude()) return this.occluded;
		this.setOptions(options);
		this.makeShim();
		return this;
	},

	makeShim: function(){
		if(this.options.browsers){
			var zIndex = this.element.getStyle('zIndex').toInt();

			if (!zIndex){
				zIndex = 1;
				var pos = this.element.getStyle('position');
				if (pos == 'static' || !pos) this.element.setStyle('position', 'relative');
				this.element.setStyle('zIndex', zIndex);
			}
			zIndex = ($chk(this.options.zIndex) && zIndex > this.options.zIndex) ? this.options.zIndex : zIndex - 1;
			if (zIndex < 0) zIndex = 1;
			this.shim = new Element('iframe', {
				src:'javascript:false;document.write("");',
				scrolling: 'no',
				frameborder: 0,
				styles: {
					zIndex: zIndex,
					position: 'absolute',
					border: 'none',
					filter: 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
				},
				'class': this.options.className
			}).store('IframeShim', this);
			var inject = (function(){
				this.shim.inject(this.element, 'after');
				this[this.options.display ? 'show' : 'hide']();
				this.fireEvent('inject');
			}).bind(this);
			if (Browser.Engine.trident && !IframeShim.ready) window.addEvent('load', inject);
			else inject();
		} else {
			this.position = this.hide = this.show = this.dispose = $lambda(this);
		}
	},

	position: function(){
		if (!IframeShim.ready) return this;
		var size = this.element.measure(function(){ return this.getSize(); });
		if ($type(this.options.margin)){
			size.x = size.x - (this.options.margin * 2);
			size.y = size.y - (this.options.margin * 2);
			this.options.offset.x += this.options.margin;
			this.options.offset.y += this.options.margin;
		}
		if (this.shim) {
			this.shim.set({width: size.x, height: size.y}).position({
				relativeTo: this.element,
				offset: this.options.offset
			});
		}
		return this;
	},

	hide: function(){
		if (this.shim) this.shim.setStyle('display', 'none');
		return this;
	},

	show: function(){
		if (this.shim) this.shim.setStyle('display', 'block');
		return this.position();
	},

	dispose: function(){
		if (this.shim) this.shim.dispose();
		return this;
	},

	destroy: function(){
		if (this.shim) this.shim.destroy();
		return this;
	}

});

window.addEvent('load', function(){
	IframeShim.ready = true;
});

