$(document).ready(function(){ 
    initMenu();
    initTables();
    initPopupPages();
    initSkycrapers();
});


function initMenu() {
  $(".menu ul").hide(); 
  $(".menu ul.actif").show(); 
  $(".menu img").click(function() {
      var ul = $(this).parent().next();
      if ( ul.css('display') == 'block' )
	return false;
      $(".menu ul.actif").slideUp("fast");

      var oldimage = $(".menu ul.actif").prev().children();
      oldimage.attr("src", "image/menu/" + oldimage.attr("name") + ".gif");
      oldimage.attr("class", "");
      
      $(".menu ul.actif").attr("class", "");
      ul.attr("class", "actif"); 
      $(this).attr("src", "image/menu/" + $(this).attr("name") + "_r.gif");
      $(this).attr("class", "actif");

      ul.slideDown("fast");
      return false;
   });
}

function menu_rollover(img, src, srcActif) {
  var classname = img.getAttribute('class');
  if ( !classname )
    classname = img.getAttribute('className');
  if ( classname != 'actif' )
    img.setAttribute("src", src);
  else
    img.setAttribute("src", srcActif);
}

function showPopup(url, width, height) {
  var params = "";
  params += "innerwidth  = " + width  + ", ";
  params += "innerheight = " + height + ", ";
  params += "width       = " + width  + ", ";
  params += "height      = " + height + ", ";
  params += "dependent   = yes, ";
  params += "location    = no , ";
  params += "menubar     = no , ";
  params += "status      = no , ";
  params += "toolbar     = no , ";
  params += "scrollbars  = yes, ";
  params += "resizable   = yes, ";    
  params += "top         = " + 10 + ", ";
  params += "left        = " + ((screen.width  - width)  / 2);
  var win = window.open(url, "win", params);
}

function initTables() {
  $(".table_title").each(function(i) {
      _initTableTitle($(this));
  });
}

function _initTableTitle(table) {
  table.attr("border", 0);
  table.find("tr:even").css("background", "#d2d1d1");
  table.find("tr:odd").css("background", "#eaeaea");
  table.find("tr:eq(0)").css("background", "#BB262C");
  table.find("tr:eq(0)").css("color", "white");
}

function initPopupPages() {
  $('.html_content a').click(function() {	
    var link = this.href;    
    if ( this.target == "_popup" ) {
      if ( link.indexOf("?") == -1 )
	link += "?";
      link += "contentwidth=498&TB_iframe=true&height=480&width=525&modal=true";
      tb_show(null, link, false);
      this.blur();  
      return false;
    } else {
      return true;
    }
  });
}

function initSkycrapers() {
  var index = 0;
  var nb = $('.skycraper').length;
  var randomnumber = Math.floor(Math.random() * nb)
 
  $('.skycraper').hide();
  $('.skycraper:eq(' + randomnumber + ')').show();

  var foo = function() {
    var nextIndex = ( index < nb - 1 ? index + 1 : 0 );
    $('.skycraper:eq(' + index + ')').fadeOut(1500, function() {
	$('.skycraper:eq(' + nextIndex + ')').fadeIn(1500);
    });
    index = nextIndex;

    setTimeout(foo, 13500);
  }
  
  setTimeout(foo, 12000);
}

