jQuery.fn.lotofoot = function( settings ) {
	settings = jQuery.extend({
		colorOver : "transparent",
		colorPair : "transparent" ,
		colorImpair : "transparent",
		selectCase : 0,
		multichoix : 0,
		listeCombo : new Array(""),
		infoPlus : 0
    }, settings );
    return this.each(function( i ) {
		jQuery.fn.lotofoot.run( jQuery( this ), settings, i );
    });
};
jQuery.fn.lotofoot.run = function( $this, settings, i ) {
	// SURVOL
	$this.mouseover ( function() { 
		$this.css("background-color", settings.colorOver ) ; 
	}) ;
	// HIGHTLIGHT
	$this.mouseout ( function() {
	 	if ( $this.attr("class") == settings.classImpair ) $this.css("background-color", settings.colorImpair ) ;
		else if  ( $this.attr("class") == settings.classPair ) $this.css("background-color", settings.colorPair ) ;
		else $this.css("background-color", "#FFF" ) ; 
	} ) ;
	// CASE & COMBO
	if ( settings.selectCase === 1 ) {
		// SETTINGS
		$this.$case =  jQuery ( "div[class=case]", $this ) ;
		$this.$case.each( function() { $(this).css("cursor","pointer"); }) ;
		$this.$input =  jQuery ( "input[class=prono]", $this ) ;
		// CLICK
		$this.$case.click ( function(e) {
			// MAJ CASE
			var idTarget =  e.target.id ;
			$laCase = $("#"+idTarget) ;
			if ( $laCase.html() === $laCase.attr("name") ) {
				// SIMPLE OU TRIPLE
				if ( settings.multichoix == 0 ) {
					$this.$case.each( function() { $(this).html($(this).attr("name")) ; $(this).css("font-weight","Normal") ;   $(this).css("color","#D00") ; }) ;
					$this.$input.val($laCase.attr("name")) ;
				} else {
					$this.$input.val($this.$input.val() + '' + $laCase.attr("name")) ;
				}
				//
				$laCase.html("X") ;
				$laCase.css("font-weight","Bold") ;
				$laCase.css("color","#000") ;
			} else {
				$laCase.html($laCase.attr("name")) ;
				$laCase.css("font-weight","Normal") ;
				$laCase.css("color","#D00") ;
				$this.$input.val($this.$input.val().replace( $laCase.html(), "" )) ;
			}
			if ( settings.multichoix == 1 ) {
					$this.$equipeA = jQuery ( "div[class^=equipe_A]", $this ) ;
					$this.$equipeB = jQuery ( "div[class^=equipe_B]", $this ) ;
					if ( !$this.$input.val().match("1") ) $this.$equipeA.css("color","#D00") ; else $this.$equipeA.css("color","#000") ;
					if ( !$this.$input.val().match("2") ) $this.$equipeB.css("color","#D00") ; else $this.$equipeB.css("color","#000") ;
					if ( $this.$input.val() === "" ) { $this.$equipeA.css("color","#000") ; $this.$equipeB.css("color","#000") ; }
			}
			// FIN MAJ CASE
			// COMBO
			if  ( settings.multichoix == 1 ) {
				$this.$combo =  jQuery ( "select", $this ) ;
				$this.$combo.empty() ;
				if ( $this.$input.val() != "" ) {
					$this.$combo.css("background-color","#fcc") ;
					var solution = settings.listeCombo[ $this.$input.val() ].length ;
					for ( var j = 0 ; j < solution ; j++ )
					{
						var valCombo = settings.listeCombo[$this.$input.val()][j] ;			
						$this.$combo.append( '<option value="'+valCombo+'">'+valCombo+' %</option>' ) ;
					}
				} else {
					$this.$combo.append( '<option value="">Repartition</option>' ) ;
					$this.$combo.css("background-color","#fff") ;
				}
			}
			// FIN COMBO
		});
	}
	// TYPE LOTO
	if ( settings.multichoix == 1 ) {
		$('input[type=radio][name=type]').click( function() {
			if ( $('input[type=radio][name=type]:checked').attr("value") === "7" && i >= 7 ) {
				//$this.fadeTo( "speed" , 0.05 ).slideUp( "slow") ;
				$this.hide() ;
				typeLoto = 7 ;
			}
			if ( $('input[type=radio][name=type]:checked').attr("value") === "15" ) {
				//$this.fadeTo( "speed" , 1 ).slideDown( "slow") ;
				$this.show() ;
				typeLoto = 15 ;
			}
		}) ;
	}
	// INFOS PLUS
	if ( settings.infoPlus == 1 ) {
		//SETTINGS
		//$this.$btn =  jQuery ( "div[class=match-plus] > div", $this ) ;
		$this.$btn =  jQuery ( "div[class^=match-plus]", $this ) ;
		$this.$plus =  jQuery ( "div[class^=info-loto]", $this ) ;
		$this.$plus.css("height", "auto") ;
		//CLICK
		$this.$btn.click ( function() {
			/*var sortie = '' ;
			$("div[class^=info-loto]").each( function() {
				if ( $(this).attr("id") != $this.$plus.attr("id") ) {
					$(this).slideUp("speed") ;
					$(this).parent().children().children().children().children(".plus").html("+") ;
				}
			}) ;*/
			$this.$plus.slideToggle("speed") ;
			//if ( $this.$btn.children().html() == "+" ) $this.$btn.children().html("&minus;") ; else $this.$btn.children().html("+") ; 
			if ( $this.$btn.hasClass("btn-plus") )  {
					$this.$btn.removeClass("btn-plus") ;
					$this.$btn.addClass("btn-moins") ;
			} else {
					$this.$btn.removeClass("btn-moins") ;
					$this.$btn.addClass("btn-plus") ;
			}
		});
	}
}
