document.observe("dom:loaded", function() {
    equalize(".products-grid");
    switcher(".product-info-switcher");
    back_links();
    handle_newsletter_inputs();
    slider();
	_new();
});
   
   
function equalize(selector) {
       
    $$(selector).each(function(ul, index) {
        _height = 0;
        ul.childElements().each(function(li, index) {
            if(+_height < li.getHeight()){
                _height = li.getHeight()
            }
        });
        ul.childElements().each(function(li, index) {
            li.setStyle({
                'height': _height+'px'
            });
        });
    });
}

function switcher(selector) {
       
    if($$(selector+' > #info-switcher > li.activated > div.switcher-content')!='')
    {
        /* set the correct height for the containing div*/ 
        _height = $$(selector+' > #info-switcher > li.activated > div.switcher-content').first().getHeight() + 50;
        $$(selector).first().setStyle({
            'height': _height+'px'
        });
    }
    
    /* observe onclick */
    $$(selector+' #info-switcher li').invoke('observe','click',function() 
    {
        $$(selector+' #info-switcher li').each(function(li, index) {
            li.removeClassName('activated');
            li.addClassName('deactivated');
        });
        this.removeClassName('deactivated');
        this.addClassName('activated');
        
        _height = $$(selector+' > #info-switcher > li.activated > div.switcher-content').first().getHeight() + 50;
        $$(selector).first().setStyle({
            'height': _height+'px'
        });
    });
}

function back_links() {

    $$('p.back-link a small').each(function(small, index) {
        small.remove();
    });

    $$('p.back-link a').each(function(link, index) {
        link.insert('<span class="back-img"></span>');
    });
}

function handle_newsletter_inputs()
{
    _email = 'Vul je e-mailadres in';
    _name = 'Vul je naam in';
    
    $$('input.newsletter-email').each(function(_elm,index){
        _elm.value = _email
    });
        $$('input.newsletter-name').each(function(_elm,index){
        _elm.value = _name;
    });

    $$('input.newsletter-email').invoke('observe','click',function() {
        if(this.value == _email){this.value='';}
    });

    $$('input.newsletter-name').invoke('observe','click',function() {
        if(this.value == _name){this.value='';}
    });

    $$('input.newsletter-email').invoke('observe','blur',function() {
        if(this.value == ''){this.value=_email;}
    });

    $$('input.newsletter-name').invoke('observe','blur',function() {
        if(this.value == ''){this.value=_name;}
    });
}

function slider()
{
    if($$('#carousel-1')!=''){
    	new Pluit.Carousel('#carousel-1', {
	      circular: true,
	      effect: 'move',
	      slideDuration: 10,
	      autoPlay: true
	    });
    }
}


function _new() {
    
    $$("._new a").each(function(_elm, index) {
        _elm.writeAttribute('target','_blank');
    });
}

