var isOver="out";
$(document).ready(function(){
	///////////////// PAGE COMBAT DES PROS ////////////////////
	if ( $("#voirPrix").length > 0 ) {
		var voirPrixOrginal = $('#voirPrix').html();
		$('#voirPrix').click(function(){
			if($('#voirPrix').html() == $('#fermerPrix').html()){
				$('#blockConteneurPrix').slideToggle('slow',changerTxt(this.id,voirPrixOrginal));
			}else{
			$('#blockConteneurPrix').slideToggle('slow',changerTxt(this.id,$('#fermerPrix').html()));
			}
			return false;
		})
		$('#fermerPrix').click(function(){
			$('#blockConteneurPrix').slideToggle('slow',changerTxt('voirPrix',voirPrixOrginal));
			
			return false;
		})
	}
	var source="";
	
	$('.cdp_big_opener').mouseover(function(){
		//isOver="in";
		source=this.src;
		this.src="http://www.pratico-pratiques.com/public/images/combatdespros/details.jpg";
		//var id = (this.id).substr((this.id).indexOf("r")+1,(this.id).length);
		//setTimeout("openBig("+id+")","500");
		//return false;
	})
	$('.cdp_big_opener').mouseout(function(){
		//isOver="out";
		this.src=source;								   
		//var id = (this.id).substr((this.id).indexOf("r")+1,(this.id).length);
		//$('#cdp_big'+id).fadeOut('slow');
		//return false;
	})
	$('.voter').click(function(){
		$('.participationCombat').fadeIn('slow');
		var id = (this.id).substr((this.id).indexOf("r")+1,(this.id).length);
		var num = parseInt(id);
		$("#vote option:eq("+num+")").attr("selected","selected")
		return false;
	})
	$('.fermerVote').click(function(){
		$('.participationCombat').fadeOut('slow');
		return false;
	})
	$('.voirRecette').click(function(){
		var id = (this.id).substr((this.id).lastIndexOf("e")+1,(this.id).length);
		$('#recetteTotale'+id).fadeIn('slow');
		return false;
	})
	$('.fermerRecette').click(function(){
		var id = (this.id).substr((this.id).lastIndexOf("e")+1,(this.id).length);
		$('#recetteTotale'+id).fadeOut('slow');
		changeActiveStyleSheet('print_combatdespros_recettes','print_combatdespros')
		return false;
	})
	$('.printRecette').click(function(){
		var id = (this.id).substr((this.id).lastIndexOf("e")+1,(this.id).length);
		changeActiveStyleSheet('print_combatdespros','print_combatdespros_recettes'+id)
		window.print();
		return false;
	})
	//Formulaires validés en Jquery
	var formValidator = new ValidatorClass();
		formValidator.init({
		  form:           "#fCombatdespros",
		  isRequired:     ['adresse', 'codepostal', 'ville', 'telephone','captchaWord'],
		  bindElement:    '#button',
		  callback:       function() {
			  var retourjcap = jcap();
			  if(retourjcap==true){
				$('#fCombatdespros').submit();
			  }else{
				$("#fValidateErreurs").html("<p>Le mot transcrit ne correspond pas &agrave; l'image de s&eacute;curit&eacute;.</p>");
				$("#fValidateErreurs").css('display','block');
			  }
		  }
		});	
	stylesheetStartup();
});

function openBig(id){
	if(isOver=="in"){
		$('#cdp_big'+id).fadeIn('slow');
	}
	clearTimeout();
}

function changerTxt($id,$valueText){
	$('#'+$id).html($valueText);
}

function changeActiveStyleSheet(ancien, nouveau){
	if(document.styleSheets){
		for (var StyleSheetIterator = 0; StyleSheetIterator < document.styleSheets.length; StyleSheetIterator++){
			if((document.styleSheets[StyleSheetIterator].title).indexOf(ancien) != -1){
				document.styleSheets[StyleSheetIterator].disabled = true;
			};
			if(document.styleSheets[StyleSheetIterator].title == nouveau){
				document.styleSheets[StyleSheetIterator].disabled = false;
			};
		};
	};
}
function stylesheetStartup(){
	if(document.styleSheets){
		for (var StyleSheetIterator = 0; StyleSheetIterator < document.styleSheets.length; StyleSheetIterator++){
			if((document.styleSheets[StyleSheetIterator].title).indexOf('print_combatdespros_recette') != -1){
				document.styleSheets[StyleSheetIterator].disabled = true;
			};
			if(document.styleSheets[StyleSheetIterator].title == 'print_combatdespros'){
				document.styleSheets[StyleSheetIterator].disabled = false;
			};
		};
	};
}
