//DETECTION SI FLASH EST ACTIVE
var hasFlash = false;
try {
	var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
	if(fo) hasFlash = true;
}catch(e){
	if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
}



$(document).ready(function() {

	$("a[rel^='external']").attr("target","_blank");

	$('.regenerateCaptcha').live("click",function () {
		regenerateCaptcha();
	});
	$('#rating').live("click",function () {
		genericPrototype($(this).attr('rel'));
		return false;
	});
	$('#bookmark').live("click",function () {
		genericPrototype($(this).attr('rel'));
		return false;
	});

	 $('.colorbox').live("click", function () {
			$(this).colorbox( {
				href :$(this).attr('rel'),
				open :true,
				height:'80%',
				width:'80%'
			});
			return false;
		});
		$(document).bind('cbox_open', function(){
			$.validationEngine.closePrompt(".formError",true)
		});
		$(document).bind('cbox_closed', function(){
			$.validationEngine.closePrompt(".formError",true)
		});	
});

// disable document scrollbars when colorbox is open
$().bind('cbox_open', function(){ $('html').css({overflow:'hidden'});
}).bind('cbox_closed', function(){ $('html').css({overflow:'auto'});
}); 

// liste d'epicerie
function addToGroceryList(url) {
	$(this).colorbox( {
		href :url,
		open :true,
		onComplete : function() {
			$('#back').bind('click', function() {
				$.validationEngine.closePrompt('.formError', true);
				$.fn.colorbox.close();
				return false;
			});
		},
		onCleanup: function () {
			
		}
	});
}

// form access
$('.loginaccess').live("click",function () {
	genericPrototype($(this).attr('rel'));
	return false;
});

//form login
function formlogin(url) {
	$(this).colorbox( {
		href :url,
		open :true,
		onComplete : function() {
			$('#back').bind('click', function() {
				$.validationEngine.closePrompt('.formError', true);
				$.fn.colorbox.close();
				return false;
			});
		},
		onCleanup: function () {

		}
	});
}

$("#loginformaccess").validationEngine({ 
	unbindEngine: false,
	success : function(){ userRegistrationClass.validateLoginform()}, 
	failure : function(){} 
});


// captcha
function regenerateCaptcha(){
	$.ajax({url: '/index/ajaxreloadcaptcha/',type: 'get',
		   success: function (response) {
						$('#captchabox').html(response);
					}
		 });
}


/*
 * clear text field value on click ----->the title tag must be present and
 * contain the same text as the value
 */

$(document).ready(function(){


	var clearMePrevious = '';

	// clear input on focus
	$('.clearMeFocus').focus(function()
	{
		if($(this).val()==$(this).attr('title'))
		{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function()
	{
		if($(this).val()==''){
			$(this).val(clearMePrevious);
		}
	});
	/* accordion */

	$(".accordion .togglepost").click(function(){
		$.validationEngine.closePrompt(".formError",true);
	  $(this).parent().next().slideToggle("fast")
	  $(this).toggleClass("active");

	return false;

	});

	$(".accordion .closepost").click(function(){
		$.validationEngine.closePrompt(".formError",true)
	  $(".toggle").slideUp("fast")

	return false;

	});
	// close validation error boxes
	$(".btnpost").click(function(){
		$.validationEngine.closePrompt(".formError",true)
	});



/* Main Navigation sub menu and hover */
	$('#navBar ul.navigation li').hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none');
			});


	/* hover */
	$("#navBar ul.navigation li").hover(
		  function () {
			$(this).children(':first-child').addClass("hover");
		  },
		  function () {
			$(this).children(':first-child').removeClass("hover");
		  }
	);


/* sign in layer */
	$('#navBar .right ul.logger li.login').hover(
			function() { $('.layer', this).css('display', 'block'); },
			function() { $('.layer', this).css('display', 'none');
			});


	/* hover */
	$("#navBar .right ul.logger li.login").hover(
		  function () {
			$(this).addClass("hover");
		  },
		  function (){ 		
			$(this).removeClass("hover");
			$.validationEngine.closePrompt(".formError",true);
		  }
	);

/* recipe search advanced options toggler (accordion) */

	$(".recipeSearch .toggler span").click(function(){
	  $(".recipeSearch .moreToggle").slideToggle("fast")
	  $(this).toggleClass("active");

	return false;

	});


		$('.recipeList li .thumb .loupe').hover( function () {
			$(this).parent().parent().css('zIndex', 2);
			$(this).find('.popper').css('zIndex',10);
			$(this).parent().find('.popper').css('display','block')
		  },
		  function () {

		  });
		$('.popper').hover( function () {
			$(this).css('zIndex',10);
		  },
		  function () {
			$(this).css('zIndex',1);
			$(this).parent().parent().css('zIndex', 1);
			$(this).css('display','none')
		  });


/* TABS for contest page */

$('.tabs div.toggle').css("opacity",0);
		$('.tabs div.toggle').hide();
		$('.tabs div.toggle:first').show();
		$('.tabs div.toggle:first').css("opacity",1);
		$('.tabs ul li:first').addClass('active');

		$('.tabs ul li a.tabs').click(function(){
			$('.tabs ul li').removeClass('active');
			$(this).parent().addClass('active');
			var currentTab = $(this).attr('href');
			$('.tabs div.toggle').animate({ opacity:0}, 400,function(){
				$('.tabs div.toggle').not(currentTab).hide()
				$(currentTab).show();
				$(currentTab).animate({ opacity:1}, 400)
			});

			return false;
		});

		/* hover pour tabs */
	$(".tabs ul li").hover(
		  function () {
			$(this).addClass("hover");
		  },
		  function () {
			$(this).removeClass("hover");
		  }
	);

	/*if( hasFlash == true ){
		$(".imgRecette .vidButton, .imgEmission .vidButton").click(function(){
			$("div.vidOverlay").animate({top:"0px"},400,"easeOutCubic")	
			return false;
		});
	}

	$(".vidOverlay .text .close").click(function(){
		$("div.vidOverlay").animate({top:"260px"},400,"easeOutCubic")
		
		// DETECTION ATEDRA
		// Si True, on change seulement le parametre param
		// Si False, on change la boite au complet
		if( $("#video").length > 0 ){
			$('#video param').eq(2).attr("value","show_title=0&show_byline=0&show_portrait=0&color=71bd60&fullscreen=1");											
			$(".vidBox script").remove();			
			var htmlVideo = $(".vidBox").html();
			$(".vidBox").html(htmlVideo);
		}

		return false;
	});*/


});




function checkKeywordSearch(){
	searchkeyword = $("#searchkeyword").val();
	if (searchkeyword.substring(0,11)=='RECHERCHER:'){
		$("#searchkeyword").val('');

		var Errholder = document.createElement('div');
		   $(Errholder).html('<div class="formError searchkeywordformError" style="top: 133.5px; left: 1036.5px; opacity: 0.87;"><div class="formErrorContent">* Ce champ est requis<br></div><div class="formErrorArrow"><div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div></div></div></div>');

		   $("body").append(Errholder);
		   $(Errholder).animate({"opacity":0.87},function(){return true;});	
		   $(Errholder).fadeTo('10000','0',function(){
			    $(this).remove();
		     });

		return false;
	}else{
		if (searchkeyword==''){
			var Errholder = document.createElement('div');
			   $(Errholder).html('<div class="formError searchkeywordformError" style="top: 133.5px; left: 1036.5px; opacity: 0.87;"><div class="formErrorContent">* Ce champ est requis<br></div><div class="formErrorArrow"><div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div></div></div></div>');

			   $("body").append(Errholder);
			   $(Errholder).animate({"opacity":0.87},function(){return true;});	
			   $(Errholder).fadeTo('10000','0',function(){
				    $(this).remove();
			     });


			return false;
		}else{
			return true;
		}

	}

}
