function Is() {
  agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla') != -1) &&
  (agent.indexOf('spoofer') == -1) &&
  (agent.indexOf('compatible') == -1) &&
  (agent.indexOf('opera') == -1) &&
  (agent.indexOf('webtv') == -1) &&
  (agent.indexOf('hotjava') == -1));
  this.ns2 = (this.ns && (this.major == 2));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4 = (this.ns && (this.major == 4));
  this.ns6 = (this.ns && (this.major >= 5));
  this.ie = ((agent.indexOf('msie') != -1) &&
  (agent.indexOf('opera') == -1));
  this.ie3 = (this.ie && (this.major < 4));
  this.ie4 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 4") != -1));
  this.ie5 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 5.") != -1) &&
  (agent.indexOf("msie 5.5") == -1) &&
  (agent.indexOf("mac") == -1));
  this.iem5 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 5.") != -1) &&
  (agent.indexOf("mac") != -1));
  this.ie55 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 5.5") != -1));
  this.ie6 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 6.") != -1));
  this.ie7 = (this.ie && (this.major == 4) &&
  (agent.indexOf("msie 7.0b") != -1));
  this.nsdom = (this.ns4 || this.ns6);
  this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
  this.iedom = (this.ie4 || this.ie5dom || this.ie6);
  this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
}

var is = new Is();

// Drop-down menu
function loadDropDownMenu() {
  var firstParent = null;
  var navigationNodesList = null;
  var parentBlockId = null;
  var parentNodeWidth = null;
  var parentNextNode = null;
  var parentNextNodeId = null;
  var parentNextNodeWidth = null;
  var nodeWidth = null;
  if (is.ie6) {
    firstParent = $('first_level');
    navigationNodesList = firstParent.getElementsByTagName('ul');
    navigationNodes = $A(navigationNodesList);
    navigationNodes.each(function(node) {
      parentBlockId = node.parentNode.id;
      parentNodeWidth = $(parentBlockId).getDimensions().width;
      grandParentNodeId = $(parentBlockId).parentNode.id;
      parentNextNodeId = $(grandParentNodeId).lastChild.id;
      parentNextNodeWidth = $(parentNextNodeId).getDimensions().width;
      nodeWidth = parentNextNodeWidth + parentNodeWidth + 1;
      node.style.left = '-' + nodeWidth + 'px';
      node.style.top = node.offsetTop + $(node.parentNode.id).offsetHeight -1 + 'px';
    });
  }
  else if (is.ie) {
    firstParent = $('first_level');
    navigationNodesList = firstParent.getElementsByTagName('ul');
    navigationNodes = $A(navigationNodesList);
    navigationNodes.each(function(node) {
      node.style.left = $(node.parentNode.id).offsetLeft + 'px';
      node.style.top = node.offsetTop + $(node.parentNode.id).offsetHeight + 'px';
    });
  }
}

// HEADLINE
function loadHeadline() {
  // Vars
  var topContainer = 0;
  var cHeight = 0;
  var fHeight = 0;
  var tHeight = 70;
  var firstNodeList = null;
  var firstNodes = null;
  var e = null;
  var i = 0;
  var k = null;
  var n = null;
  var img = null;

  // Load Interaction
  firstNodeList = $('embed_headline_container').getElementsByClassName('headline_sheet_thumbnail');
  firstNodes = $A(firstNodeList);
  firstNodes.each(function(node){
    i++;
    if (i > 1) {
      node.style.opacity = '0.2';
      node.style.filter = 'alpha(opacity=20)';
//       if(is.ie6){
//         img = node.firstChild.src;
//         node.firstChild.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + img + ', sizingMethod="scale")';
//         img = null;
//       }
    }
    n = node.id;
    e = $(n).nextSiblings();
    e.each(function(f){
      // Set space
      fHeight = $(f.id).getDimensions().height;
      if (i > 1)
        $(f.id).hide();
      else {
        topContainer = $('embed_headline_container').offsetTop + fHeight;
      }
      if (is.ie){
        $(f.id).style.float = 'none';
      }
      else{
        $(f.id).style.position = 'absolute';
      }
      $(f.id).style.top = topContainer+'px';
      if (fHeight > cHeight) {
        cHeight = fHeight;
        $('embed_headline_container').style.paddingBottom = fHeight + tHeight + 'px';
      }
      // Add event
      Event.observe(n, 'mouseover', function() {
        // Reset
        firstNodes.each(function(g){
          $(g.id).style.opacity = '0.2';
          $(g.id).style.filter = 'alpha(opacity=20)';
//           if(is.ie6){
//             $(g.id).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/white.png', sizingMethod='scale')";
//           }
          h = $(g).nextSiblings();
          h.each(function(j){
            j.hide();
          });
        });
        // Interact
        $(node.id).style.opacity = '1';
        $(node.id).style.filter = 'alpha(opacity=100)';
        $(f.id).show();
        }, false);
    });
  });
}

// GOOGLE MAPS
function loadGmapsControl(map_canvas) {
  map = new GMap2($(map_canvas));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(48.5, 1.125), 8);
  geocoder = new GClientGeocoder();
}

function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert('Désolé, il est impossible de géocoder cette adresse.');
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
      map.addOverlay(marker);
      marker.openInfoWindowHtml(place.address);
  }
}

function showLocation(address) {
  geocoder.getLocations(address, addAddressToMap);
}

function loadGoogleMaps() {
  var map = null;
  var geocoder = null;

  loadGmapsControl(m);
  showLocation(a);
}


function waitAndSee(time, fct)
{
  window.setTimeout(fct,time);
}