$(document).ready(function(){			
	    
	if(typeof $(".lightbox")[0] == 'object') {
		$(".lightbox").lightBox();
	}   
	
	$('div#ue a').click(function(){return false;});	
	
	setTimeout(function(){
		ImageBlender(document.getElementById('anim'), imgs, 4000);
	}, 3000)

     // Acordeon	
     if(typeof $('div.subpagina')[0] == 'object'){         
         var items = $('div.subpagina h2');
         var heights = [];                                        	 
	 
         $(items).each(function(i, item){	
             var content = $(item).next();             	     			 
	     
             heights.push($(content)[0].offsetHeight);             

	     $(content).css({"height":0});                                                  
	   
             $(item).click(function(){	    				
				 
			if(parseInt($(content).css("height")) > 0){
				    $(item).find('img')[0].src="/img/open-acordeon.gif"; 
			        $(content).stop().animate({'height': 0}, 500, 'easeInOutSine');                                  
	         }else{				
				$(item).find('img')[0].src="/img/close-acordeon.gif"; 
				$(items).each(function(j, prev){                     
    	                 if(parseInt($(prev).next().css("height")) > 0){
        	                $(prev).next().stop().animate({'height': 0}, 500, 'easeInOutSine');
							$(prev).find('img')[0].src="/img/open-acordeon.gif";
            	         }
                	 });
				 
	                 $(this).next().stop().animate({'height': heights[i]}, 500, 'easeInOutSine');                                  
	     } 
             
             }).mouseover(function(){
                  if(/MSIE 6.0/.test(navigator.userAgent)){   
                           $(this).css("cursor", "pointer");
                  }
             });    
         });
	 
	 $($(items)[0]).next().css({'height':heights[0]}); 
	 $($(items)[0]).find('img')[0].src="/img/close-acordeon.gif"; 
    }		
	
	$('input[type=text], textarea')
	.click(function(){$(this).css({'border-color': '#cc2200 #e76a52 #e76a52 #cc2200'})})
	.blur(function(){$(this).css({'border-color': '#777777 #CCCCCC #CCCCCC #777777'})})		
	
	
	if(/MSIE 6/.test(navigator.userAgent)){
		$('ul#topmenu li a.selected').removeClass('selected');
	}
});


function ImageBlender(container, imgs, d){  
			
	this.imgs = imgs;		
	this.container = container;
	this.index = 0;		
	this.duration = d;
	this.cache = [];
	this.isCached = false;		
	
	this.startBlending = function(){		
	
		if(this.index == this.imgs.length){
			this.index = 0;
			this.isCached = true;
		}else{								
			var src = this.imgs[this.index++];
		}
		
		this.changePhoto(src || 0);
		var that = this;
		
		window.setTimeout(function(){
			that.startBlending();
		}, this.duration);
	}	
	
	this.changePhoto = function(src){		
	
		var oldImg = this.container.getElementsByTagName('img')[0];
		
		if(this.isCached == true) {			
			var newImg = this.cache[this.index];				

			if (newImg != undefined) {
				newImg.style.display = 'none';
				this.container.appendChild(newImg);
				$(newImg).fadeIn("slow", function(){$(oldImg).remove();});
			}
		}else {		
			var newImg = document.createElement('img');
			this.cache.push(newImg);
			newImg.className = oldImg.className;
			newImg.style.display = 'none';			
			this.container.appendChild(newImg);
			newImg.src = src;										
			
			if (newImg.complete) {				
				$(newImg).fadeIn(2000, function(){$(oldImg).remove();}, 'easeOutQuad');				
			}
			else {			
				newImg.onload = function(){
					$(newImg).fadeIn(2000, function(){$(oldImg).remove();}, 'easeOutQuad');
				}
			}
		}				
	}
	
	this.startBlending();		
};