

$(function()
{
	$("#conteneur_bg").css('height', ($(document).height()-1168)+'px');
	$("#conteneur_degrade").css('top', $("#conteneur_bg").height()+'px');
	$("#contenu_principal").css('minHeight', ($(window).height()-600)+'px');
	$("#habillage_link").click(function() {
		window.open($("#habillage_link a").attr('href'));
	});
	
	$("#habillage_link_deux").click(function() {
		window.open($("#habillage_link_deux a").attr('href'));
	})
	$("#boite_services").cycle({
		pause: 1,
		random: 1,
		timeout: 6000		
	});

	$("#boite_manchettes").cycle({
		pause: true,
		timeout: 5000,
		//speed: 500,
		startingSlide: 0,
		before: 
		function(currSlideElement, nextSlideElement, options, forwardFlag)
		{
			id = "#"+$(nextSlideElement).attr('id');
			switchManchette(id);
		},
		cleartypeNoBg: true
	});

	function switchManchette(manchette, full)
	{
		if (full == null)
			full = false;
		s = manchette.split("-");
		currentNews = parseInt(s[1]) - 1;
		if (full)
		{
			$("#manchette .manchette_contenu").css('display', 'none');
			$("#manchette .manchette_contenu").css('opacity', '0');
			$(manchette).css('display', 'block');
			$(manchette).css('opacity', '1');
		}
		$("#manchette_titres li").removeClass('selectionne');
		$(manchette+"-lien").addClass('selectionne');
		return false;
	}
	
	$("#manchette_titres li a").click(function() {
		$("#boite_manchettes").cycle('pause');
		$("#bouton_pause").addClass("active");
		$("#bouton_play").removeClass("active");
		switchManchette($(this).attr('href'), true);
		return false;
	});

	
	
	
	$("#bouton_pause").click(function() 
	{ 
		$("#boite_manchettes").cycle('pause');
		$("#bouton_pause").addClass("active");
		$("#bouton_play").removeClass("active");
		return false; 
	});
	
	$("#bouton_play").click(function() { 
		
		$("#boite_manchettes").cycle({
			pause: 0,
			timeout: 5000,
			speed: 500,
			startingSlide: currentNews,
			before: 
				
			function(currSlideElement, nextSlideElement, options, forwardFlag)
			{
				id = "#"+$(nextSlideElement).attr('id');
				switchManchette(id);
			},
			cleartypeNoBg: true
		}); 
		
		$("#bouton_pause").removeClass("active");
		$("#bouton_play").addClass("active");
		return false;
	});

	
	$("#bloc_menus #mini_menu li a").click(function()
	{
		switchBlocChoix($(this).attr('href'));
		return false;
	});
	
	function switchBlocChoix(bloc_choix)
	{
		$(".bloc_menu_contenu").hide();
		$(bloc_choix).show();
		$("#mini_menu li").removeClass('selectionne');
		$(bloc_choix+"-lien").addClass('selectionne');
	}

	$("a.exterieur").click(function() { window.open($(this).attr('href')); return false; });
	
	switchManchette("#manchette-1", true);
	switchBlocChoix("#minimenu-1");
	
	newsInteralId = setInterval( "slideSwitch()", 5000 );
	$("#nextNews").click( function() {
		clearInterval(newsInteralId);
		var active = $('#slideshow div.active');
		if ( active.length == 0 ) {
	    	active = $('#slideshow div:last');
	    }
		
		// use this to pull the images in the order they appear in the markup
		var next =  active.next().length > 0 ? active.next(): $('#slideshow div:first');	    
		
		active.removeClass('active');
		next.addClass('active');
		
		active.fadeOut('slow');
		$('#thumb'+active.attr('id') + ' img').removeClass('activeThumbnail');
		$('#thumb'+next.attr('id') + ' img').addClass('activeThumbnail');
		next.fadeIn('slow');
		
		newsInteralId = setInterval( "slideSwitch()", 5000 );
	});

	$("#prevNews").click( function() {
		clearInterval(newsInteralId);
		var active = $('#slideshow div.active');
		if ( active.length == 0 ) {
	    	active = $('#slideshow div:last');
	    }
		
		// use this to pull the images in the order they appear in the markup
		var prev =  active.prev().length > 0 ? active.prev(): active.siblings(':last');	    
		
		active.removeClass('active');
		prev.addClass('active');
		
		active.fadeOut('slow');
		$('#thumb'+active.attr('id') + ' img').removeClass('activeThumbnail');
		$('#thumb'+prev.attr('id') + ' img').addClass('activeThumbnail');
		prev.fadeIn('slow');
		
		newsInteralId = setInterval( "slideSwitch()", 5000 );
	});
	
	$("#newsSelector a.thumbnails").click(function()
	{
		thumbnailOnclick($(this).attr('id'));
	});
		


	
	
	
	$("#close_btn").click(function(event) {
		$('#contact_container').fadeOut('slow');		
	});
	
	$("#contact_us").click(function(event) {
		$('#contact_container').fadeIn('slow');		
	});
	
	
	
	$("#ecrire_un_message").click(function()
	{
		 $("#form_gestionnaire").slideToggle();
		 return false;
	});
	
	$(".table_ligue tr:odd").addClass('c1');
	$(".table_ligue tr:even").addClass('c2');

	
	
	$(".lightbox").lightBox({fixedNavigation:true});
	
	$(".boite_toggle h4").click(function()
	{
		$(this).toggleClass('active');
		$(this).siblings(".boite_toggle_contenu").slideToggle();
	});
	
	$('#search_league').autocomplete(
	{ 
	  serviceUrl: 'ligueAutoComplete.action',
	  minChars:2,
	  delimiter: /(,|;)\s*/,
	  maxHeight:400,
	  width:300,
	  zIndex: 9999,
	  deferRequestBy: 0,
	  noCache: true,
	  // Mettre lookup en commentaire quand on veux tester notre vrai json
	  //lookup: ['zLigue Ligue <span>fdfsdhifsd</span>', 'zLigue Ligue <span>fdfsdhifsd</span>','zLigue Ligue <span>fdfsdhifsd</span>','zLigue Ligue <span>fdfsdhifsd</span>','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1','Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1', 'Ligue Ligue 1',], //local lookup values 
	  onSelect: function(value, data)
	  { 
	      window.location = data;
	  }
	});

	
	$("#changer_region > a").click(function()
	{
		$("#changer_region > div").slideToggle();
		return false;
	});
	
	$("#search_league_button").click(function()
	{
		$("#search_league").focus();
	});
	
	$(".search_league").focus(function()
	{
		if(this.value == this.defaultValue)
			this.value = '';
	});

	
});

$(function()
{
	nbBoutons = $("#manchette #manchette_titres").children().size();
widthBouton = parseInt(100 / nbBoutons);
//$("#manchette #manchette_titres li").css('width', widthBouton + '%');
});

/* SLIDESHOW */

var newsInteralId = 0;


function slideSwitch() { 
	var active = $('#slideshow div.active');
	if ( active.length == 0 ) {
    	active = $('#slideshow div:last');
    }
	
	// use this to pull the images in the order they appear in the markup
	var next =  active.next().length > 0 ? active.next(): $('#slideshow div:first');
	
	//alert('#thumb'+next.attr('id'));
	
	active.removeClass('active');
	
	next.addClass('active');
	
	active.fadeOut('slow');
	$('#thumb'+active.attr('id') + ' img').removeClass('activeThumbnail');
	$('#thumb'+next.attr('id') + ' img').addClass('activeThumbnail');
	next.fadeIn('slow');
};


function thumbnailOnclick (newsId) {
	clearInterval(newsInteralId);
	var active = $('#slideshow div.active');
	var next = $("#" + newsId.substring(5,9));
	
	active.removeClass('active');
	next.addClass('active');
	
	active.fadeOut('slow');
	$('#thumb'+active.attr('id') + ' img').removeClass('activeThumbnail');
	$('#thumb'+next.attr('id') + ' img').addClass('activeThumbnail');
	next.fadeIn('slow');
	   
    newsInteralId = setInterval( "slideSwitch()", 5000 );
};

function clearForm() {	 
	 $("input#email").val('');
	 $("input#sujet").val('');
	 $("input#cronique_contact_mess").val('');
	 $("input#cronique_contact_mess").checked = false;
	}

var currentNews = 0;
