$(document).ready(function(){
	$(".page_item").hover(function () {
	    $(this).find(".children:eq(0)").css("display","block");},
						  function () {
	    $(this).find(".children:eq(0)").css("display","none");
	  }
	);
	$( "#dialog" ).dialog({ modal: true,
							width:300,
							height:120,
							resizable: false 
						  });
 	$( "#dialog_big" ).dialog({ modal: true,
							width:380,
							resizable: false 
						  });
						  
	$( "#product_lightbox" ).dialog({ autoOpen: false,
							modal: true,
							width: 840,
							height: 580,
							resizable: false 
						  });
	$( "#gallery_lightbox" ).dialog({ autoOpen: false,
							modal: true,
							width:620,
							height:600,
							resizable: false 
						  });
 	$("a.ui-dialog-titlebar-close, .ui-widget-overlay").live('click', function(){
 		$("#product_lightbox,#dialog_big,#dialog,#gallery_lightbox" ).dialog("close");
	 });
 	
 	$(".close-icon").click(function(){ $("#message_box").css("display","none") });
	 
  	
	  
	$(".gallery_tamplate").click(function(){
		$( "#gallery_lightbox" ).dialog("open");
	}) ; 					
	/*
	$('#slider2').nivoSlider({effect:'fade',
							 slices:10,
							 controlNav:false,
							 directionNav:false,
							 pauseOnHover:false,
							 pauseTime:10000});	3
 	*/
							 
 	$('#slider1').bxSlider({pager: true, auto: true, pause: 6000});
	
	//Remove the link from Le domain & ses secrets
	$(".page-item-23>a").attr("href", "javascript:void(0)");
	
	//Remove the link from Les environs 
	$(".page-item-209>a").attr("href", "javascript:void(0)");
	
	//Change the title for Equipe
	$(".page-item-150 a").html("L'équipe")
	
	//Style Actualite sidebar newsletter
	$(".widget_newsletter").addClass("newsletterBox");
	$(".widget_newsletter").find('form').attr("action", "");
	$(".widget_newsletter").find('input[type="submit"]').attr("value", "OK");
	
	
	
	//Make sure Actualite excerpt image is not bigger than 150px height
	var h=$(".actuBox img").height();
	if(h>150) h=150;
	
	
	//Image preloader
	(function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
	    var args_len = arguments.length;
	    for (var i = args_len; i--;) {
	      var cacheImage = document.createElement('img');
	      cacheImage.src = arguments[i];
	      cache.push(cacheImage);
	    }
	  }
	})(jQuery)
	
	var i=0;
	$(".ngg-gallery-thumbnail-box, .ngg-gallery-thumbnail-box2").each(function(){
		i++;
		var img=$(this).find("img").attr("src");
		img=img.replace("thumbs/thumbs_", "");	
		jQuery.preLoadImages("image"+i+".jpg", img);
	});
	
	
	//Image slider for galleries
	$(".ngg-gallery-thumbnail a").live("click", function(){
		$(".ngg-gallery-thumbnail-box").removeClass("active");
		$(this).parent().parent().addClass("active");
		var img=$(this).find("img").attr("src");
		var caption=$(this).parent().find("span").html();
		//if(caption=="&nbsp;") caption=null;
		img=img.replace("thumbs/thumbs_", "");
		$(".pic img").fadeTo("fast", 0.33, function(){
				$(".pic img").attr("src", img).delay(200); 
				$(".pic img").fadeTo("fast", 1, function(){
					if ($(".pic img").height()>420) $(".pic img").height(420);
				});
				
				if(caption){
					$(".gallery_caption").css("display", "none");
					$(".gallery_caption").html("<p>"+caption+"</p>").delay(500).slideDown("slow");
				}
				else $(".gallery_caption").html("");
				
				
		});
		
		return false;
	});
	if($(".gallery_caption>p").html()=="&nbsp; ") $(".gallery_caption>p").css("display", "none");
	
	
	var p = $(".newsletterFooter").position();
	p.top+=20;
	$(".to_footer").css("top", p.top);
	
});

function escramble(){
 var a,b,c,d,e,f,g,h,i
 a='<a href=\"mai'
 b='contact'
 c='\">'
 a+='lto:'
 b+='@'
 e='</a>'
 f=''
 b+='chateau-saint-esteve.com'
 g='<img src=\"'
 h=''
 i='\" alt="Email" border="0">'

 if (f) d=f
 else if (h) d=g+h+i
 else d=b

 document.write(a+b+c+d+e)
}

function escramble2(){
 var a,b,c,d,e,f,g,h,i
 a='<a href=\"mai'
 b='shop'
 c='\">'
 a+='lto:'
 b+='@'
 e='</a>'
 f=''
 b+='chateau-saint-esteve.com'
 g='<img src=\"'
 h=''
 i='\" alt="Email" border="0">'

 if (f) d=f
 else if (h) d=g+h+i
 else d=b
 document.getElementById("escramble2").innerHTML=a+b+c+d+e;
 document.getElementById("escramble3").innerHTML=a+b+c+d+e;
}
