// JavaScript Document
var $k = jQuery.noConflict();
// Use jQuery via $k(...)
$k(document).ready(function(){
							
	jQuery(function( $ ){
		$.easing.elasout = function(x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		};
	});
	
	/* Tooltips */
	$k(".tooltips").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: "::",
		fade: 250
	});

							
	/* Menu Déroulant */
	$k("li.menuLinkNiv1").bind('mouseleave',function(event){
		$k(this).children("ul.menuNiv1").slideUp(100);
    }).bind('mouseenter',function(event){
		if($k(this).children("ul.menuNiv1").css("display") == "none"){
			$k(this).children("ul.menuNiv1").slideDown(100);
		}
    });
	$k("li.menuLinkNiv2").bind('mouseleave',function(event){
		$k(this).children("ul.menuNiv2").slideUp(100);
    }).bind('mouseenter',function(event){
		if($k(this).children("ul.menuNiv2").css("display") == "none"){
			$k(this).children("ul.menuNiv2").slideDown(150);
		}
    });
	$k("a.MenuNonLink").click(function(event){ // desactivation du clic sur les liens menus parents
		event.preventDefault();
	});
	
							
	/* Desactivation des petites icones de jeux dans le header */
	$k("li.iconGameSmall").click(function(event){
		if( $k(this).hasClass("disabled") ){
			alert("Vous n'avez pas acces a ce jeu !");
			event.preventDefault();
		}
	});
	
	/* Desactivation des grandes icones de jeux sur la home */
	/*$k("div.image").click(function(event){
		if( $k(this).hasClass("disabled") ){
			alert("Vous n'avez pas acces a ce jeu !");
			event.preventDefault();
		}
	});*/
	/* Desactivation des liens vers les jeux sur la home */
	/*$k("div.linkDisabled").click(function(event){
		alert("Vous n'avez pas acces a ce jeu !");
		event.preventDefault();
	});*/

	
	
	/* Liens des blocks jeux sur la home */
	$k("div.game-block div.hold div.block").hover(
		function () {$k(this).children("div.image").children("div").addClass("iconGameBigOver");},
		function () {$k(this).children("div.image").children("div").removeClass("iconGameBigOver");}
	);
	$k("div.game-block div.hold div.block").click(function(event){
		var urlGame = $k(this).children("div.link").children("a").attr("href"); // recup de l'url du lien
		if(urlGame){
			window.location.href=urlGame;
		} else {
			alert("Vous n'avez pas acces a ce jeu !");
			event.preventDefault();
		}
	});
	/*$k("div.game-block div.hold div.block a").hover(
		function () {
			if($k(this).parent().hasClass("linkDisabled"))
				$k(this).parent().parent().next(".thereasonwhy").show(); 
		},
		function () {
			if($k(this).parent().hasClass("linkDisabled"))
				$k(this).parent().parent().next(".thereasonwhy").hide(); 
		}
	);*/

	
	/* Phrase scrollante en header */
	$k("p.scrollingText").marquee();
	
	
	/* Tooltip Tournaments */
	$k("td.player").hover(
		function(){
			var cibleTooltip = $k(this).attr("alt");
			$k("#"+cibleTooltip).show(); // rollover -> show
			$k(this).mousemove(function(e){ // move with mouse										
				var wWidth = $k(window).width();
				var containerWidth = $k("#wrapper").width();
				var tooltipWidth = $k(".tooltip").width();
				var posx = e.pageX-((wWidth-containerWidth)/2);
				$k("#"+cibleTooltip).css('top', (e.pageY)-220).css('left', (posx)-tooltipWidth);
			});
		},
		function(){
			var cibleTooltip = $k(this).attr("alt");
			$k("#"+cibleTooltip).hide(); // rollout -> hide
		}
	);
	
	/* Tableaux Tournois tablesorter */	
	$k(".tournamentTable").tablesorter(); 
	$k(".resultTable").tablesorter();
	
	
	
	
	/* Faux Popups */
	$k(".boxy").boxy();
	$k(".boxyFull").click(function(event){
		var boxyTitle = $k(this).attr("title");
		var boxyContent = this.getAttribute('href');
		new Boxy(boxyContent, {title: boxyTitle, modal: true});
		event.preventDefault();
	});
	
	/* Images Lightbox */
	$k("a.lightbox").lightBox();
	
	/* Smooth Scrolling */
	//$.scrollTo( '#topPage', 800, {easing:'elasout'} );
	$k("a.ancre").click(function(event){
		var anchorTarget = $k(this).attr("href");
		$k(document).scrollTo(anchorTarget,1000);
		event.preventDefault();
	});
	

	$k(".info-list li a").click(function(){window.location.replace($k(this).attr("href"));return false;});
	$k(".info-list li").toggle(function(){
		
		$k(this).css("overflow","hidden");	
		$k(this).css("height","11px");
		
	},function(){	
		$k(this).css("overflow","");	
		$k(this).css("height","auto");	
	});
	/*$k(".info-list li a").click(function(){window.location.replace($k(this).attr("href"));});*/
	
	

	/* ********** RANKINGS RIGHT ************ */
	$k(".rankingOpenable:gt(0)").parent().parent().next(".c").height("0");
	$k(".rankingOpenable:gt(0)").parent().parent().next(".c").css("display","none");
	$k(".rankingOpenable:lt(1)").parent().parent().next(".c").height("auto");
	
	$k(".rankingOpenable").click(function(){	
		
		if($k(this).parent().parent().next(".c").height()==0)
		{
			$k(this).parent().parent().next(".c").css("display","block");
			$k(this).parent().parent().next(".c").css("height","auto").slideUp(0).slideDown(1000);			
		}
		else{	
			$k(this).parent().parent().next(".c").css("display","block");
			$k(this).parent().parent().next(".c").animate({height: "0px"},	1000);
			//$k(this).parent().parent().next(".c").css("height","0px");
		}
	});
	
});
