﻿// JavaScript Document

function debut_chargement(){
//	$("#loader_page").fadeIn();
}

function fin_chargement(){
//	$("#loader_page").fadeOut();
}

$(document).ready(function(){
													 
	$('#diapo_bandeau').cycle({
			fx:     'fade',
			prev:   '#prev',
			next:   '#next',
			timeout:  7000,
			random:  1,
			pause:  1
	});
	$('#bandeau').live("mouseleave", function(e){
		$('#diapo_bandeau').trigger(e);
		if ($.browser.msie || $.browser.msie6) {
			$('.nav div span').stop(true, true).clearQueue().css("display","none");
		} else { 
			$('.nav div span').stop(true, true).clearQueue().fadeOut(300,'swing');
		}
	}).live("mouseenter", function(e){
		$('#diapo_bandeau').trigger(e);
		if ($.browser.msie || $.browser.msie6) {
			$('.nav div span').stop(true, true).clearQueue().css("display","block");
		} else {
			$('.nav div span').stop(true, true).clearQueue().fadeIn(300,'swing');
		}
	});

	$('.nav div span').css("display","none")
										.live("mouseenter", function(e){ $(this).css("cursor","hand");})
										.live("mouseleave", function(e){ $(this).css("cursor","");});

	$("#menu a").live("mouseenter", function(e){
		e.stopImmediatePropagation();
		var off=$(this).children("img").attr("src");
		var on=$(this).children("img").attr("on_src");
		if (off!=on) $(this).children("img").attr("src",on).attr("off_src",off);
		
		var id=$(this).attr("id");
		$("#sousmenu label[id="+id+"]:not([flag])")
					.css("left",($(this).position().left-15)+"px")
					.css("width",$(this).width()+"px")
					.attr("flag","1");
		$("#sousmenu label").each(function(){
			if ($(this).attr("id")==id) {
				if ($.browser.msie || $.browser.msie6) {
					$(this).stop(true, true).clearQueue().css("display","block");
				} else { 
					$(this).stop(true, true).clearQueue().fadeIn();
				}
			} else {
				if ($.browser.msie || $.browser.msie6) {
					$(this).stop(true, true).clearQueue().css("display","none");
				} else { 
					$(this).stop(true, true).clearQueue().fadeOut(300,'swing');
				}
			}
		});
	});

	$("#menu a img").live("mouseleave", function(e) {
		$(this).attr("src",$(this).attr("off_src"));
	});
	
	$("#sousmenu label").live("mouseleave", function(e){
		e.stopImmediatePropagation();
		if ($.browser.msie || $.browser.msie6) {
			$(this).stop(true, true).clearQueue().css("display","none");
		} else { 
			$(this).stop(true, true).clearQueue().fadeOut(300,'swing');
		}
	});

	$("#langues a").live("mouseenter",function(){
			$("#langues label").stop(true, true).clearQueue().html($(this).attr("title")).fadeIn("fast");
	}).live("mouseleave",function(){
			$("#langues label").stop(true, true).clearQueue().fadeOut("fast");
	});
	
	$("td:has(a.offre)").live("mouseenter", function(){
			$("td#"+$(this).attr("id")).addClass("on");
	}).live("mouseleave", function(){
			$("td#"+$(this).attr("id")).removeClass("on");
	});

	$("div.encart_gris:has(a)").live("mouseenter", function(){
			$(this).addClass("on");
	}).live("mouseleave", function(){
			$(this).removeClass("on");
	});
	
	$("a#suppr_actu").live("click", function(e){
		var tr=$(this).parents("tr");
		var td=$(this).parents("td");
		charger_page(path+"_suppression_actu.php",
								 null,
								 {id_actu:$(this).attr("id_actu")},
								 function(retour, statut, requete){
										if (retour=="ok"){
											tr.remove();
										} else {
											td.html(retour);
										}
									});
		return false;
	})
	
	$("a#suppr_ref").live("click", function(e){
		var tr=$(this).parents("tr");
		var td=$(this).parents("td");
		charger_page(path+"_suppression_ref.php",
								 null,
								 {id_ref:$(this).attr("id_ref")},
								 function(retour, statut, requete){
										if (retour=="ok"){
											tr.remove();
										} else {
											td.html(retour);
										}
									});
		return false;
	})
	
	$("a#modif_img").live("click", function(e){
		$(this).parents("td").children("span").trigger("dblclick");
		return false;
	})
	
	$("table.notre_offre tr#deplier").live("mouseenter mouseleave", function(e){
			$(this).children("td").stop(true, true).toggleClass("on");
	}).live("click", function(e){
			e.stopImmediatePropagation();
			$("label#"+$(this).attr("id_label")).stop(true, true).slideToggle('fast');
			$(this).children("td").stop(true, true).toggleClass("on2");
			return false;
	});
	
	rendre_editable();

	log_js("<span class='vert'>Chargement du script 'www.js' OK</span>");
});

function rendre_editable(){
	$(".editable[type_objet!=image]").editable(path+'ACTION_objet_edition.php', { 
      type      : "textarea",
			select		: false,
      loadurl   : path+"_objet_edition.php",
			loadtype	: 'GET',
			loaddata	: function(){
										return {id_objet:$(this).attr('id_objet'), 
										type_objet:$(this).attr('type_objet'),
										master_js:1 };
									},
			loadtext	: "Edition en cours ...",
			name			: function(){return $(this).attr('id_contenu');},
			id				: "id_page",
			width			: "auto",
			height		: "none",
			submitdata : function(){
										return {id_objet:$(this).attr('id_objet'), 
										type_objet:$(this).attr('type_objet'), 
										master_js:1 };
									},
			submit    : "",
      cancel    : "",
      tooltip   : "Double-click pour modifier le texte.",
      event     : "dblclick",
      style  		: 'inherit',
			cssclass	: 'inherit',
			indicator : 'Action en cours',
			placeholder : "<em>Objet en construction</em>",
			ajaxoptions : {
				complete: function(requete, statut) {
										$.post(sys_path+"_message.php", function(retour){
											$('#zone_message').html($.trim(retour));
										});
									$('#log').load(sys_path+"_log.php");
									}
				},
			onedit		: function(requete, statut) {
										$.post(sys_path+"_message.php", function(retour){
											$('#zone_message').html($.trim(retour));
										});
									$('#log').load(sys_path+"_log.php");
									},
			onblur		: 'submit'
  });	

	$(".editable[type_objet=image]").editable('', { 
      type      : "image",
      loadurl   : path+"_img_edition.php",
			loadtype	: 'POST',
			loaddata	: function(){
										return {master_js:1, id_objet:$(this).attr("id_objet") };
									},
			loadtext	: "Edition en cours ...",
			width			: "none",
			height		: "none",
      event     : "dblclick",
      style  		: 'inherit',
			cssclass	: 'inherit',
			indicator : 'Action en cours',
			placeholder : "",
			onedit		: function(requete, statut) {
										$.post(sys_path+"_message.php", function(retour){
											$('#zone_message').html($.trim(retour));
										});
									$('#log').load(sys_path+"_log.php");
									},
			onblur		: 'ignore'
  });	

}

