var save = 'nos-realisations-map-1';

jQuery(document).ready(function(){
  
  jQuery('.nos-realisations-map-hover').hover(function() {
    jQuery('.nos-realisations-map').removeClass(save).addClass('nos-realisations-map-' + jQuery(this).attr('id'));
    save = 'nos-realisations-map-' + jQuery(this).attr('id');

    for(i = 1; i < 6; i++)
      jQuery('.continent-' + i).css('display', 'none');
    jQuery('.continent-' + jQuery(this).attr('id')).css('display', 'inline');
  });

  jQuery('.nos-realisations-map').mouseleave(function() {
    //jQuery(this).removeAttr('class').addClass('nos-realisations-map');
    jQuery(this).removeClass(save);
    for(i = 1; i < 6; i++)
      jQuery('.continent-' + i).css('display', 'none');
  });
  
  
  //jQuery('.container-left').tinyscrollbar();
  if(jQuery('.container-text').length && jQuery('.scrollbar').length)
    jQuery('.container-text').tinyscrollbar();

  if(jQuery('.big-scrollbar').length && jQuery('.scrollbar').length)
    jQuery('.big-scrollbar').tinyscrollbar();

  setInterval( "slideSwitch()", 3000 );
  setInterval( "temoignageSwitch()", 15000 );

  jQuery('.circuit').click(function(){
    location = jQuery(this).find('a').attr('href');
  });
  
  if(jQuery('.animation-div').length) {
    /*jQuery('.animation-div').html('<table id="animation" valign="middle" align="center" width="100%" height="780px">'+
                                  '<tr>'+
                                    '<td align="center" valign="middle">'+
                                      '<object type="application/x-shockwave-flash"  data="/flash/coniraya.swf" width="950" height="520" id="coniraya" align="middle" onmouseup="hideAnimation();">'+
                                        '<param name="allowScriptAccess" value="sameDomain" />'+
                                        '<param name="allowFullScreen" value="false" />'+
                                        '<param name="wmode" value="transparent" />'+
                                        '<param name="src" value="/flash/coniraya.swf" />'+
                                        '<param name="quality" value="high" />'+
                                        '<embed type="application/x-shockwave-flash"  src="coniraya.swf" width="950" height="520"></embed>'+
                                      '</object>'+
                                      '<div><a href="#" class="animation-link">Aller directement au site</a></div>'+
                                    '</td>'+
                                  '</tr>'+
                                '</table>');*/

    jQuery('.animation-link').click(function(){
      return hideAnimation();
    });
  }
});

function hideAnimation() {
    jQuery('.animation-div').remove();
    return false;
}

//Ouverture des photos des circuits en popup
function photoNewWindow(url, ref, w, h) {
  var width = (parseInt(w) + 20);
  var height = (parseInt(h) + 20);
  var top = (screen.height - height) / 2;
  var left = (screen.width - width) / 2;
  window.open(url, 'Réf. : ' + ref, config='height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no, top=' + top + ', left=' + left);
}

//Slideswitch des images
function slideSwitch() {
    var $active = jQuery('#subheader img.active');

    if ( $active.length == 0 ) $active = jQuery('#subheader img:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('#subheader img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

//Slideswitch des images
function temoignageSwitch() {
    var $active = jQuery('.temoignage-client li.active');

    if ( $active.length == 0 ) $active = jQuery('.temoignage-client li:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('.temoignage-client li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
}
