﻿if (document.location.href.indexOf("localhost") > -1) {
	window.sitePath = "http://localhost:2834/";
} else if (document.location.href.indexOf("broadgauge.org.uk") > -1) {
    window.sitePath = "http://www.broadgauge.org.uk/";
}
window.dataDirectory = window.sitePath + "_data/";

(function ($) {
    //  $ == jquery, shortened to reduce traffic; function ensures if adopted by a later process, the jquery will still run.
    $(function () {
        $.ajaxSetup({ cache: false });

        $("#header_insert").load("../_insert_code/page_header.html", function () {
            //$("ul#mainmenu").menu({ orientation: 'horizontal' });

            $("#menuh1").dropSlideMenu();
        });
        $("#footer_insert").load("../_insert_code/page_footer.html", function () {
            resizeControls();

            setTimeout("resizeControls();", 250);
        });

        $("#container").show();

        $(window).resize(function () {
            resizeControls();
        });
    });
})(jQuery);

function resizeControls() {
    $("#left_col").css("height", "auto");
    $("#right_col").css("height", "auto");
    $("#centre_col").css("height", "auto");

    var centreWidth = $("#centre_col").outerWidth();

    // Check whether any images on page by checking length; if found, calculate width available to display
    if ($("img.ImageCentre").length > 0) {
                // mod for IE9 to reduce width by 2 pixels as index.html picture being pushed down.
        if ( ($.browser.msie) && ($.browser.version >= 9.0) ) {  
            $("img.ImageCentre").width(centreWidth - Number($("img.ImageCentre").css("margin-left").replace("px", ""))
            - Number($("img.ImageCentre").css("margin-right").replace("px", "")) -2 );
        }
        else {
            $("img.ImageCentre").width(centreWidth - Number($("img.ImageCentre").css("margin-left").replace("px", ""))
            - Number($("img.ImageCentre").css("margin-right").replace("px", "")));
        }
    }

    // Check whether any 'Right' images on page by checking length, if found, calculate width available to display
    if ($("img.ImageRight").length > 0) {


        $("img.ImageRight").each(function () {
            var t = $(this);
            t.width(centreWidth - Number(t.css("margin-left").replace("px", "")) - Number(t.css("margin-right").replace("px", "")));
        });


    	//$(".ImageRight").width(centreWidth - Number($(".ImageRight").css("margin-left").replace("px", ""))
        //    - Number($(".ImageRight").css("margin-right").replace("px", "")));

    	// set the min-height of the container divs to ensure that the image only floats with its own text and not that
		// in the next container
        $("img.ImageRight").each(function () {
    		var container = $(this).parents("div.ImageHolder");
    		if (container.length > 0) {
    			container.css("min-height", ($(this).outerHeight()) + "px");
    		}
    	});
    }

    // Check whether any 'Left' images on page by checking length, if found, calculate width available to display
    if ($("img.ImageLeft").length > 0) {
    	$("img.ImageLeft").width(centreWidth - Number($("img.ImageLeft").css("margin-left").replace("px", ""))
            - Number($("img.ImageLeft").css("margin-right").replace("px", "")));

    	// set the min-height of the container divs to ensure that the image only floats with its own text and not that
    	// in the next container
    	$("img.ImageLeft").each(function () {
    		var container = $(this).parents("div.ImageHolder");
    		if (container.length > 0) {
    			container.css("min-height", ($(this).outerHeight()) + "px");
    		}
    	});
    }

    var windowHeight = $(window).height();
    var headerHeight = $("#header_insert").outerHeight(true);
    var footerHeight = $("#footer").outerHeight(true);
    var footerTop = 0;

    try {
        footerTop = $("#footer").position().top;
    }
    catch (e)
    { }

    $("#main_col").height(windowHeight - headerHeight - footerHeight);

    var leftHeight = $("#left_col").outerHeight(true);
    var rightHeight = $("#right_col").outerHeight(true);
    var centreHeight = $("#centre_col").outerHeight(true);
    var colMaxHeight = Math.max(leftHeight, rightHeight, centreHeight);
    var colHeight = Math.max($("#main_col").height(), colMaxHeight, footerTop);

    //window.document.title = ;

    $("#left_col").height(colHeight);
    $("#right_col").height(colHeight);
    $("#centre_col").height(colHeight - Number($("#centre_col").css("padding-bottom").replace("px", ""))); // - padding on div

    if ($("#centre_col .fullWidth").length > 0) {
    	$("#centre_col .fullWidth").width(centreWidth - 3);
    }
}

//$(document).ready(function () {
//    $("#navigation").dropSlideMenu({
//        indicators: true, // adds a div to the list items for attaching indicators (arrows)
//        clickstream: true, // highlights the clickstream in a menu by comparing the links to the current URL path
//        openEasing: "easeOutQuad", // open animation effect
//        closeEasing: "easeInQuad", // close animation effect
//        duration: 600, // speed of drop down animation (in milliseconds)
//        delay: 800, // delay before the drop down closes (in milliseconds)
//        hideSelects: true // hide all select elements on the page when the menu is active (IE6 only)
//    });
//});




