$(document).ready(function(){

	$('#newsletter-form').validate({
		rules: 
		{ 
			emailnewsletter:{ email:true }
		},
		errorPlacement: function(error, element){
			error.appendTo(".div-error");
		},
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					success: function(response) 
                        { 
                            if(response == 'true'){
                                $('#newsletter-form').css('display', 'none');
                                $('#newsletter-success-message').css('display', 'block');		
                            }else{
								if(response.indexOf('Duplicate') != -1)
                                	alert(form_error);
								else
									alert(response);
                            }
                        } 
				});
			}
		});


	
	var button_bg_url = 'url('+template_url+'/images/nav_button_bg.gif)';
	var subbutton_bg_url = 'url('+template_url+'/images/nav_subbutton_bg.gif)';

	$(".menu .current-menu-item .sub-menu").css("display", "block");

	$(".menu > li").mouseover(function()
	{
		clearTimeout(menutimer);
		$(".menu > li > a").css('background-image', 'none');
		$(".menu .sub-menu").css("display", "none");
		$(this).find("ul").css("display", "block");
		$(".menu > .current-menu-item > a").css("background-image", "none");
		$(".menu > .current-menu-parent > a").css("background-image", "none");
		$(this).find("a:first").css('background-image', button_bg_url);
		
	});
	
	var menutimer;
	var activeItem;
	
	$(".menu > li").mouseout(function()
	{
		activeItem = this;
		menutimer = setTimeout(function(){closemenu();}, 1000);

	});
	
	function closemenu(){
		
		$(activeItem).find("ul").css("display", "none");
		$(".menu .current-menu-item .sub-menu").css("display", "block");
		$(".menu .current-menu-parent .sub-menu").css("display", "block");
		if($(activeItem).hasClass("current-menu-parent") || $(activeItem).hasClass("current-menu-item")){
			$(".menu .sub-menu .current-menu-item").css("background-image", subbutton_bg_url);
			return;
		}
		$(activeItem).find("a:first").css('background-image', "none");		
		$(".menu > .current-menu-item > a").css("background-image", button_bg_url);
		$(".menu > .current-menu-parent > a").css("background-image", button_bg_url);		
	}
	
	var titleHeight = $('.entry-subtitle').height();
	var title = $('.entry-title');
	
	if(titleHeight > 50 && title.length > 0 ){
		$('.entry-subtitle.single').css('top', '20px');
	}
	if(titleHeight > 55){
		$('.entry-subtitle').css('font-size', '20px');
	}
	

	
	var content_height = $('#container').height();
	var sidebar_height = 680;		
	var primary_height = $('#primary').height()+89;
	var facebook_height = $('#side-bar-facebook').height();
	
	if(primary_height < sidebar_height){
		$('#side-bar-facebook').height(facebook_height+(sidebar_height-primary_height));
	}
	
	if(content_height > sidebar_height){
		var newheight = (content_height-sidebar_height)+facebook_height;
		$('#side-bar-facebook').height(newheight);
	}
	
	if(post_type == 'post'){
		var menu_id = (icl_lang == 'fr') ? 'menu-item-67' : 'menu-item-335';
		$('#'+menu_id).addClass('current-menu-item');	
	}
	
	try{
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}catch(err){
		
	}
	
	$(".video-realisation-block span.overlay").mouseenter(function(){
		
			$(this).css('background-image', 'url('+template_url+'/images/blank.gif)');
		
		});
	$(".video-realisation-block span.overlay").mouseleave(function(){

		$(this).css('background-image', 'url('+template_url+'/images/video_alpha_overlay.png)');
	
	});
	
	var textEmail = $('#input-email-newsletter').val();
	
	$('#input-email-newsletter').focusin(function(){
		if($(this).val() == textEmail)
		{
			$(this).val('');
			$(this).removeClass('griser');
		}
	});
	
	$('#input-email-newsletter').focusout(function(){
		if($(this).val() == '')
		{
			$(this).val(textEmail);
			$(this).addClass('griser');
		}
	});
	
});



	
	
function submitForm(){
	$('#newsletter-form').submit();
}	

