$(function(){
  $("a.external").click( function(){
    goExit(this);
    return false;
  } );
  $('#print a').click(function(){
    print();
    return false;
  });
    
  $('#principale li.main-btn').mouseover(function(){
    $(this).children('.home-sub-menu').css('display', 'block');
  });
    
  $('#principale li.main-btn').mouseout(function(){
    $(this).children('.home-sub-menu').css('display', 'none');
  });
    
    
  $('#vote').click(function(){
    url = $(this).attr('href');
    reg = new RegExp('([0-9]+)$');
    myNumbers = url.match(reg);

    $.ajax({
      url: $(this).attr('href'),
      
      success: function(msg){
        $('#vote').parent().addClass('desable');
        $('#vote').attr('href', 'javascript:')
        $('.boutonvote').addClass('desable');
        $('.view-video .vote').text(msg);
        $('.subvideo .vote').text(msg);
        
        elmt = '#' + myNumbers[1] + ' .rate';
        $(elmt).text(msg);
      }
    });
    return false;
  });
    
  
  if($('.video-nav').html())
  {
    
    $('.video-nav-inner .video-item').each(function(){numVideo++});
    $('.video-nav-inner').css('width', numVideo * 172 + 'px');
    
    $('#upper').click(function(){
      videoUpper();
      return false;
    });
  
    $('#downer').click(function(){
      videoDowner();
      return false;
    });
    
  }
    
    
    
    
});


function videoUpper()
{
  
if(currentVideo > 0)
  {
    $('.video-nav-inner').animate({
      left: '+=170'
    }, 400);
    currentVideo--;
}
  
}

function videoDowner()
{ 
  if(currentVideo < numVideo - 5)
    {
    $('.video-nav-inner').animate({
      left: '-=170'
    }, 400);
 currentVideo++;
}
}

var numVideo = 0;
var currentVideo = 0;
var siteName = '';
var siteHref = '';
var siteHrefAlt = '';

function goExit(element)
{
  siteName = $(element).attr('title');
  siteHref = $(element).attr('href');
  siteHrefAlt = '';
  if (siteName == "facebook")
    siteHrefAlt = 'http://www.facebook.com';
							
  $("#exitlabel").html(siteName);
  $("#exitlink").html(siteHref);
  if(siteHrefAlt != '')
    $("#exitlink").html(siteHrefAlt);
  //console.log($(element).attr('href'));
	
  if($(element).attr('id') == 'facebook')
    $('#traceur').html('<iframe src="http://fls.doubleclick.net/activityi;src=2943923;type=lifes125;cat=;ord=1;num=1?" width="1" height="1" frameborder="0"></iframe>')
	
							
  sizeW = $(document).width() * 0.5;
  sizeH = 450;


  posW = ($(document).width() - sizeW) / 2;
  posH = ($(document).height() - sizeH) / 4 + $(document).scrollTop() / 4;


  $("#exit_outer").css('top', posH + 'px');
  $("#exit_outer").css('left', posW+'px');
  $("#exit_outer").css('width', sizeW + 'px');
  $("#exit_outer").css('height', sizeH+'px');
  
  $("#exit_outer").show('slow');

  return false;

}

function exitSite()
{
  window.open(siteHref);
  $("#exit_outer").hide('slow');
}

function staySite()
{
  $("#exit_outer").hide('slow');
}
