$(document).ready(function() {
    /* Function to pre-load slide images */
    $.preloadImages(['http://kcaglobal.com/assets/img/splash.jpg','http://kcaglobal.com/assets/img/environment-2.jpg','http://kcaglobal.com/assets/img/tracking-slide.jpg','http://kcaglobal.com/assets/img/h&s.jpg']);
    /* Call Slide Show */
    $().slideShow();
    /* Make columns equal hights */
    $(".column").equalColumnHeight();
    /* show and hide addresses */
    var visableAddress = "uk";
    $("." + visableAddress).toggleClass("hidden");
    $("#contact nav ul li a").css("cursor", "pointer");
    $("#contact nav ul li a").click(function() {
        $("div." + visableAddress).toggleClass("hidden");
        visableAddress = $(this).attr("title");
        $("div." + visableAddress).toggleClass("hidden");
    });

    /* Content Slider */
    $(".toggle").click(function() {
        var contentHeight = $("#main-content").height();
        // close all open
        $(".show").each(function() {
            if ($(this).css("display") == "block") {
                $(this).slideUp("slow");
                $("#main-conent").css("height", contentHeight);
                $("#sidebar").css("height", contentHeight);
            }
        });
        var total = 0;
        if ($(this).next().css("display") == "none") {
            // add space
            $(this).text($(this).text() == 'read more' ? 'hide' : 'read more');
//            alert($(this).next().height());
            var spaceToAdd = $(this).next().height();
            total = contentHeight + spaceToAdd + 50;
            $("div#main-conent").css("height", total);
            $("div#sidebar").css("height", total);
        } else {
            // deduct space
            $(this).text($(this).text() == 'hide' ? 'read more' : 'hide');
            var spaceToDeduct = $(this).next.height();
            total = contentHeight - spaceToDeduct;
            $("div#main-conent").css("height", total);
            $("div#sidebar").css("height", total);
        }
        $(this).toggleClass("active").next().slideToggle("slow");
        return false;
    });
});

