$(function() {
    InitCickClear();
    InitVideo();
});

function InitVideo() {
    var videos = $('.VideoBlocImageFloat');
    var index = videos.length;
    var videoElem = videos.get(Math.round(index / 2)-1);
    //var videoElem = videos.get(3);
    $(videoElem).children("a").triggerHandler('mouseover');
}

function VideoHover(elem) {
    $('.VideoBlocImageFloat1').hide();
    $('#' + elem).show();
}

function afficher(element) {
    var elem = document.getElementById(element);
    if(elem)
        elem.style.display = "block";
}

function cacher(element) {
    var elem = document.getElementById(element);
    if(elem)
        elem.style.display = "none";
}

function FedOver(id) {
    $('#Fed-' + id).addClass('selectedFederation');
}

function FedOut(id) {
    $('#Fed-' + id).removeClass('selectedFederation');
}

function InitLinkActive() {
    $('li.link a').click(function() { // When an item is clicked
        var id = $(this).attr('rel'); // Retrieve its content ID
        var showing = $(id).is(':visible'); // Remember if that content was already visible

        $('li.link a').removeClass('active'); // Mark all as inactive
        if (!showing) { // If it wasn't visible

            $(this).addClass('active'); // Mark link as active
        }
    });
}

function InitCickClear() {
    $(".clickClear").focus(function() {
        if ($(this).val() == $(this).attr("title")) { $(this).val(''); }
    });

    $(".clickClear").blur(function() {
        if ($(this).val() == '') { $(this).val($(this).attr("title")); }
    });

}

function changerTaille(modif) {
    var size = document.getElementsByTagName("body")[0].style.fontSize;
    size = size + modif;
    alert(size);
    if (size > 0.5 && size < 1.5)
        document.getElementsByTagName("body")[0].style.fontSize = size + "em";
}

function resizeText(multiplier) {
    if (document.body.style.fontSize == "") {
        document.body.style.fontSize = "1.0em";
    }
    var current = parseFloat(document.body.style.fontSize) + (multiplier * 0.1);
    if (current > 0.4 && current < 1.6)
        document.body.style.fontSize = current + "em";
}

function menuOver() {
    $(this).children('.ImageMenuH').hide();
    $(this).children('.ImageMenu').show();
    $('#light' + GetMenuContentFromIndex($(this))).show();
}

function menuOut() {
    $(this).children('.ImageMenu').hide();
    $(this).children('.ImageMenuH').show();
    $('#light' + GetMenuContentFromIndex($(this))).hide();
}

function menuContentOver() {
    var index = GetMenuContentFromIndex($(this));
    $('#mainMenu' + index).mouseover();
}

function menuContentOut() {
    var index = GetMenuContentFromIndex($(this));
    $('#mainMenu' + index).mouseout();
}

function GetMenuContentFromIndex(elem) {
    var id = $(elem).attr('id');
    var idString = new String(id);
    idString = idString.replace('mainMenu', '').replace('ImageMenu', '').replace('ImageMenuH', '').replace('light', '');
    return idString;
}

function noMenuAction() {}

function menuClick() {
   // var index = GetMenuContentFromIndex($(this));
   // $('#mainMenu' + index).mouseover();
   // $('#fade').show();
}

function fadeClick() { 
  $(this).hide();
  //$('.mainMenuHover').mouseout();
  $('#light0').hide();
  $('#light1').hide();
  $('#light2').hide();
  $('#light3').hide();
  $('.onglet').hide();
  $('.Logo').css({zIndex: 1010});
  window.location.reload(true);
  
}
function ContentClick() { 
  $(this).hide();
  //$('.mainMenuHover').mouseout();
  $('#light0').hide();
  $('#light1').hide();
  $('#light2').hide();
  $('#light3').hide();
  $('.onglet').hide();
  $('.Logo').css({zIndex: 1010});
  window.location.reload(true);

}


function MenuOver2() {
   // var idString = new String($(this).attr('id'));
   // var idNumber = idString.replace('menu', '');
   // $('#light' + idNumber).show();
	
}

function MenuOut2() {
   // var idString = new String($(this).attr('id'));
   // var idNumber = idString.replace('onglet', '');
   // $('#light' + idNumber).hide();
 

}

function MenuClick2() {
  // var idString = new String($(this).attr('id'));
  // var idNumber = idString.replace('onglet', '');
   // $('#light' + idNumber).show();
   // $('#fade').show();
	// $('#light0').show();
   //$('#onglet' + idNumber).unbind('mouseleave');
	$('.Logo').css({zIndex: 11});
	$('.MenuBloc').css({ zIndex: 10 });
	
    return false;
}
//flexislider
var speed = 50;
	var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 

$(window).load(function(){
	pic = $("#slider").children("img");
	numImgs = pic.length;
	arrLeft = new Array(numImgs);
	
	for (i=0;i<numImgs;i++){
		
		totalWidth=0;
		for(n=0;n<i;n++){
			totalWidth += $(pic[n]).width();
		}
		
		arrLeft[i] = totalWidth;
		$(pic[i]).css("left",totalWidth);
	}
	
	myInterval = setInterval("flexiScroll()",speed);
	$('#imageloader').hide();
	$(pic).show();	
});

function flexiScroll(){

	for (i=0;i<numImgs;i++){
		arrLeft[i] -= 1;		

		if (arrLeft[i] == -($(pic[i]).width())){	
			totalWidth = 0;	
			for (n=0;n<numImgs;n++){
				if (n!=i){	
					totalWidth += $(pic[n]).width();
				}			
			}	
			arrLeft[i] =  totalWidth;	
		}					
		$(pic[i]).css("left",arrLeft[i]);
	}
}













