// Association des constructeurs-propriétaires en électricité et des électriciens d'entretien du Québec
// Scripts communs à toutes les pages du site (jQuery)

$(document).ready(function(){
						   
	// Add bookmark script
	
	// add a "rel" attrib if Opera 7+  
	if(window.opera) {  
			if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set  
					$("a.jqbookmark").attr("rel","sidebar");  
			}  
	}  

	$("a.jqbookmark").click(function(event){  
			event.preventDefault(); // prevent the anchor tag from sending the user off to the link  
			var url = this.href;  
			var title = $("title").text();//this.title
			
			//alert(url + " - " + title);

			if (window.sidebar) { // Mozilla Firefox Bookmark  
					window.sidebar.addPanel(title, url,"");  
			} else if( window.external ) { // IE Favorite  
					window.external.AddFavorite(url, title);  
			} else if(window.opera) { // Opera 7+  
					return false; // do nothing - the rel="sidebar" should do the trick  
			} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)  
					 alert("Malheureusement, votre fureteur ne supporte pas l'ajout de favoris par JavaScript,"  
					 + " veuillez ajouter le favori manuellement.");  
			}  

	});		
	
	// Rollovers for other buttons (class="roll")
	$("a.roll").mouseover(function() {
		imgsrc = $(this).children("img").attr("src");
		// Fail if no image found
		if (typeof(imgsrc) != 'undefined') {
			// Replace .gif with _over.gif
			imgsrcON = imgsrc.replace('.gif', '_over.gif');
			// Now change the src to the 'ON' value
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	
	$("a.roll").mouseout(function(){
	  // trap for 'undefined' errors again
	  if (typeof(imgsrc) != 'undefined') {
		  $(this).children("img").attr("src", imgsrc);
	  }
	});
	
	// Corners
	$("#secContent #outils").corner("round 10px");
	$("#secContent #outils h2 span").corner("round tl tr 10px");
	$("#secContent #secNav a").corner("round 10px");
	$("#signaler ul li").corner("round tl tr 5px");
	$("#signaler").corner("round bl br 10px");
	
	// Tabs
	$("#signaler > ul").tabs();
	
	// Ouverture et fermeture des Activités (definition lists dl/dt/dd)
	// En premier lieu, cacher le texte principal (dd) et laisser seulement les questions visibles
	// Ensuite, ajouter la classe par défaut requise (closed) au questions pour les rendre "cliquables"
	$(".activites dd").hide();
	$(".activites dt").addClass("closed");
	// Ajouter variable pour garder la dernière question ouverte en mémoire et la fermer lorsque'une autre
	// question est ouverte
	var lastOpen;

	$(".activites dt").click(function() {
		$(".activites dt").attr("class", "closed"); // set class of all dt elems to closed
		if (!$.browser.msie) {
			$(lastOpen).next().toggle(500); // Hide the last showing dd
		} else {
			$(lastOpen).next().toggle(); // Hide the last showing dd without animation to avoid loss of anti-aliasing issue in IE
		}
		$(this).toggleClass("open"); // Set the class of the dt that was just clicked to open
		if (!$.browser.msie) {
			$(this).next().toggle(500); // Show the clicked dt's dd
		} else {
			$(this).next().toggle(); // Show the clicked dt's dd without animation to avoid loss of anti-aliasing issue in IE
		}
		lastOpen = this;		
	});
	
});
