/*********************
TRILLIUM CODE - START
*********************/
function GetPerson(personId) {

    var timeout = 0;
    if ($(window).scrollTop() > 0) var timeout = 300;
    $.scrollTo($("#container"), 300);
    setTimeout(function () {
        var params = {
            PersonID: personId
        };
        $.ajax({
            type: "POST",
            url: "/WebServices/WebMethods.aspx/GetPerson",
            data: JSON.stringify(params),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: ajaxGetBio,
            error: function (msg) {
                var x = 1;
                // Do something interesting here.
            }
        });
    }, timeout);
}

function ajaxGetBio(response, options) {
    var myReq = response;
    var data = response.d
    var myOptions = options;
    if (typeof data != "undefined") {
        $("#main section header, .people_profile, .related").slideToggle(300, function () {
            $("#main section h1:first, #main section .people_profile, #main section .related, #main section header").remove();
            $(data).insertBefore("#main section .key_people");
            $("#main section .people_profile, #main section .related, #main section header").slideToggle(300);
        });
    }
}
/*********************
TRILLIUM CODE - END
*********************/

function googlemapsInitialize() {
    if ($("#map_london").length > 0 && $("#map_dublin").length > 0) {
        var londonLat = new google.maps.LatLng(51.512922429762554, -0.1134037971496582);
        var londonOpts = {
            zoom: 14,
            center: londonLat,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var dublinLat = new google.maps.LatLng(53.333268, -6.252638);
        var dublinOpts = {
            zoom: 14,
            center: dublinLat,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map_london = new google.maps.Map(document.getElementById("map_london"), londonOpts);
        var map_dublin = new google.maps.Map(document.getElementById("map_dublin"), dublinOpts);

        var london_marker = new google.maps.Marker({
            position: londonLat,
            map: map_london
        });

        var dublin_marker = new google.maps.Marker({
            position: dublinLat,
            map: map_dublin
        });
    }
}

function googlemapsLoadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=googlemapsInitialize";
    document.body.appendChild(script);
}

window.onload = googlemapsLoadScript;

/*
$(document).ready(function () {

    if ($("#slideshow").length > 0) {

        $('#slideshow ul').anythingSlider({
            buildNavigation: false,
            autoPlay: true,
            delay: 3000
        });
    }

*/

var windowLoaded = false;
var documentReady = false;

$(document).ready(function() {


    $(document).on("click", ".enquiry_form", function (e) {

        if (!$(this).hasClass("opened")) {
            $(this).find("strong").text('Map >');
        } else {
            $(this).find("strong").text('Enquiry form >');
        }
        $(this).toggleClass("opened");

        $(this).closest("div.contact_container").find("div.contact_map").find(".photo").slideToggle(300);
        $(this).closest("div.contact_container").find("div.contact_map").find(".google_maps").slideToggle(300);
        $(this).closest("div.contact_container").find("div.contact_map").find(".contact_form").slideToggle(300);
        return false;
    });

    $(".contact_map .contact_form .fields").each(function () {
        $(this).attr("data-placeholder", $(this).val());
    });

    $(document).on("blur", ".contact_map .contact_form .fields, #search .search_text", function (e) {
        if ($(this).val() == '') $(this).val($(this).attr("data-placeholder")).removeClass("focused");
    });
    $(document).on("focus", ".contact_map .contact_form .fields, #search .search_text", function (e) {
        if ($(this).val() == $(this).attr("data-placeholder")) $(this).val('').addClass("focused").removeClass("error");
        if (typeof $(this).attr("data-entered") != "undefined") {
            $(this).val($(this).attr("data-entered")).removeAttr("data-entered").removeClass("error");
        }
    });

    $(document).on("click", "#main section .key_people div a.wrapper", function (e) {
        if (e.ctrlKey || e.metaKey) {
            return true;
        } else {
            $("#main nav ul li ul li").removeClass("current");
            $elem = $("#main nav ul li ul").find("li").eq($(this).closest("div").index());
            if ($elem.length > 0) $elem.addClass("current");
            $("#main section .key_people div").removeClass("current");
            $(this).closest("div").addClass("current");
            /*********************
            TRILLIUM CODE - START
            *********************/
            GetPerson($(this).attr("data-personid"));
            /*********************
            TRILLIUM CODE - END
            *********************/
        }
        return false;
    });

    $(document).on("click", "#main section .key_people div p a", function (e) {
        if (e.ctrlKey || e.metaKey) {
            return true;
        } else {
            $("#main nav ul li ul li").removeClass("current");
            $elem = $("#main nav ul li ul").find("li").eq($(this).closest("div").index());
            if ($elem.length > 0) $elem.addClass("current");
            $("#main section .key_people div").removeClass("current");
            $(this).closest("div").addClass("current");
            /*********************
            TRILLIUM CODE - START
            *********************/
            GetPerson($(this).attr("data-personid"));
            /*********************
            TRILLIUM CODE - END
            *********************/
        }
        return false;
    });

   /*  $(document).on("click", "#main nav ul li ul li a", function (e) {
        if (e.ctrlKey || e.metaKey) {
            return true;
        } else {
            $("#main nav ul li ul li").removeClass("current");
            $(this).parent().addClass("current");
            $("#main section .key_people div").removeClass("current");
            $elem = $(".people_section div").eq($(this).parent().index());
            if ($elem.length > 0) $elem.addClass("current");
           ********************
            TRILLIUM CODE - START
            *********************/
           /* GetPerson($(this).attr("data-personid"));
            ********************
            TRILLIUM CODE - END
            ********************
        }
        return false;
    });*/



    $(document).on("mouseenter", "#main section .our_people_roles div a.wrapper", function () {
        $(this).parent().find("div:first").animate({ "background-color": "#31C1F4" }, 120);
        $(this).find("span").stop().animate({ opacity: 0 }, 120);
    });

    $(document).on("mouseleave", "#main section .our_people_roles div a.wrapper", function () {
        $(this).parent().find("div:first").animate({ "background-color": "#999999" }, 120);
        $(this).find("span").stop().animate({ opacity: 0.4 }, 120);
    });

    $(document).on("mouseenter", "#main section .key_people div a.wrapper", function () {
        $elem = $("#main nav ul li ul").find("li").eq($(this).parent().index());
        if ($elem.length > 0) $elem.addClass("hovered");
        $(this).find("span").stop().animate({ opacity: 0 }, 120);
        $(this).parent().addClass("hovered");
    });

    $(document).on("mouseleave", "#main section .key_people div a.wrapper", function () {
        $elem = $("#main nav ul li ul").find("li").eq($(this).parent().index());
        if ($elem.length > 0) $elem.removeClass("hovered");
        $(this).find("span").stop().animate({ opacity: 0.4 }, 120);
        $(this).parent().removeClass("hovered");
    });

    $(document).on("mouseenter", "#main section .key_people div p a", function () {
        $elem = $("#main nav ul li ul").find("li").eq($(this).closest("div").index());
        if ($elem.length > 0) $elem.addClass("hovered");
        $(this).parent().parent().find("a.wrapper span").stop().animate({ opacity: 0 }, 120);
    });

    $(document).on("mouseleave", "#main section .key_people div p a", function () {
        $elem = $("#main nav ul li ul").find("li").eq($(this).closest("div").index());
        if ($elem.length > 0) $elem.removeClass("hovered");
        $(this).closest("div").find("a.wrapper span").stop().animate({ opacity: 0.4 }, 120);
    });

    $(document).on("mouseenter", "#main nav ul li ul li a", function () {
        $(".people_section div").eq($(this).parent().index()).find("a").trigger('mouseenter');
    });

    $(document).on("mouseleave", "#main nav ul li ul li a", function () {
        $(".people_section div").eq($(this).parent().index()).find("a").trigger('mouseleave');
    });
	
	
//alert($("#slideshow").length);
if (windowLoaded) {
	  if ($("#slideshow").length > 0) {
		$('#slideshow ul li').show();
		$('#slideshow ul').anythingSlider({
			buildStartStop: false,
			buildNavigation: false,
			autoPlay: true,
			delay: 3000
		});
	  }
  //if ($("#slideshow").length > 0) {
  //alert('ie7 - test1');
  //  $('#slideshow ul li:first').show();
  //}
}
documentReady = true;



});


$(window).load(function(){
//$('#slideshow ul li:first').show();
//window.alert('ie7 test1');
//alert($("#slideshow"));
  if (documentReady) {
	  if ($("#slideshow").length > 0) {
		$('#slideshow ul li').show();
		$('#slideshow ul').anythingSlider({
			buildStartStop: false,
			buildNavigation: false,
			autoPlay: true,
			delay: 3000
		});
	  }
  }
  windowLoaded = true;
});

