$(document).ready(function() {
            $('.content_nieuws img').each(function() {
        var maxWidth = 150; // Max width for the image
        var maxHeight = 100;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height

        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
        });


        //hoverTweets();
        accordion();
        click();
        $("#consumentenknop").click(function () {
            if(!$(this).hasClass("active")){
                //$("#categorie_form").submit();
                $.ajax({
                    type: "POST",
                    url: "index.php",
                    data: "categorie_input=consument",
                    success: function(msg){
                        window.location.href = "http://www.myorder.nl/";

                    }

                });
            }
        });
        $("a").click(function () {
            $("a").removeClass("active");
            $(this).addClass("active");

        });

        $("#ondernemerknop").click(function () {
            if(!$(this).hasClass("active")){
                $.ajax({
                    type: "POST",
                    url: "index.php",
                    data: "categorie_input=ondernemer",
                    success: function(msg){
                        window.location.href = "http://www.myorder.nl/";
                    }
                });
            }
        });
        if(window.location.pathname == "/locaties/"){
            var location = window.location.toString();
            var array = location.split("?");

            var element = document.getElementById(array[1]);
            $(element).trigger('click');
            $(".titel").removeClass("active");
            $(element).addClass("active");
        }

         drawOrangeLink();


        $(".titel").click(function () {

            $(".titel").removeClass("active");
            $(this).addClass("active");
            setTimeout(function(){resize()} , 400);
        }
    );
        $(".dropdown").click(function () {
            setTimeout(function(){resize()} , 350);
            drawOrangeLink();
        });
        resize();
        setTimeout(function(){resize()} , 400);
		$('.locatie_img').each(function() { 
        var maxWidth = 60; // Max width for the image
        var maxHeight = 60;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height

        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
// Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image

	
        }
$(this).css("padding-left", (10 - $(this).width())/2 );  
$(this).css("padding-top", (60 - $(this).height())/2 );   
        });
    });

    function drawOrangeLink(){
        var location = window.location.pathname;
            var array = location.split("/");
            array[array.length-2] += "_link";
            var id= array[array.length-2];

             var element = document.getElementById(id);
             $(element).addClass("active");
             if(id=="contact_link"){
                 id+="2";
                 element = document.getElementById(id);
             $(element).addClass("active");
             }
             if(id=="minitix_link"){
                 id+="2";
             element = document.getElementById(id);
             $(element).addClass("active");
             }
    }

    function click(){
        $("#getp").click(function () {
            $("#middle_middle_middle").append("Bla <br /> \nBla <br /> \nBla <br /> \nBla <br /> \nBla <br /> \n");
            resize();
        });
    }

    function accordion(){
        $( "#accordion" ).accordion({
            autoHeight: false,
            navigation: true,
            collapsible: true,
            active:false
        });
    }
    function resize(){
        if($("#middle_middle_middle").height()>512){
            $("#middle_middle").height($("#middle_middle_middle").height()+21)
        }
        var height = $("#middle_middle_middle").height()-$("#nieuws").height()-$("#twitter").height()-$("#download").height()-$("#logos").height() - 74;

        if(height<0){
            height = 17;
        }
        else{
            height += 24;
        }
        $("#logos").css('padding' , height);
        var height2 = $("#middle_middle_middle").height() - $("#consumenten").height() - 376 -33;

        if(height2<0){
            height2 = 64;
        }
        else{
            height2+=80;
        }
        $("#social").css('padding' , height2);

        var middle_height= $("#middle_middle").height();
        $("#middle_shadow_left").height(middle_height);
        $("#middle_shadow_right").height(middle_height);
    }

