$(document).ready(function(){
	/* Recuperation SiteUrl */
	var siteurl = $("#hiddenSiteUrl").attr("value");
	
	
	
	/* Variables globales */
	var historique = "";
	var title_click = "undefined";

	
	/* Definition du background aleatoire */	
	var bgnbr = $("#hiddenRand").attr("value");
	var resolution = $("#hiddenResolution").attr("value");
	if(resolution == "0"){
		var width = screen.width;
		if(width >= 1920)
			resolution = "1920";
		else if(width >= 1680)
			resolution = "1680";
		else if(width >= 1360)
			resolution = "1360";
		else if(width >= 1280)
			resolution = "1280";
		else if(width >= 1024)
			resolution = "1024";
		else 
			resolution = "800";
	}
	$("#hiddenResolution").attr("value",resolution);
	var bg = siteurl+"/wp-content/themes/prestatech/img/bg/"+resolution+"/"+bgnbr+".jpg";
	$("body").css("background","url("+bg+")  no-repeat black");
	
	
	/* FullScreen */
	$("#fullscreen").click(function(){
		window.open('http://www.prestatech-artifices.com', 'Prestatech Artifices' , 'type=fullWindow, fullscreen, scrollbars=yes');
	});
	
	
	/* Clique sur le menu */
	$("#menu_right li").click(function(){
		$("#menu_right li").each(function(){
			if($(this).hasClass("menu_selected")){
				$(this).removeClass("menu_selected");
			}
		});
		$(this).addClass("menu_selected");
	});
	
	
	
	/* Hover du menu */
	$("#menu_right li").hover(function(){
		if($(this).hasClass("menu_selected")){}
		else{
			var imgurl = siteurl+"/wp-content/themes/prestatech/img/fleche-menu.png";
			$(this).css("background","url("+imgurl+") no-repeat");
			$("a", this).css("color","white");
		}
	}, function(){
		if($(this).hasClass("menu_selected")){}
		else{
			$(this).css("background-image","none");
			$("a",this).css("color","black");
		}
	});
	
	
	
	/* jScrollPane */
	$("#post_container").jScrollPane({scrollbarOnLeft:true, dragMaxHeight:60, reinitialiseOnImageLoad:true});



	
	/* Vignettes dans les news */
	var i = 0;
	$(".post_left").each(function(){
		i++;
		$(this).addClass("lpost"+i);
	});
	var i = 0;
	$(".post_right img").each(function(){
		var img = $(this);
		var width = $(this).attr("width");
		var height = $(this).attr("height");
		
		if(width == "60" && height == "60"){
			i++;
			$(".lpost"+i).html($(this).clone());
			$(this).css("display","none");
		}
	});	
	
	

	/* Gestion custom des galleries */
	$(".gallery").click(function(){
		var gid = $(this).attr("id");
		$("#post_container").html("<br /><br /><center><img src='wp-content/themes/prestatech/img/ajax-loader.gif' alt='Loading...' title='Loading...' />");
		$('#post_container').jScrollPaneRemove();
		$.post("wp-content/themes/prestatech/ajax_gallery.php", {"action":"gallery", "gid":gid}, 
			function(data){
				$("#post_container").html(data);
				document.title = $(".gallery_title:first").html()+" | "+document.title;
				Shadowbox.init();
			}
		);	
	});




});

