// detectamos javascript habilitado. Clase usada en la CSS segun la que usaremos unos u otros estilos
document.documentElement.className = 'js-enabled';

window.addEvent('domready', function(){
	// para navegadores chungos
	$$('li:first-child').addClass('first-child');
	$$('li:last-child').addClass('last-child');
	$$('form input[type=text], form textarea').addEvents({
		'focus': function(){
			this.addClass('activo');
		},
		'blur': function(){
			this.removeClass('activo');			
		}
	});
	
	// marcar enlaces externos
	if(! (Browser.Engine.trident4 || Browser.Engine.trident5)){
	   $$('a[href^="http:"]').addClass('external');
	   $$('a[href^="http://kus.cool-z.com"], a[href^="http://www.cool-z.com"], a[href^=http://cool-z.com], a[href^=http://v2.cool-z.com]').removeClass('external');
    }		
	
	// clases html
	$$('div.bloque.clientes div.grid_4:nth-child(3n-2)').addClass('primero');
	$$('div.bloque.clientes div.grid_4:nth-child(3n+0)').addClass('ultimo');
	
	new CZ.Efectos($$('a:not(.button), a:not(.page)'), {
		color: '#8d9f27'
	});
	new CZ.Efectos($$('.button'),{
	    background: '#ff1662'
    });
    new CZ.Efectos($$('.wp-pagenavi a.page'),{
        background: '#8d9f27'
    });
	new CZ.Imgs($$('.img img'));
	

	new CZ.HighlightAnchors($$('#comentarios ol li'));
	
	//new FormCheck('form-comentarios');

		
});

var CZ = CZ || {};
CZ.Efectos = new Class({
	Implements: Options,
	options: {},
	initialize: function(elements, options){
		this.setOptions(options);		
		this.elements = elements;
		this.hoverLinks();
	},
	hoverLinks: function(){				
		var colorFinal = this.options.color;	
		var bgFinal = this.options.background;
		if(this.options.color){
    		this.elements.each(function(el){
    			var colorOriginal = el.getStyle('color');
    			
    			el.addEvent('mouseenter', function(){
    				this.set('tween',{
    				    duration: 200
    				}).tween('color', colorFinal);				
    			});
    			el.addEvent('mouseleave', function(){
    				this.set('tween',{
    				    duration: 400
    				}).tween('color', colorOriginal);				
    			})
    		})    
        }	
        if(this.options.background){
            this.elements.each(function(el){
    			var colorOriginal = el.getStyle('background-color');    			
				el.addEvents({
					'mouseenter': function(){
						this.set('tween',{
	    				    duration: 200
	    				}).tween('background-color', bgFinal);					
					},
					'focus': function(){
						this.set('tween',{
	    				    duration: 200
	    				}).tween('background-color', bgFinal);
					},
					'mouseleave': function(){
						this.set('tween',{
	    				    duration: 400
	    				}).tween('background-color', colorOriginal);	
					},
					'blur': function(){
						this.set('tween',{
	    				    duration: 400
	    				}).tween('background-color', colorOriginal);
					}
				});
    		})
        }
	}
});

CZ.Imgs = new Class({
	Implements: Options,
	options: {
		
	},
	initialize: function(elements, options){
		this.setOptions(options);
		this.elements = elements;
		this.hoverImgs();		
	},
	hoverImgs: function(){
		var all = this.elements;
		this.elements.addEvents({
			'mouseenter': function(){
				all.set('tween',{
					duration: 300
				}).tween('opacity', .3);
				this.set('tween',{
					duration: 300
				}).tween('opacity', 1);				
			},
			'mouseleave': function(){
				all.set('tween',{
					duration: 300
				}).tween('opacity', 1);				
			}
		})
	}
});

CZ.HighlightAnchors = new Class({
    initialize: function(elements){
        this.elements = elements;
        this.getTarget();
    },
    getTarget: function(){
        if(document.location.hash){
            var target = $(document.location.hash.split('#')[1]);
            if(!target) return;
            this.elements.each(function(el){
                if (target != el) return; // si no esta dentro de las etiquetas que buscamos...
                target.set('tween',{
                    duration: 800
                }).tween('background-color', '#ff8');
            });            
        }
    }
});

