//When the DOM tree is loaded

$(document).ready(function() {

    //========================================================================

    $("#map").each(function() {


        var myLatlng = new google.maps.LatLng(51.5008822, -0.1895276);
        var myOptions = {
            scrollwheel: false,
            zoom: 15,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(document.getElementById("map"), myOptions);



        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map

        });

    });

    //========================================================================


    $(".enquirieEmail a").each(function() {
        var email = $(this).attr("href").replace("mailto:", "");

        $(this).fancybox({
            'href': 'ContactForm.aspx?email=' + email,
            'autoDimensions': false,
            'autoScale': false,
            'scrolling': 'no',
            'padding': 0,
            'height': 400,
            'margin': 0,
            'width': 700,
            'type': 'iframe',
            'centerOnScroll': true,
            'overlayColor': 'black',
            'overlayOpacity': 0.7,
            'enableEscapeButton': false,
            'hideOnOverlayClick': false,
            'titleShow': false


        });
    });
    $("#loginBut").each(function() {
        $(this).attr("href", "/loginint.aspx");

        $(this).fancybox({
            'autoDimensions': false,
            'autoScale': false,
            'scrolling': 'no',
            'padding': 0,
            'height': 300,
            'margin': 0,
            'width': 400,
            'type' : 'iframe',
            'centerOnScroll': true,
            'overlayColor': 'black',
            'overlayOpacity': 0.7,
            'enableEscapeButton': false,
            'hideOnOverlayClick': false,
            'titleShow': false
        });
    });






    $(".caseStudiesHolder .compHolderVid .smallLogo a, .videoLogo a").fancybox({

        'autoDimensions': true,
        'scrolling': 'no',
        'padding': 10,
        'margin': 0,
        'type': 'ajax',
        'centerOnScroll': true,
        'overlayColor': 'black',
        'overlayOpacity': 0.7,
        'enableEscapeButton': false,
        'hideOnOverlayClick': false,
        'titleShow': false

 	   }
	);


    $(".locationHolder .linkHolder a").each(function() {


        if ($(this).attr("rel") == $("#" + $(".locationHolder").attr("rel")).val()) {
            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())
        }

    });


    $(".statusHolder .linkHolder a").each(function() {

        if ($(this).attr("rel") == $("#" + $(".statusHolder").attr("rel")).val()) {

            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())
        }
    });


    $(".sectorHolder .linkHolder a").each(function() {

        if ($(this).attr("rel") == $("#" + $(".sectorHolder").attr("rel")).val()) {

            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())

        }
    });


    $(".yearHolder .linkHolder a").each(function() {

        if ($(this).attr("rel") == $("#" + $(".yearHolder").attr("rel")).val()) {

            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())
        }
    });


    $(".countryHolder .linkHolder a").each(function() {

        if ($(this).attr("rel") == $("#" + $(".countryHolder").attr("rel")).val()) {

            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())
        }
    });


    if ($(".rightCol").height() < $(".leftCol").height()) {
        $(".rightCol").css("height", $(".leftCol").height() + "px");
    }


    $(".functionHolder .linkHolder a").each(function() {

        if ($(this).attr("rel") == $("#" + $(".functionHolder").attr("rel")).val()) {
            $(this).css("font-weight", "bold");
            $(this).css("background-color", "#cbcbcb");
            $(this).parent().parent().parent().find(".showSel").html($(this).html())
        }

    });



    $(".nameSlide").each(function() {


        if ($("#" + $(this).attr("rel")).val() == "1") {
            $(this).find("img").css("top", "1px");
            $(this).find("img").attr("src", "/css/images/buttons/searchDown.png");

            $(this).css("color", "#595959");
            $(this).parent().find(".hidPan").css("display", "block");

        }


    });

    $(".nameSlide").hover(function() {

        $(this).css("cursor", "pointer");

    },

   function() {

       $(this).css("cursor", "normal");


   });

    $(".nameSlide").toggle(function() {

        if ($(this).parent().find(".hidPan").is(':hidden')) {
            $("#" + $(this).attr("rel")).val("1");



            $(this).find("img").attr("src", "/css/images/buttons/searchDown.png");
            $(this).find("img").css("top", "1px");
            $(this).css("color", "#595959");

            $(this).parent().find(".hidPan").slideToggle("fast", function() {



            });

        }
        else {


            $("#" + $(this).attr("rel")).val("");
            $(this).css("color", "#AF006E");
            $(this).find("img").css("top", "");
            $(this).find("img").attr("src", "/css/images/buttons/search.png");
            $(this).parent().find(".hidPan").slideToggle("fast", function() {



            });

        }

    },
    function() {
        if ($(this).parent().find(".hidPan").is(':hidden')) {
            $("#" + $(this).attr("rel")).val("1");

            $(this).find("img").attr("src", "/css/images/buttons/searchDown.png");
            $(this).find("img").css("top", "1px");
            $(this).css("color", "#595959");

            $(this).parent().find(".hidPan").slideToggle("fast", function() {



            });

        }
        else {


            $("#" + $(this).attr("rel")).val("");
            $(this).css("color", "#AF006E");
            $(this).find("img").css("top", "");

            $(this).find("img").attr("src", "/css/images/buttons/search.png");
            $(this).parent().find(".hidPan").slideToggle("fast", function() {

            });

        }

    });








    $(".bookmarkImg").click(function() {
    });

    //Add pointer class to .photo .item
    $(".photo .item").addClass("pointer");

    //Hover over photo fade in hidden span
    $(".photo .item").hover(
        function() {
            $(this).find("span").fadeIn();
        },
        function() {
            $(this).find("span").fadeOut();
        }
    );

    $(".interactiveMenu a, a.mapButton").hover(function() {

        $(this).find("img").each(function() {

            $(this).attr("src", $(this).attr("src").replace(".png", "-on.png"));

        });


    },
        function() {

            $(this).find("img").each(function() {

                $(this).attr("src", $(this).attr("src").replace("-on.png", ".png"));

            });

        });

    $(".newsStory:last").css("border-bottom", "0px");

    $(".inputContText").focus(function() {
        if ($.trim($(this).val()) != "") {
            $(this).val("");

        }
    });

    if ($(".inputContText").val() == "") {

        $(".inputContText").val("Search...");

    }

    $(".rightSearchButton").click(function() {


        if ($.trim($(".inputContText").val()) == "" || $.trim($(".inputContText").val()) == "Search...") {

            return false;

        }

    });


    $(".inputContText").blur(function() {
        if ($.trim($(this).val()) == "" && $.trim($(this).val()) != $(".searchTransText").val() + "...") {
            $(this).val($(".searchTransText").val() + "...");

        }
    });

});


function bookmarksite(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}


$(window).load(function() {

    $(".compHolder .smallLogo img").each(function() {

        if ($(this).parent().parent().height() > $(this).height()) {
            $(this).css("margin-top", (($(this).parent().parent().height() - $(this).height()) / 2) + "px");
        }

    });
});

