﻿$(document).ready(function() {

    $(document).pngFix();



    $(".homepage .popup_container .select").mouseover(function() {
        $(this).addClass("selected");
        $(".homepage .popup_container .popup").show();
    });
    $(".homepage .popup_container").mouseleave(function() {
        $(".homepage .popup_container .select").removeClass("selected");
        $(".homepage .popup_container .popup").hide();
    });



    $(".focus .submit_field, .finder .submit_field").mouseover(function() {
        $(this).attr("src", "/images/button_go_orange.gif");
    });
    $(".focus .submit_field, .finder .submit_field").mouseleave(function() {
        $(this).attr("src", "/images/button_go.gif");
    });



    $(".find .submit_field").mouseover(function() {
        $(this).attr("src", "/images/button_go_largeorange.png");
    });
    $(".find .submit_field").mouseleave(function() {
        $(this).attr("src", "/images/button_go_large.png");
    });







    $(".landing_two .search_results li a").click(function() {
        $(".landing_two .search_results li a").parent().removeClass("selected");
        $(this).parent().addClass("selected");
    });



    $(".accordion a.tog").click(function() {
        $(this).next().toggle();
        $(this).toggleClass("tog_selected");

    });

    $(".accordion_slim a.tog").click(function() {
        if ($(this).next().css('display') != 'block') {
            $(".accordion_slim p").slideUp();
            $(".accordion_slim a").removeClass("tog_selected");
            $(this).next().slideDown();
            $(this).addClass("tog_selected");
        }
    });


    $(".panel_contact_default").fadeIn();



    $(".homepage .proposition .col_news .slider").easySlider({
        auto: true,
        pause: 8000,
        vertical: true,
        controlsShow: true,
        continuous: true,
        numeric: true,
        speed: 2000
    });


    $(".history .history_c_1 a").click(function() {

        var x = $(this).attr("title");


        $(".history .history_c_1 a").removeClass("selected");
        $(this).addClass("selected");

        $(".history .history_c_2 .history_panel").hide();
        $(".history .history_c_2 .history_" + x).show();

    });



    //loadMap();

});


var map;

function loadMap() {
    
    
    $(".off_addr").each(function (i) {        
        var val = $(this).val().split(";");
        setTimeout("geocodeMapLoad("+val[1]+","+val[0]+")",200);
      });
    
   
    var myLatlng = new google.maps.LatLng(40, 0);
    var myOptions = {
        zoom: 2,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel: false,
        smallzoomcontrol3d: true,
        mapTypeControl: false
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
}


  
    
function panMap(x, y) {

    $(".col_office, .col_office h3").removeClass("selected");
    $(".col_office .popout").hide();

    if(x != ";")
    {
        var val = x.split(";");
        setTimeout("geocodeMap("+val[1]+","+val[0]+")",200);
    }
    
    map.setZoom(16);
    
    $(y).prev().prev().prev().show();
    $(y).parent().prev().show();
    
    $(y).parent().addClass("selected");
    $(y).parent().parent().addClass("selected");
}

function panMap2(x, y) {

    $(".col_office").removeClass("selected");
    $(".col_office .popout").hide();
    
    if(x != ";")
    {
        var val = x.split(";");
        setTimeout("geocodeMap("+val[1]+","+val[0]+")",200);
    }
    
    map.setZoom(16);
    
    $(y).parent().prev().prev().prev().show();
    $(y).parent().parent().addClass("selected");
    alert("pan2");
}


function resetMap() {
    $(".col_office").removeClass("selected");
    $(".col_office .popout").hide();
    map.setZoom(3);
}



function geocodeMapLoad(lat,lon) {
    
    var myLatLng = new google.maps.LatLng(lon,lat);
    
    var image = new google.maps.MarkerImage('/images/marker/image.png',
    // This marker is 20 pixels wide by 32 pixels tall.
    new google.maps.Size(50, 50),
    // The origin for this image is 0,0.
    new google.maps.Point(0,0),
    // The anchor for this image is the base of the flagpole at 0,32.
    new google.maps.Point(0, 50));
    var shadow = new google.maps.MarkerImage('/images/marker/shadow.png',
    // The shadow image is larger in the horizontal dimension
    // while the position and offset are the same as for the main image.
    new google.maps.Size(50, 50),
    new google.maps.Point(0,0),
    new google.maps.Point(0, 50));
    // Shapes define the clickable region of the icon.
    // The type defines an HTML <area> element 'poly' which
    // traces out a polygon as a series of X,Y points. The final
    // coordinate closes the poly by connecting to the first
    // coordinate.
    var shape = {
    coord: [1, 1, 1, 20, 18, 20, 18 , 1],
    type: 'poly'
    };

    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape

    });

    google.maps.event.addListener(marker, 'click', function() {
        map.setCenter(myLatLng);
        map.setZoom(16);
    });
    
}



function geocodeMap(lon,lat) {
    
    var myLatLng = new google.maps.LatLng(lat,lon);
    
    map.setCenter(myLatLng);
    //var image = '/images/marker.png';
    
    var image = new google.maps.MarkerImage('/images/marker/image.png',
    // This marker is 20 pixels wide by 32 pixels tall.
    new google.maps.Size(50, 50),
    // The origin for this image is 0,0.
    new google.maps.Point(0,0),
    // The anchor for this image is the base of the flagpole at 0,32.
    new google.maps.Point(0, 50));
    var shadow = new google.maps.MarkerImage('/images/marker/shadow.png',
    // The shadow image is larger in the horizontal dimension
    // while the position and offset are the same as for the main image.
    new google.maps.Size(50, 50),
    new google.maps.Point(0,0),
    new google.maps.Point(0, 50));
    // Shapes define the clickable region of the icon.
    // The type defines an HTML <area> element 'poly' which
    // traces out a polygon as a series of X,Y points. The final
    // coordinate closes the poly by connecting to the first
    // coordinate.
    var shape = {
    coord: [1, 1, 1, 20, 18, 20, 18 , 1],
    type: 'poly'
    };
    
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape
    });

    google.maps.event.addListener(marker, 'click', function() {
        map.setCenter(myLatLng);
        map.setZoom(16);
    });
}



function showFlyover(x) {
    var width = $(x).children("a.nav").width();
    var newWidth = 213 - parseInt(width);
    $(".top").css('width', newWidth);
    $(x).addClass("fly");
    $(x).children("div").show();
}

function showFlyoverLarge(x) {
    var width = $(x).children("a.nav").width();
    var newWidth = 379 - parseInt(width);
    $(".top").css('width', newWidth);
    $(x).addClass("fly");
    $(x).children("div").show();
}

function hideFlyover(x) {
    $(x).removeClass("fly");
    $(x).children("div").hide();
}


function setTab(theLink, theTarget) {
    $(".landing .tabs .tab a").parent().removeClass("selected");
    $(theLink).parent().addClass("selected");

    $(".landing .column_3 .panel_contact").hide();
    $(".panel_contact_" + theTarget).fadeIn();
    //alert(theTarget);
}

function SearchBoxTip(box,focus,defaultv)
{   
    if(focus && box.value == defaultv)
    {
        box.value = "";
    }
    else if(box.value == "")
    {
        box.value = defaultv;
    }        
}


function checkEnter(e)
{ 
    //e is event object passed from function invocation
    var characterCode;// literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        //document.forms[0].submit(); //submit the form        
        var targ;
        
        if (e.target) targ = e.target;        
            else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
        
        document.location.href= '/search.aspx?key='+ targ.value;         
        
        StopPropogations(e);
        
        return false;
    }
    else {
        return true;
    }
}
function StopPropogations(evt)
{
    var e=(evt)?evt:window.event;
    if (window.event) {
        e.cancelBubble=true;
    } else {
        e.stopPropagation();
    }
}


function Search(boxId, defaultvalue)
{
    var box = document.getElementById(boxId);
    if(box && box.value != "" && box.value != defaultvalue)
    {
        document.location.href= '/search.aspx?key='+ box.value; 
    }else 
        alert('Please enter a search term and try again.');
    
    return false;
}


function SearchPeople(boxId, defaultvalue)
{
    var box = document.getElementById(boxId);
    if(box && box.value != "" && box.value != defaultvalue)
    {
        document.location.href= '/search.aspx?key='+ box.value+'&type=people'; 
    }
    else alert('Please enter a search term and try again.');
    
    return false;
}


function CheckEnterPeopleSearch(e)
{ 
    //e is event object passed from function invocation
    var characterCode;// literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        //document.forms[0].submit(); //submit the form        
        var targ;
        
        if (e.target) targ = e.target;        
            else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
        
        document.location.href= '/search.aspx?key='+ targ.value + '&type=people';
        
        return false;
    }
    else {
        return true;
    }

}
function SearchSolution(boxId, defaultvalue)
{
    var box = document.getElementById(boxId);
    if(box && box.value != "" && box.value != defaultvalue)
    {
        document.location.href= '/search.aspx?key='+ box.value+'&cat=solutions'; 
    }
    else alert('Please enter a search term and try again.');
    
    return false;
}


function checkEnterSolution(e)
{ 
    //e is event object passed from function invocation
    var characterCode;// literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        //document.forms[0].submit(); //submit the form        
        var targ;
        
        if (e.target) targ = e.target;        
            else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
        
        document.location.href= '/search.aspx?key='+ targ.value+"&cat=solutions";         
        
        return false;
    }
    else {
        return true;
    }
}

function LoadSelectedLevels(url, comboid)
{
    var combo = document.getElementById(comboid);
    document.location.href = url + "?level=" + combo.options[combo.selectedIndex].value;
    return false;
}

function LoadComboUrl(comboid, type)
{
    var combo = document.getElementById(comboid);
    if(combo.selectedIndex == 0)
        alert("Please select a "+type+" and try again.");
    else
        document.location.href = combo.options[combo.selectedIndex].value;
    
    return false;
}

function LoadMicrosite(caption, micrositeurl)
{
    tb_show(caption, micrositeurl,"");
}