var path_base_abs = "http://www.annecy.org/";
/* function init_js
 * Initialise les action JS de la page courante
 * @param : str_json     //str_json = ""
 */
function init_js(json_param)
{
  init_barre_citia();
  init_menu( json_param[0], json_param[1], json_param[2], json_param[3] );
  //ajout JC pour menu network
  init_menu_class( json_param[0], json_param[1], json_param[2], json_param[3] );  
  
  init_modal();
  resizeBackground();

  //$(".visionneuse").loopedSlider();
  $(window).resize(function(){
      resizeBackground();
  });
}

/* function init_barre_citia
 * Gère l'affichage ou non des intitulés de site dans la barre
 * @param : NULL
 */
function init_barre_citia()
{
  $('#bc_contenu .kwicks').kwicks({
    max: 90,
    min: 35,
    spacing: 2,
    duration: 300,
    sticky: true
  });
  
  $("a#btn_print").click(function() {
    window.print();
    return false;
  });
}

/* function init_menu
 * Initialise l'interactivité du menu
 * @param : NULL
 */
function init_menu( langue, diffusion, n1_actif, n2_actif )
{
  var index_1 = $( '#menu h3' ).index( $( '#mp_'+langue+'_'+diffusion+'_'+n1_actif ).parent() );

  var index_acco_1 = 0;
  var index_std = 0;

  $( "#menu h3" ).each( function() {
    if( $(this).hasClass( "is_menu" ) && index_std < index_1 )
    {
      index_acco_1++;
    }
    index_std++;
  } );
  
  if( $( '#mp_'+langue+'_'+diffusion+'_'+n1_actif ).parent().next().is( ".menu1" ) ) //index_acco_1 != 0 )
    $( "#menu" ).accordion( { header: "h3.is_menu", active: index_acco_1, autoHeight: false } );
  else
    $( "#menu" ).accordion( { header: "h3.is_menu", active: false, autoHeight: false } );
  // Si le N2 a un sous menu...
  if( n2_actif != "undefined" && $( '#mp_'+langue+'_'+diffusion+'_'+n2_actif ).parent().next().is( ".menu2" ) )
  {
    var index_2 = $( "#menu h3.is_menu" ).eq( index_acco_1 ).next().find( "h4" ).index( $('#mp_'+langue+'_'+diffusion+'_'+n2_actif ).parent() );
    $( "#menu h3.is_menu" ).eq( !index_acco_1 ).next( "div.menu1" ).accordion( { header: "h4", active: false, autoHeight: false } );
    $( "#menu h3.is_menu" ).eq( index_acco_1 ).next( "div.menu1" ).accordion( { header: "h4", active: index_2, autoHeight: false } );
  }
  else
    $( "div.menu1" ).accordion( { header: "h4", active: false, autoHeight: false } );

  $( "#menu h3.is_menu" ).click( function() {
    $( "#menu h3" ).each( function() {
      if( !$(this).hasClass( "is_menu" ) )
      {
        $(this).next( "div.menu1" ).hide( "fast" );
      }
    } );
  } );

  $( "h4.non_noeud a" ).click( function() {
    document.location.href = $(this).attr( "href" );
  } );
}

/* function init_menu_class (network)
 * Initialise l'interactivité du menu
 * @param : NULL
 */
function init_menu_class( langue, diffusion, n1_actif, n2_actif )
{
  var index_1 = $( '.menu h3' ).index( $( '#mp_'+langue+'_'+diffusion+'_'+n1_actif ).parent() );

  var index_acco_1 = 0;
  var index_std = 0;

  $( ".menu h3" ).each( function() {
    if( $(this).hasClass( "is_menu" ) && index_std < index_1 )
    {
      index_acco_1++;
    }
    index_std++;
  } );
  
  if( $( '#mp_'+langue+'_'+diffusion+'_'+n1_actif ).parent().next().is( ".menu1" ) ) //index_acco_1 != 0 )
    $( ".menu" ).accordion( { header: "h3.is_menu", active: index_acco_1, autoHeight: false } );
  else
    $( ".menu" ).accordion( { header: "h3.is_menu", active: false, autoHeight: false } );
  // Si le N2 a un sous menu...
  if( n2_actif != "undefined" && $( '#mp_'+langue+'_'+diffusion+'_'+n2_actif ).parent().next().is( ".menu2" ) )
  {
    var index_2 = $( ".menu h3.is_menu" ).eq( index_acco_1 ).next().find( "h4" ).index( $('#mp_'+langue+'_'+diffusion+'_'+n2_actif ).parent() );
    $( ".menu h3.is_menu" ).eq( !index_acco_1 ).next( "div.menu1" ).accordion( { header: "h4", active: false, autoHeight: false } );
    $( ".menu h3.is_menu" ).eq( index_acco_1 ).next( "div.menu1" ).accordion( { header: "h4", active: index_2, autoHeight: false } );
  }
  else
    $( "div.menu1" ).accordion( { header: "h4", active: false, autoHeight: false } );

  $( ".menu h3.is_menu" ).click( function() {
    $( ".menu h3" ).each( function() {
      if( !$(this).hasClass( "is_menu" ) )
      {
        $(this).next( "div.menu1" ).hide( "fast" );
      }
    } );
  } );

  $( "h4.non_noeud a" ).click( function() {
    document.location.href = $(this).attr( "href" );
  } );
}

/* function init_modal
 * Initialise l'interactivité des fenètre modales
 * @param : NULL
 */
function init_modal()
{
  $('a.nyroModal').nyroModal();
}

/* function resizeBackground
 * Gère l'affiche du background
 * @param : NULL
 */
function resizeBackground()
{
  var ImgH = $("#background #fond").height();
  var ImgW = $("#background #fond").width();

	var windowH = $(window).height();
	var windowW = $(window).width();

  var containerH = $(".container").height();
	var containerW = $(".container").width();
  if( containerH > windowH && containerW > windowW )
  {
    $("#logout").append("ahah");
    windowH = containerH;
    windowW = containerW;
  }

  if( windowH > windowW )
    var ratio = windowW / ImgW * 100 - 20;
  else
    var ratio = windowH / ImgH * 100 - 20;

  var newImgW = Math.round(ImgW * ratio / 100);
  var newImgH = Math.round(ImgH * ratio / 100);

	$("#background #fond").width( newImgW+"px");
  $("#background #fond").height( newImgH+"px");
}

/* function init_box
 * Gère l'amnmation des mini_box 4 blocs
 * @param : NULL
 */
function init_boxgrid()
{
  //Coulissement de légende (Une partie cachée à visible)
  $('.boxgrid.caption').hover(function() {
    $(".cover", this).stop().animate({top:'40px', height :'66px'},{queue:false,duration:160}).find("p").show();
  }, function() {
    $(".cover", this).stop().animate({top:'81px', height :'25px'},{queue:false,duration:160}).find("p").hide();
  });
}

/* function init_contact
 * Gère le survol des bloc de contact
 * @param : NULL
 */
function init_contact()
{
  $(".blc_contact").hover(function()  {
    $(this).addClass("hover");
  },
  function()  {
    $(this).removeClass("hover");
  });
}


/* function init_news_flash
 * Rend les news défilante selon les parametres
 * @dependances: jquery.easynews.js 
 * @param id_news:String
 * @param vitesse:Number 
 */
function init_news_flash()
{

  $.init_news();
}

/* function init_home_mifa
 * Initialise la home page du Mifa
 * @param NULL
 */
function init_home_mifa()
{
  
    $('dl.chiffres dt span').each(function(){
   // $('ul.chiffres li span').each(function(){
        id_courant = $(this).attr("id");
        s1 = new SWFObject("/resources/swf/mifa-chiffres.swf", "so_chiffres", "100", "30", "9", "#fff");
       	s1.addParam('flashvars','chiffre='+$(this).text());
       	s1.addParam('wmode','transparent');
        s1.write(id_courant);
    });
    
    $("div#slider").codaslider();
}

/* function init_modal_jury
 * Initialise les comportements modal sur les jury
 * @param NULL
 */
function init_modal_jury()  
{
  $(".modal_jury").click(function() {
			$.nyroModalManual({ content: $($(this).attr("href")).html() });
  });
}

function init_planlieux( mapname )
{
  $('a.detail_lieu').click( function()
  {
    var valeurhref = $(this).attr("href");
    var idhref     = valeurhref.substr( 1,9 ) + '('+mapname+')';
    
    $( "#details_lieux blockquote" ).each( function() {
      if( !$(this).hasClass( "masque" ) )
      {
        $(this).addClass( "masque" );
      }
      if( !$(this).hasClass( "hide" ) )
      {
        $(this).addClass( "hide" );
      }
    } );
    $( valeurhref ).removeClass( "masque" );
    $( valeurhref ).removeClass( "hide" );
    eval( idhref );
    return false;
  });
}