var vent = 0;
var oldInfo = null;
var objImage = new Image();
var isOeuvre = false;
//var breakClose = false;
//var opacity = 0;

function show_info(id) {
	if (oldInfo!=null) $("#"+oldInfo).hide(); //document.getElementById(oldInfo).style.display='none';
	$("#"+id).show();
	show_infos();
	oldInfo = id;
}

function close_infos() {
	$("#infos_fond").fadeOut();
}

function show_infos() {
	$("#infos_fond").fadeIn()
}

$(document).ready(function() {

	$("#infos > div").hide();
	$("#bienvenue").show();

	
	if (oldInfo != null) $("#"+oldInfo).show();
	$("#bienvenue").click(function() {
		$("#infos_fond").fadeOut("normal", function() {
			$("#bienvenue").remove();
		});
	});

	setTimeout("letShine()", 5000);
	setTimeout("vente()", 100);

});

function show_oeuvre(photo, ref, desc, artiste, collec) {


	$("body").append("<div id='photo_cache'></div>");
	$("body").append("<div id='oeuvre'><div id='oeuvre_close'></div></div>");
	$("#oeuvre").hide();
	$("#oeuvre").append("<img id='oeuvreimg' src='img/loading.gif' /><br/><br/>");
	$("#oeuvre").append("<p style='margin: 0 0 0 30px'></p>");
	$("#oeuvre p").append("<b>Auteur:</b> "+artiste);
	$("#oeuvre p").append("<br/><b>Collection:</b> "+collec);
	$("#oeuvre p").append("<br/><b>Référence:</b> "+ref);
	$("#oeuvre p").append("<br/><b>Description:</b> "+desc);
	$("#oeuvre").fadeIn();
	centerOeuvre();

/*	$("#photo_cache").click(function() {
		$(this).fadeOut("normal", function(){$(this).remove()});
		$("#oeuvre").remove();
	
	});*/

	$("#oeuvre").click(function() {
		isOeuvre = false;
		$("#photo_cache").remove();
		$("#oeuvre").remove();
	});

	$("#oeuvre_close").hover(
		function () {
			$(this).css("background", "transparent url('img/photo_close_hover.gif') no-repeat center center");
		}, 
		function () {
			$(this).css("background", "transparent url('img/photo_close.gif') no-repeat center center");
		}
	);

	isOeuvre = true;

	objImage = new Image();
	objImage.onLoad=setTimeout("imageLoaded()", 500);
	objImage.src = 'media/oeuvre/'+photo;

}

function imageLoaded(){

	$("#oeuvre").hide();
	$("#oeuvreimg").attr("src", objImage.src);
	setTimeout("centerOeuvre();", 10);
}

function centerOeuvre(){


	var dimensions = {width: 0, height: 0};

	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    dimensions.width = window.innerWidth;
	    dimensions.height = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    dimensions.width = document.documentElement.clientWidth;
	    dimensions.height = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    dimensions.width = document.body.clientWidth;
	    dimensions.height = document.body.clientHeight;
	  }



	dimensions.width /= 2;
	dimensions.height /= 2;
	dimensions.width -= $("#oeuvre").outerWidth()/2;
	dimensions.height -= $("#oeuvre").outerHeight()/2;
	
	if (dimensions.width < 0) dimensions.width = 0
	if (dimensions.height < 0) dimensions.height = 0
	
	$("#oeuvre").css("left", dimensions.width);
	$("#oeuvre").css("top", dimensions.height);
	$("#oeuvre").show();
	
	if (isOeuvre) setTimeout("centerOeuvre()", 200);
}


function shine(lien){

	$("#lien_"+lien).hide();
	$("#lien_"+lien).css("background-image", "url(img/lien_"+lien+".jpg)");
	

	$("#lien_"+lien).fadeIn(200, function(){
		$(this).fadeOut(200, function(){
			$("#lien_"+lien).css("background-image", "");
			$("#lien_"+lien).show();
						
		});
	} );

	
/*	$("#lien_contact").animate( { backgroundColor: "#F00"}, 1000, "linear", function(){
		$(this).animate( { backgroundColor: "transparent"}, 1000);
	} );*/
}

function letShine(){


	setTimeout("shine('contact')", 10);
/*	setTimeout("shine('galerie')", 200);
	setTimeout("shine('artistes')", 300);
	setTimeout("shine('boutique')", 400);
	setTimeout("shine('cotedeco')", 500);
	setTimeout("shine('oeuvres')", 500);
	setTimeout("shine('expos')", 550);
	setTimeout("shine('news')", 650);
	setTimeout("shine('cotemode')", 700);
	setTimeout("shine('cotejardin')", 700);
	*/
	setTimeout("letShine()", 10000);
}

function vente(){
	$("#vent").css("background-position", vent+"px 0px");
	vent+=8;
	vent = vent%790;
	setTimeout("vente()", 100);
}








