/*  ###########################################################################
    company:    42
    client:     Marjolein Delhaas
    client:     Marcel van Doorn
    date:       August 2007
    author:     C. Egor Kloos
    ########################################################################### */
    

    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-8523884-1");
        pageTracker._initData();
        pageTracker._trackPageview();
    });
    

    
    $(document).ready(function(){ 
    
        $('#thumbs > li').each(function(){
            var r = $(this);
            r.hover(function(){
                $('#thumbs > li').addClass('hover');
                $(this).removeClass('hover');
            },function(){
                $('#thumbs > li').removeClass('hover');
            });
        });
                
        $('#navigation > li > ul').each(function(){
            var r = $(this);
            r.hover(function(){
                $(this).addClass('hover');
            },function(){
                $(this).removeClass('hover');
            });
        }); 
        
        
        $('#pagination').width(new Number($('#slides > div > img').attr('width')));      
        $('<li class="next">></li>').insertAfter('#pagination > li:last')
        $('<li class="close">CLOSE X</li>').insertAfter('#pagination > li:last')
        $('#pagination .next').click(function(){
            var n = $('#pagination > li').length-1;
            var i = new Number(location.pathname.split('/')[location.pathname.split('/').length-2]);
            var j = (i==(n-1)) ? (1) : (i+1);
            location.href = location.href.replace('/'+i+'/','/'+j+'/')
        })
        $('#pagination .close').click(function(){
            var h = location.href.substr(0,location.href.length-2);
            location.href=h;
        })
        
        
        var h = $("#contact #slides img:first").attr("height");
        if (h>190){
            var l = $("#contact #slides a:first").attr("href");
            $("#contact #slides a:first").remove();
            $("#contact #slides img:first").wrap('<a href="'+l+'"></a>');
        }
        
        //$("#homepage img").attr("width","255").attr("height","330");
        $("#homepage img").each(function(){
            var w = $(this).attr('width');
            var h = $(this).attr('height');
            if(h>w) $(this).attr("width","255").attr("height","330");
            if(w>h) $(this).attr("width","436").attr("height","330");
        })
        $("#contact #slides a img").each(function(){
            var sh = ($(this).attr("height"))/2;
            $("#image-crop, #image-crop a").css({height:sh});
        })
        $("#contact #slides a img").hover(function(){
            var sh = ($(this).attr("height"))/2;
            $(this).css({top:(sh-(sh*2))})
        },function(){
            var sh = ($(this).attr("height"))/2;
            $(this).css({top:"0"})
        })

    });
    
    