

$(document).ready(function(){
$('#menu_centre').css('width',getWindowWidth()-248);

//~ menu_gauche1.

//~ $("#imgcargement").fadeOut(1);

//~ $(window).resize(function(){metombre();})


$('#identite,#identite2').click(function(){
	if ($("#tab_identite").is(":hidden")) {
	$('#tab_identite2').show();
	$('#tab_identite').slideDown("slow");
	}
	else{
	$('#tab_identite').slideUp("slow");
	$('#tab_identite2').hide();
	}
});

$('#contact').click(function(){
	if ($("#tab_identite").is(":hidden")) {
	}
	else{
	$('#tab_identite').slideUp("slow");
	$('#tab_identite2').hide();
	}
});


$("[id^=creecompte]").click(function(){
	$('#tab_identite').slideUp("slow");
	$('#tab_identite2').hide();
	location.href='index.php?lang='+$('#lang').val()+'&page=identification';
});

$('#demandelogin1').click(function(){
	if ($("#entremail").is(":hidden")) {
	$('#entrelogin').css('display','none');
	$('#entremail').css('display','');
	}
$("#alert_mail1").css('display','none');
$("#alert_mail2").css('display','none');
});


$('#demandelogin2').click(function(){
	if ($("#entrelogin").is(":hidden")) {
	$('#entrelogin').css('display','');
	$('#entremail').css('display','none');
	}
$("#alert_mail1").css('display','none');
$("#alert_mail2").css('display','none');
});

//~ $('a.supprimer').click(function() {
//~ alert($(this).attr("id"));
//~ })
	
$("#gray_secu").treeview({
	control: $("#treecontrol_secu"),
	animated: "fast",
	persist: "cookie",
	cookieId: "treeview-black"
});


/* essais pour combiner treview span avec lien */

$('[id^=affichefolio_]').click(function(){
var id = $(this).attr("id").substring(13); // on recupere l'id de l'element

//~ var branches=$("gray_19").find(">ul");
//~ alert(branches.li);
	//~ branches.each(function(){
	
	//~ }


//~ setTimeout("Timer()",1000);
//~ window.location.href=$('#submitfolio'+id).attr("href")+'&lang='+$('#lang').val();
window.location.href=$('#submitfolio'+id).attr("href");
return false;
});




/* validez mail*/
$('#validezmail').click(function(){
foundError = false;
if (validateMail2($('#perduEmail').val())==false) {
alert($(this).attr("rel"));
this.focus();
foundError = true;
}
if( foundError==false ){
$.post("ajaxfront.php",
{
fonction: "pertepsw",
lang:$('#lang').val(),
Email:$('#perduEmail').val()
} ,
function(data){
if(data>1){ 
$("#alert_mail1").css('display','');
$("#alert_mail2").css('display','none');
}
else{
$("#alert_mail1").css('display','none');
$("#alert_mail2").css('display','');
}
})
}
});
 
//validez login
$('#validezlogin').click(function(){
foundError = false;
if (validateMail2($('#login').val())==false) {
alert($(this).attr("rel"));
this.focus();
foundError = true;
}
if( foundError==false ){
$.post("ajaxfront.php",
{
fonction: "veriflogin",
lang:$('#lang').val(),
login:$('#login').val(),
psw:$('#psw').val()
} ,
function(data){
if(data>0){ 
$("#alert_mail1").css('display','none');
$("#alert_mail2").css('display','none');
$('#tab_identite').slideUp("slow");
$('#tab_identite2').hide();
//~ $(document).load();
//~ location.href='index.php?lang='+$('#lang').val();
location.reload(); 
}
else{
$("#alert_mail1").css('display','');
$("#alert_mail2").css('display','none');
}
})
}
});


//select menu gauche
$("[name=theme]").change(function(){
//~ alert(this.value);
location.href='index.php?fn=folio&'+this.name+'='+this.value+'&lang='+$('#lang').val();
});
//select menu gauche
$("[name=photographe]").change(function(){
//~ alert(this.value);
//~ location.href='index.php?fn=gphoto&'+this.name+'='+this.value+'&lang='+$('#lang').val();;
location.href='index.php?fn=folio&'+this.name+'='+this.value+'&lang='+$('#lang').val();;
});


//select folios + cookies
$("[name=formpagevignette]").change(function(){
//~ alert('ok');
if($("#searchword").length>0){
location.href='index.php?fn=folio&searchword='+$("#searchword").val()+'&lang='+$("#lang").val()+"&numpage="+this.value+"&pre="+$("#pre").val()
}
else if($("#lephotographe").length>0){
location.href='index.php?fn=folio&photographe='+$("#photographe").val()+'&lang='+$("#lang").val()+"&numpage="+this.value+"&pre="+$("#pre").val()
}
else{
var option='';
if($("#theme").length>0 && $("#theme").val()!=0 ){option="&theme="+$("#theme").val();}
var pour_request='';
if($("#co").val().length>0 ){pour_request="&co="+$("#co").val();}
if($("#lo").val().length>0 ){pour_request="&lo="+$("#lo").val();}

//~ if($("#photographe").length>0 && $("#photographe").val()!=0 ){option="&photographe="+$("#photographe").val();}
location.href='index.php?fn=folio&'+pour_request+'&FolioID='+$("#FolioID").val()+'&lang='+$("#lang").val()+"&numpage="+this.value+"&pre="+$("#pre").val()+option
}
});

$("[name^=nb_page]").change(function(){
$.cookie('nb_page', this.value,{ expires:30});
if($("#searchword").length>0){
location.href='index.php?fn=folio&searchword='+$("#searchword").val()+'&lang='+$("#lang").val()+"&nb_page="+this.value+"&pre="+$("#pre").val()
}
else if($("#lephotographe").length>0){
location.href='index.php?fn=folio&photographe='+$("#lephotographe").val()+'&lang='+$("#lang").val()+"&nb_page="+this.value+"&pre="+$("#pre").val()
}
else{
var option='';
if($("#theme").length>0 && $("#theme").val()!=0 ){option="&theme="+$("#theme").val();}
var pour_request='';
if($("#co").val()){pour_request="&co="+$("#co").val();}
if($("#lo").val() ){pour_request="&lo="+$("#lo").val();}
//~ if($("#photographe").length>0 && $("#photographe").val()!=0 ){option="&photographe="+$("#photographe").val();}
location.href='index.php?fn=folio&'+pour_request+'&FolioID='+$("#FolioID").val()+'&lang='+$("#lang").val()+"&nb_page="+this.value+"&pre="+$("#pre").val()+option
}
});

$("[name^=nb_pagelight]").change(function(){
$.cookie('nb_pagelight', this.value,{ expires:30});
if($("#IDlightbox").length>0){
location.href='index.php?page=pagelight&lang='+$("#lang").val()+'&IDlightbox='+$("#IDlightbox").val()+'&nb_pagelight='+this.value
}else{
location.href='index.php?page=pagelight&lang='+$("#lang").val()+"&nb_pagelight="+this.value
}
});



/*permet de mettre le bas de page pour les style avec bord comme halo...*/
if($("div#idsans_centre").is(":hidden")){
var newtab=getWindowHeight()-parseInt($('#footer').css('height').replace('px',''))-parseInt($('#tab_menu_horizontal').css('height').replace('px',''))-parseInt($('#affichelogo').css('height').replace('px',''));
$('#menu_gauche').css('height',newtab);
$('#menu_centre').css('height',newtab);
};


$("[id^=video_news_]").click(function(){
	var id = $(this).attr("id").substring(11); // on recupere l'id de l'element
	$.post("ajaxfront.php",
	{
	fonction:'affichevideo',
	NewsID: id
	} ,function(data){
	$("#newsvideo").html(data);
	$("#newsvideo").css('display','');
	})
});


/* page liste +info*/ 
$("[id^=plus_info_]").click(function(){
lid=this.id.substring(10);
if ($('#autreinfo_'+lid).is(":hidden")) {
$('#autreinfo2_'+lid).show();
$('#autreinfo_'+lid).slideDown("slow");
}
else{
$('#autreinfo_'+lid).slideUp("slow");
$('#autreinfo2_'+lid).hide();
}
});
/*fin de page liste +info*/ 

/* page liste +folios*/ 
//~ $("[id^=plus_folio_]").click(function(){
//~ lid=this.id.substring(11);
//~ if ($('#info_folio_'+lid).is(":hidden")) {
//~ $('#sep_info_folio').css('display','none');
//~ $('#info_folio_'+lid).css('display','');
//~ $('#info_folio_'+lid).slideDown(1000);
//~ }
//~ else{
//~ $('#info_folio_'+lid).slideUp("slow");
//~ $('#sep_info_folio').show();
//~ }
//~ });

$("#plus_folio_").click(function(){
	$('#tabsuite').css('display','none');
	$('#cutstring').css('display','none');
	$("#suite").fadeIn(500);
	$("#suite").animate({ left: 50, opacity:1 }, 500);
	$('#tabfermer').show();
});


$("#fermer_folio_").click(function(){
	$("#suite").fadeOut(500);
	$('#tabfermer').css('display','none');
	$('#tabsuite').show();
	$('#cutstring').show();
});



/* pour caroussel*/
$(function() {
    $(".anyClass").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 6,
		speed: 1000,
		scroll: 6,
		//~ auto: 800,
		mouseWheel: true
    });
});
$("[id^=imgdiapo_]").click(function() {
id=this.id.substring(9);
Chargement(id);
});
/*fin de pour caroussel*/



$("#panier").click(function(){
location.href='index.php?page=pagepanier&lang='+$('#lang').val();
});

// fonction ligthbox sans customer

$("[id^=lightbox_sc]").click(function(){
idimg=this.id.substring(11);
$.post("ajaxfront.php",
{
fonction: "addlightbox",
img:idimg
} ,
function(data){$("#inlightbox").html(data)});

//quand on est dessus l'image est a on donc on transforme on en on1
var chaine=$("#lightbox_sc"+idimg).attr('src');
var reg=new RegExp("(_on.png)", "g");
chaine=chaine.replace(reg,"_on1.png");
$("#lightbox_sc"+idimg).attr("src",chaine);
$("#lightbox_sc"+idimg).css({cursor:"default"});
});





//~ $("img[src*=lightbox_off.png]").mouseover(function(){ img_to_on(this);})//mettre off pour generalise
//~ $("img[src*=lightbox_off.png]").mouseout(function(){ img_to_off(this);})//mettre off pour generalise

$("[id^=lightbox_sc]").mouseover(function(){ img_to_on(this);})//mettre off pour generalise
$("[id^=lightbox_sc]").mouseout(function(){ img_to_off(this);})//mettre off pour generalise


//~ $("[img[src*=_off.png]").mouseover(function(){ img_to_on(this.src);})//mettre off pour generalise
//~ $("[img[src*=_off.png]").mouseout(function(){ img_to_off(this.src);})//mettre off pour generalise
//fin de fonction ligthbox sans customer

$("#info_img").click(function(){
idimg=$(this).attr("rel");
$.post("ajaxfront.php",
{
fonction: "menu_info_img",
lang:$('#lang').val(),
lo:$('#lo').val(),
img:idimg
} ,
function(data){
$("#menu_gauche1").fadeOut("slow");
$("#menu_gauche1").css({display:"none"});
$("#menu_gauche2").fadeIn("slow");
$("#menu_gauche2").html(data);
});
})

//~ 
if ($("div#infoimgdroite").is(":hidden")){
$("#menu_gauche1").hide();
$("#menu_gauche0").hide();
}else{
$("#menu_gauche1").fadeIn(1);
$("#menu_gauche0").hide();
	//~ preload_image();
	//~ metombre();
}
//~ })
//~ }
//~ $(window).bind('resize', function() {
	//~ preload_image();
	//~ metombre();
	//~ })


$(window).resize(function(){
metombre();				
});

$(window).load(function(){
//~ alert(getWindowWidth());
preload_image();
metombre();
//~ alert($('#menu_centre').width());

})
/*fin du jquery*/
$("#souvenir1").click(function(){
if ($('input[type=checkbox][id=souvenir1]:checked').length ==1){
sauvecookie_menu_folio('logincook',$('#login').val());
sauvecookie_menu_folio('pswcook',$('#psw').val());
sauvecookie_menu_folio('remembercook',1);
}else{
sauvecookie_menu_folio('logincook',null);
sauvecookie_menu_folio('pswcook',null);
sauvecookie_menu_folio('remembercook',0);

}
//~ alert($("#login").val()+' '+$('input[type=checkbox][id=souvenir1]:checked').length);

})


//~ $("#souvenir1").toggle(function(){ alert('ok'); },function(){ alert('pas vok'); });

})



/*
function affichefolio(lid){
setTimeout("Timer()",1000);
//~ this.addClass("treeview");
// prepare branches and find all tree items with child lists
location.href=$('#submitfolio'+lid).attr("href");
//~ alert($('#submitfolio'+lid).attr("href"));
//~ loadIfModified($('#submitfolio'+lid).attr("href"));
return false;
}
*/
function ouvrir_texte_folio(lid){
$('#tabsuite').css('display','none');
$('#suite').hide();
$.post("ajaxfront.php",
{
fonction: "addsuite",
cutString:$('#suite').html(),
lenght:$('#suite').attr("rel"),
idfolio:lid
} ,
function(data){$("#suite").html(data);
$("#suite").animate({ left: 50, opacity: 'show' }, 500);}
);
$('#tabfermer').show();

}

function sauvecookie_menu_folio(key,value){
// pour fermer les autres collections qui seraient ouvertent
//~ var reg=new RegExp("[,]+", "g");
//~ var  tableau=lescollections.split(reg);
	//~ for (var i=0; i<tableau.length; i++) {
	//~ $('#a1_'+tableau[i]+'').click();
	//~ }
$.cookie(key,value, { expires:30});
}

			

function suprime_info_img(){
$("#menu_gauche2").html('');
$("#menu_gauche2").fadeOut("slow");
$("#menu_gauche1").fadeIn("slow");
$.post("ajaxfront.php",
{
fonction: "menu_info_img0"
});
}

function retourne_img_panier(){
	$("[@id^=caddie_]").each(function(){
		lid=this.id.substring(7);
		alert(lid);
	})

}


function img_to_on(e){
var chaine=$(e).attr("src");
var reg=new RegExp("(_off.png)", "g");
chaine=chaine.replace(reg,"_on.png")
$(e).attr("src",chaine);
}

function img_to_off(e){
var chaine=$(e).attr("src");
var reg=new RegExp("(_on.png)", "g");
chaine=chaine.replace(reg,"_off.png")
$(e).attr("src",chaine);
}




function tb_remove(){
	location.reload(); 
	//~ $.post("ajaxfront.php",{fonction: "qttdanspanier",} ,function(data){$("#inpanier").html(data);})
	//~ location.reload(); 

 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";

	//~ $.post("ajaxfront.php",{fonction: "metdanscookie"});

	//~ retourne_img_panier();

	//~ $.post("ajaxfront.php",
	//~ {
	//~ fonction: "metdanscookie",
	//~ } ,
	//~ function(data){
	//~ $("#inpanier").html(data);
	//~ })

	return false;
}


/*pour caroussel*/
function Chargement(id){
//~ alert(id);
	$.post("ajaxfront.php",
		{
		fonction: "afficheimg",
		id:id
		} ,
		function(data){
		//~ alert(data)
		$(".midimg").fadeTo("fast", 1); 
		$(".midimg").html(data);
		});
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function preload_image(){
MM_preloadImages('taiga/noir/fd_on.png');
MM_preloadImages('taiga/noir/fg_on.png');

}

function alerte(e)	{
		$(e).animate({
			fontSize:"1.2em"
			}, 500,	function(){
			$(e).animate({
			fontSize:"1em"
			}, 500);
		});
		$(e).addClass("erreur");		  
	}
	
function noalerte(e){
$(e).addClass("form");
}


function validateMail2(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   //~ var address = document.forms[form_id].elements[email].value;
   if(reg.test(email) == false) {
      return false;
   }else{return true;}
}
 
//~ $(function() {
//~ $("#menu_horizontal").lavaLamp({
//~ fx: "backout", 
//~ speed: 700,
//~ click: function(event, menuItem) {
//~ return false;
//~ }
//~ });
//~ });

//Fonction
function metombre(){
pos = $('#table1').findPos();
//~ alert(pos.x+950);
//~ alert($('#table1').height());
$('#col_ombregauche1').css('left',pos.x-13);
$('#col_ombregauche1').css('height',$('#table1').height());
$('#col_ombredroite1').css('left',pos.x+950);
$('#col_ombredroite1').css('height',$('#table1').height());
}

function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}

function getWindowWidth() {
    var windowHeight=0;
    if (typeof(window.innerWidth)=='number') {
        windowWidth=window.innerWidth;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientWidth) {
         windowWidth = document.documentElement.clientWidth;
    }
    else {
     if (document.body&&document.body.clientWidth) {
         windowWidth=document.body.clientWidth;
      }
     }
    }
    return windowWidth;
}

jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

function findPos(obj) {
        var curleft = obj.offsetLeft || 0;
        var curtop = obj.offsetTop || 0;
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
        return {x:curleft,y:curtop};
}

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 4;
if (document.body.offsetHeight >= getWindowHeight()) { barredef = "yes"; }
else {barredef = "auto";}
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+barredef+',resizable=yes';
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


/***caroussel*/




