var img_count = 1;
var img_max   = 6;
var img_selected = 0;
var img_default  = true;
var timer_1;
var timer_2;
var Effia = {};

function openOnline() {
  fw = 697;
  fh = 570;
  scr = 'yes';
  x = (screen.width - fw)/2;
  y = (screen.height - fh)/2;

  window.open("http://www.effia.fr/frontoffice/online/default.htm","online","width="+fw+",height="+fh+",left="+x+",top="+y+",scrollbars="+scr);
}

//var srcOut = -1;

function on(id) {
//  if (srcOut == -1) srcOut = document.getElementById("out").src;
  document.getElementById("out").src = "/doc/img/accueil/"+id;
}

function off(id) {
  document.getElementById("out").src = srcOut;
}


function switch_area_img(area_id) {
  document.getElementById("map-bkg").src = "doc/img/espace_emploi/fresque-"+area_id+".jpg";
  if(area_id == 0) { 
    $$('.topics').each(function (el) {
	  el.removeClassName('selected-title');
	});
  }
  else $('topic-'+area_id).addClassName('selected-title');
}

function auto_switch_area_img(area_id) {
  document.getElementById("map-bkg").src = "doc/img/espace_emploi/fresque-"+area_id+".jpg";
}


function show_iframe(id) {
  if (img_selected != id) {
    if (img_selected != 0) hide_all_text();
	$('topic-'+id).addClassName('selected-tab');
    Effect.SlideDown($('content-topic-'+id), { duration: 0.5 });
    img_selected = id;
  }
}

function show_all_iframe() {
  $$('.topics').each(function (el) {
    regMask  = new RegExp("[0-9]+","g");
    rank = parseInt(el.id.match(regMask));
    el.writeAttribute('rank', rank);
    Event.observe(el, 'mouseover', function(e){
      switch_area_img(el.readAttribute('rank'));
    });
	Event.observe(el, 'mouseout', function(e){
      switch_area_img(0);
    });
	action_id = el.readAttribute('p_id');
    action = '?p_a=__iframe_content&p_id='+action_id;
    Kwo.exec(action, null, {container: 'content-'+el.id});
  });
  $$('.containers').each(function (elm) {
	elm.hide();
  });
    /*action_id = el.readAttribute('p_id');
    action = '?p_a=__iframe_content&p_id='+action_id;
    Kwo.exec(action, null, {container: 'content-'+el.id, callback: function() {
      ('content-'+el.id).select('p').each(function (elp) {
	    regMask  = new RegExp("[0-9]+","g");
        rank = parseInt(el.id.match(regMask));
	    elp.writeAttribute('rank', rank);
        Event.observe(elp, 'mouseover', function(e){
          switch_area_img(e.target.readAttribute('rank'));
        });
        Event.observe(elp, 'mouseout', function(e){
          switch_area_img(0);
        });
        elp.hide();
	  });
    }});*/
}

function hide_all_text(){
  /*$$('.topics').each(function(el){
    el.select('p').each(function(elp){
      if (! elp.hasClassName('content-title')) elp.hide(); //Effect.SlideUp(elp); 
    });
  });*/
  $$('.topics').each(function (el) {
	el.removeClassName('selected-tab');
  });
  $('content-topic-'+img_selected).hide();
  //Effect.SlideUp($('content-topic-'+img_selected), { duration: 0.5 });
}

Effia.display = {
  "alphaBackgrounds" : function (e) {
    var bg = e.currentStyle.backgroundImage;
    if (bg.match(/\.png/i) != null && e.hasClassName("trans")) { 
      var mypng = bg.substring(5,bg.length-2);
      e.setStyle({  
        filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mypng + "', sizingMethod='" + (e.currentStyle.backgroundRepeat == "no-repeat" ? "crop" : "scale") + "')",
        backgroundImage : "none"}); 
    }
  },

  "fnLoadPngs" : function (img){
    if (img.src.match(/\.png$/i) != null) {
      var src = img.src;
      var div = document.createElement("DIV");    
      div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
      div.style.width = img.width + "px";
      div.style.height = img.height + "px";
      img.replaceNode(div); 
    }
  },

  "swapBg" : function (el) {
    var position = "top";
    if (!el.style.backgroundPosition.match(/bottom/gi)) position = "bottom";
    el.setStyle({ backgroundPosition: "left " + position });
  }

};


Effia.Init = function() {
  if (Prototype.Browser.IE) {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, "");
    if (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7) {
      $$("img.trans").each(Effia.display.fnLoadPngs);
    }
  }
};

document.observe("dom:loaded", function() { setTimeout(Effia.Init, 10); });

/*
 //timer_1 = window.setTimeout("show_next()",2000);
function auto_switch_area_imgs(){
  if (img_default) {
    auto_switch_area_img(img_selected);
    img_default = false;
  }
  else {
    auto_switch_area_img(0);
    img_default = true;
  }
  timer_2 = window.setTimeout("auto_switch_area_imgs()",800);
}

function show_iframe(id) {
  for(var i=1; i<=img_max; i++) {
    if(i == id) {
      document.getElementById("iframe_"+i).style.display = 'block';
    }
    else {
      document.getElementById("iframe_"+i).style.display = 'none';
    }
  }

}
*/

/*
function show_next()
{
  if (img_count > img_max) { 
    switch_area_img(0);
    window.clearTimeout(timer_1);
    window.clearTimeout(timer_2);
    //$('map-bkg').hide();
  }
  else {
    window.clearTimeout(timer_2);
    auto_switch_area_imgs();
    img_selected = img_count;
    img_count++;
    timer_1 = window.setTimeout("show_next()",4000);
  }
} 

img_count = img_max +1 ;
  window.clearTimeout(timer_1);
  window.clearTimeout(timer_2);

*/


