var open=false;
var timer=null;
var current=$('.resto a').html();
var interv=null;
var nbpage=null;

function popTXT()
{
	$("#main").fadeIn();
	$("#layer").fadeIn();
	$("#hidecontent").html('masquer le contenu');
}

function hideTXT()
{
	$("#main").fadeOut();
	$("#layer").fadeOut();
	$("#hidecontent").html('afficher le contenu');
}

$(document).ready(function()
{
	
	$("#add_fav").click(function()
	{
		favoris();
		return false;
	});
	
	movelocator($("#menu .selected a"),0);
	
	$("#hidecontent").click(function()
	{
		if($("#main").css('display')=="block")
		{
			document.getElementById('bg_main').hideLayer();
		}
		else
		{			
			document.getElementById('bg_main').popLayer();
		}
	});
	
	$("#menu li a").click(function()
	{
		if($(this).html()!=current)
		{
		current=$(this).html();
		var link=$(this).attr('href');
		movelocator($(this));
		$("#main").fadeOut(function(){
			$("#main").load("page-"+link,{byajax:1},function(){$("#main").fadeIn(function(){checkpage(i,nbpage);})});
		});
		setTimeout("document.getElementById('bg_main').popLayer()",1000);
		}
		else
		{
			document.getElementById('bg_main').popLayer();
		}
		return false;
	});	
	
	$(".noredirect").click(function()
	{
		var link=$(this).attr('href');
		current=$(".resto a").html();
		document.getElementById('bg_main').hideAdresse();
		movelocator($(".resto a"));
		$("#main").fadeOut(function(){
			$("#main").load("page-"+link,{byajax:1},function(){$("#main").fadeIn()});
		});
		//document.location.href=document.location.href.replace('#'+param,'');
		return false;
	});	
	
	
	//Gallery
	$("#thumbnail li").each(function(){
		if($(this).attr('id')!='l_0')
			$(this).css({opacity:'0.7'})
		else
			open=$(this).attr('id');
		}
	);
	$("#thumbnail li a").click(function(){
		if(open!=$(this).parent('li').attr('id'))
		{
			if(open!=false)
				$('#'+open).animate({opacity:'0.7'});
			open=$(this).parent('li').attr('id');
			$('#'+open).animate({opacity:'1'});
			$("#pic_zone img").hide().attr({"src": $(this).attr("href"), "title": $("> img", this).attr("title")});
			$("#large h2").html($("> img", this).attr("title"));
			$("#pic_zone img").attr('alt',$(this).attr('title'));
			$("#toile_desc").html($(this).parent('li').children('div').html());
		}
		return false;
	
	});
	$("#pic_zone>img").load(function(){newheight=$("#pic_zone img").height(); $("#pic_zone").animate({height:newheight+"px"});       $("#pic_zone>img:hidden").fadeIn("slow")});
});


function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' ){
window.sidebar.addPanel("Eclat d'Art",url,"");
}
else {
window.external.AddFavorite(url,"Eclat d'Art");
}
}

function changeurl(newurl)
{
		old=param=jQuery.url.setUrl(document.location.href).attr("anchor");
		document.location.href=document.location.href.replace('#'+old,'')+newurl;
		return false;
}

function movelocator(obj,durr)
{
		if(durr==undefined)
			durr=500;
		$('#menu .selected').removeClass('selected');
		obj.parent('li').addClass('selected');
		var offset = obj.parent('li').offset();
		offneg=$("#menu").offset();
		pos=(offset.left+(obj.parent('li').width()/2))-offneg.left-($("#locator").width()/2) ;
		posvert=obj.parent('li').css('margin-top').replace('px','');
		if(posvert>0)
		{
			$("#locator").animate({marginTop:'-5px'},durr,function(){$("#locator").animate({marginLeft:pos+'px'},durr)});
		}
		else
		{
			$("#locator").animate({marginTop:'-10px'},durr,function(){$("#locator").animate({marginLeft:pos+'px'},durr)});
		}
}

function check_pop()
{
	if($("#main").css('display')=="none")
	{
		$("#main").fadeIn();
		$("#layer").fadeIn();
		$("#hidecontent").html('masquer le contenu');
	}
}


function diaporama(diapo_array)
{
	i++;
	if(i>(diapo_array.length-1))
		i=0;
	
	$("#zone_img img").hide().attr({"src": 'images/'+diapo_array[i], "alt": $("> img", this).attr("alt")});
	$("#zone_img>img").load(function(){$("#zone_img>img:hidden").fadeIn("slow")});
}

function checkpage(i,nbpage)
{
	if(i<=0)
	{
		$('#up img').fadeOut();
	}
	else
	{
		$('#up img').fadeIn();
	}
	
	if(i>=nbpage)
	{
		$('#down img').fadeOut();
	}
	else
	{
		$('#down img').fadeIn();
	}
}

function ajax_send()
{
	var zenom=$("#nom").attr("value");
	var zeprenom=$("#prenom").attr("value");
	var zeemail=$("#email").attr("value");
	var zemessage=$("#message").attr("value");
	$("#contact-form").fadeOut(function(){
		$("#result").load('submit_contact.php',{nom:zenom,prenom:zeprenom,email:zeemail,message:zemessage},function()
		{
			$("#result").fadeIn();
		});
	});
	return false;
}

