/*	###########################################################################
	42 B.V.
	date:   November 2008
	author: C. Egor Kloos
	author: ---
	########################################################################### */
    
    
    
    // LOAD GOOGLE ANALYTICS 
/*
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    $.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
        // RUN GOOGLE ANALYTICS
        var pageTracker = _gat._getTracker("UA-6612944-1");
        pageTracker._setDomainName("www.42.nl");
        pageTracker._initData();
        pageTracker._trackPageview();
    });
*/


    $(document).ready(function(){
            
        // validate the form when it is submitted
        $(':input[name="required[]"]').attr('name',function(index){return "required[" + index + "]"}); /* FIX FOR NAME ARRAY ISSUE NEEDED IN EXPRESSION ENGINE */
        $("label span.required").parent().next(":input").addClass("required");
        $("form").each(function(){$(this).validate();});  


        $('.overview .archive-list .linklist').each(function(){
            var i = $(this).find('li');
            if(i.length<5) return;
            $(this).clone().insertAfter('.archive-list .linklist:first').clone().insertAfter('.archive-list .linklist:first')
            var l = Math.ceil(i.length/3)-1;
            $(this).find('li:gt('+l+')').remove();
            $(this).next().find('li:lt('+(l+1)+')').remove();
            $(this).next().find('li:gt('+l+')').remove();
            $(this).next().next().find('li:lt('+(l*2+2)+')').remove();
        })
        
        
        // REDUCE LINKS IN SIDEBAR
        $('#sidebar .article .linklist').each(function(){
            var l = $(this).find('li');
            if(l.length<21) return;
            l.each(function(i){
                if(i>20){
                    $(this).hide();
                }
            });
            $(this).append('<li><a>toon de hele lijst</a></li>');
            $(this).find('li:last-child').addClass('toggle-list').click(function(){
                l.show();
                $(this).remove();
            })
        });
        
        
        /* BLOCK HOVER ############################################################ */
        
        $('.result, .company li, .overview .article, .blog #content .article').each(function(){
            var r = $(this);
            var l = r.find('a.readon').length;
            if(l>0){
                r.hover(function(){
                    $(this).addClass('hover');
                },function(){
                    $(this).removeClass('hover');
                });
                r.click(function(){
                    location.href = $(this).find('a.readon').attr('href');
                });
            }
        });
        
        $('aside nav').each(function(){
            var r = $(this);
            var l = r.find('a').length;
            if(l>0){
                r.hover(function(){
                    $(this).addClass('hover');
                },function(){
                    $(this).removeClass('hover');
                });
                r.click(function(){
                    location.href = $(this).find('a').attr('href');
                });
            }
        });
    });
    
    
    /* jQuery Validator: extending to the dutch language. (many other languages available) */
    $.extend(jQuery.validator.messages, {
        required: "Dit is een verplicht veld.",
        remote: "Controleer dit veld.",
        email: "Vul hier een geldig email adres in.",
        url: "Vul hier een geldige URL in.",
        date: "Vul hier een geldige datum in.",
        dateISO: "Vul hier een geldige datum in (ISO).",
        number: "Vul hier een geldig nummer in.",
        digits: "Vul hier alleen nummers in.",
        creditcard: "Vul hier een geldig credit card nummer in.",
        equalTo: "Vul hier dezelfde waarde in.",
        accept: "Vul hier een waarde in met een geldige extensie.",
        maxlength: jQuery.format("Vul hier maximaal {0} tekens in."),
        minlength: jQuery.format("Vul hier minimaal {0} tekens in."),
        rangelength: jQuery.format("Vul hier een waarde in van minimaal {0} en maximaal {1} tekens."),
        range: jQuery.format("Vul hier een waarde in van minimaal {0} en maximaal {1}."),
        max: jQuery.format("Vul hier een waarde in kleiner dan of gelijk aan {0}."),
        min: jQuery.format("Vul hier een waarde in groter dan of gelijk aan {0}.")
    });

    
    
    

