 
/*
 * jQuery Tooltip plugin 1.3
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 J�rn Zaefferer
 *
 * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
 
;(function($) {
	
		// the tooltip element
	var helper = {},
		// the current tooltipped element
		current,
		// the title of the current element, used for restoring
		title,
		// timeout id for delayed tooltips
		tID,
		// IE 5.5 or 6
		IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		// flag for mouse tracking
		track = false;
	
	$.tooltip = {
		blocked: false,
		defaults: {
			delay: 200,
			fade: false,
			showURL: true,
			extraClass: "",
			top: 10,
			left: 15,
			id: "tooltip",
			positionBottom:true
		},
		block: function() {
			$.tooltip.blocked = !$.tooltip.blocked;
		}
	};
	
	$.fn.extend({
		tooltip: function(settings) {
			settings = $.extend({}, $.tooltip.defaults, settings);
			createHelper(settings);
			
			
			return this.each(function() {
					$.data(this, "tooltip", settings);
					this.tOpacity = helper.parent.css("opacity");
					// copy tooltip into its own expando and remove the title
					if(!this.title) {
						this.title = this.alt;
					}
					this.tooltipText = this.title;
					/*
					$(this).removeAttr("title");				
					this.alt = "";
					*/
					if($(this).attr('href') == '' || $(this).attr('href') == '#') {						
						$(this).attr('href','')
						$(this).removeAttr('href');
						$(this)[0].removeAttribute('href');
						$(this).attr('nohref','nohref');
						$(this).addClass('noclick');
					}
					
				})
				.mouseover(save)
				.focus(saveFocus)
				.mouseout(hide)
				.click(hide);
		},
		fixPNG: IE ? function() {
			return this.each(function () {
				var image = $(this).css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
					image = RegExp.$1;
					$(this).css({
						'backgroundImage': 'none',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
					}).each(function () {
						var position = $(this).css('position');
						if (position != 'absolute' && position != 'relative')
							$(this).css('position', 'relative');
					});
				}
			});
		} : function() { return this; },
		unfixPNG: IE ? function() {
			return this.each(function () {
				$(this).css({'filter': '', backgroundImage: ''});
			});
		} : function() { return this; },
		hideWhenEmpty: function() {
			return this.each(function() {
				$(this)[ $(this).html() ? "show" : "hide" ]();
			});
		},
		url: function() {
			return this.attr('href') || this.attr('src');
		}
	});
	
	function createHelper(settings) {
		// there can be only one tooltip helper
		if( helper.parent )
			return;
		// create the helper, h3 for title, div for url
		helper.parent = $('<div style="position: absolute;z-index: 3000;margin-right:15px;background:url('+window.baseU+'tooltip.gif) bottom right;padding:0 1px 14px 0;" id="' + settings.id + '"><h3 style="margin:0;padding:9px 10px 9px 13px ;background:url('+window.baseU+'tooltip_lien.gif) no-repeat;color:white;font-size:13px;"></h3></div>')
			// add to document
			.appendTo(document.body)
			// hide it at first
			.hide();
			
		// apply bgiframe if available
		if ( $.fn.bgiframe )
			helper.parent.bgiframe();
		
		// save references to title and url elements
		helper.title = $('h3', helper.parent);
		helper.body = $('div.body', helper.parent);
		helper.url = $('div.url', helper.parent);
	}
	
	function settings(element) {
		return $.data(element, "tooltip");
	}
	
	// main event handler to start showing tooltips
	function handle(event) {
		// show helper, either with timeout or on instant
		if( settings(this).delay )
			tID = setTimeout(show, settings(this).delay);
		else
			show();
		
		// if selected, update the helper position when the mouse moves
		track = !!settings(this).track;
		
		window.updateMaps = update;
		window.mapInterval = setInterval('window.updateMaps()',20);
		//$(document.body).bind('mousemove', update);
		
		
		
		// update at least once
		update(event);
	}
	
	// save elements title before the tooltip is displayed
	function save() {
		//console.log('SAVE')	;
	
		// if this is the current source, or it has no title (occurs with click event), stop
		if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) )
			return;

		
		// save current
		current = this;
		title = this.tooltipText;

		if($(this).attr('href') != "" && $(this).attr('href') != undefined) {
			$('#tooltip').removeClass('nolink');
		} else {
			$('#tooltip').addClass('nolink');
		}


		window.currentArea = this;
		
		if ( settings(this).bodyHandler ) {
			helper.title.hide();
			var bodyContent = settings(this).bodyHandler.call(this);
			if (bodyContent.nodeType || bodyContent.jquery) {
				helper.body.empty().append(bodyContent)
			} else {
				helper.body.html( bodyContent );
			}
			helper.body.show();
		} else if ( settings(this).showBody ) {
			var parts = title.split(settings(this).showBody);
			helper.title.html(parts.shift()).show();
			helper.body.empty();
			for(var i = 0, part; (part = parts[i]); i++) {
				if(i > 0)
					helper.body.append("<br/>");
				helper.body.append(part);
			}
			helper.body.hideWhenEmpty();
		} else {
			helper.title.html(title).show();
			helper.body.hide();
		}
		
		// if element has href or src, add and show it, otherwise hide it
		if( settings(this).showURL && $(this).url() )
			helper.url.html( $(this).url().replace('http://', '') ).show();
		else 
			helper.url.hide();
		
		// add an optional class for this tip
		helper.parent.addClass(settings(this).extraClass);

		// fix PNG background for IE
		if (settings(this).fixPNG )
			helper.parent.fixPNG();
			
		handle.apply(this, arguments);
	}
	
	// save elements title before the tooltip is displayed
	function saveFocus() {
		//console.log(window.omitNextFocus);
	
		if(window.omitNextFocus) {
			window.omitNextFocus = false;		
			return;
		}
		//console.log('SAVEFOCUS')	;
		// if this is the current source, or it has no title (occurs with click event), stop
		if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) )
			return;

		// save current
		current = this;
		title = this.tooltipText;
		/*
		$(this).attr("title",title);
		$(this).attr("alt",title);
		*/
		//$(this).attr("alt",title);
		//this.alt = title;
		
		if($(this).attr('href') != "" && $(this).attr('href') != undefined) {
			$('#tooltip').removeClass('nolink');
		} else {
			$('#tooltip').addClass('nolink');
		}
		window.currentArea = this;		
		
		if ( settings(this).bodyHandler ) {
			helper.title.hide();
			var bodyContent = settings(this).bodyHandler.call(this);
			if (bodyContent.nodeType || bodyContent.jquery) {
				helper.body.empty().append(bodyContent)
			} else {
				helper.body.html( bodyContent );
			}
			helper.body.show();
		} else if ( settings(this).showBody ) {
			var parts = title.split(settings(this).showBody);
			helper.title.html(parts.shift()).show();
			helper.body.empty();
			for(var i = 0, part; (part = parts[i]); i++) {
				if(i > 0)
					helper.body.append("<br/>");
				helper.body.append(part);
			}
			helper.body.hideWhenEmpty();
		} else {
			helper.title.html(title).show();
			helper.body.hide();
		}
		
		// if element has href or src, add and show it, otherwise hide it
		if( settings(this).showURL && $(this).url() )
			helper.url.html( $(this).url().replace('http://', '') ).show();
		else 
			helper.url.hide();
		
		// add an optional class for this tip
		helper.parent.addClass(settings(this).extraClass);

		// fix PNG background for IE
		if (settings(this).fixPNG )
			helper.parent.fixPNG();
			
		handle.apply(this, arguments);
	}
	
	// delete timeout and show helper
	function show() {
		tID = null;
		if ((!IE || !$.fn.bgiframe) && settings(current).fade) {
			if (helper.parent.is(":animated"))
				helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity);
			else
				helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade);
		} else {
			helper.parent.show();
		}
		update();
	}
	
	/**
	 * callback for mousemove
	 * updates the helper position
	 * removes itself when no current element
	 */
	function update(event)	{
		if($.tooltip.blocked)
			return;
		
		if (event && event.target.tagName == "OPTION") {
			return;
		}
		event = true;
		
		
		// stop updating when tracking is disabled and the tooltip is visible
		if ( !track && helper.parent.is(":visible")) {
			if(window.mapInterval) {
				clearInterval(window.mapInterval);
			}
			//$(document.body).unbind('mousemove', update)
		} else {
			//setTimeout("window.updateMaps()",20);
		}
		
		// if no current element is available, remove this listener
		if( current == null ) {
			//$(document.body).unbind('mousemove', update);
			if(window.mapInterval) {
				clearInterval(window.mapInterval);
			}
			return;	
		}else {
			//setTimeout("window.updateMaps()",20);
		}
		
		// remove position helper classes
		helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
		
		var left = helper.parent[0].offsetLeft;
		var top = helper.parent[0].offsetTop;
		var bottom = 'auto';
		if (event) {
			
			// position the helper 15 pixel to bottom right, starting from mouse position
			left = window.M_X + settings(current).left;
			top = window.M_Y + settings(current).top;
						
			var right='auto';
			if (settings(current).positionLeft) {
				right = $(window).width() - left;
				left = 'auto';
			}
			if (settings(current).positionBottom) {
				//top = 'auto';
				top = /*$(window).height() - */window.M_Y - 55;
			}
			helper.parent.css({
				left: left,
				right: right,
				top: top,
				bottom:bottom
			});
		}
		
		var v = viewport(),
			h = helper.parent[0];
		// check horizontal position
		if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
			left -= h.offsetWidth + 20 + settings(current).left;
			helper.parent.css({left: left + 'px'}).addClass("viewport-right");
		}
		// check vertical position
		if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
			top -= h.offsetHeight + 20 + settings(current).top;
			helper.parent.css({top: top + 'px'}).addClass("viewport-bottom");
		}
	}
	
	function viewport() {
		return {
			x: $(window).scrollLeft(),
			y: $(window).scrollTop(),
			cx: $(window).width(),
			cy: $(window).height()
		};
	}
	
	// hide helper and restore added classes and the title
	function hide(event) {
		
		//console.log('HIDE')	;
	
		if($.tooltip.blocked)
			return;
		// clear timeout if possible
		if(current) {
			/*$(current).removeAttr("title");				
			current.alt = "";*/
		}
		if(tID)
			clearTimeout(tID);
		if(window.mapInterval) {
			clearInterval(window.mapInterval);
		}
		// no more current element
		current = null;
		
		var tsettings = settings(this);
		
		function complete() {
			helper.parent.removeClass( tsettings.extraClass ).hide().css("opacity", "");
		}
		
		if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
			if (helper.parent.is(':animated'))
				helper.parent.stop().fadeTo(tsettings.fade, 0, complete);
			else
				helper.parent.stop().fadeOut(tsettings.fade, complete);
		} else
			complete();
		
		if( settings(this).fixPNG )
			helper.parent.unfixPNG();
			
	}
	
})(jQuery);

(function($) {
	var has_VML, create_canvas_for, add_shape_to, clear_canvas, shape_from_area,
		canvas_style, fader, hex_to_decimal, css3color, is_image_loaded;
	has_VML = document.namespaces;
	has_canvas = document.createElement('canvas');
	has_canvas = has_canvas && has_canvas.getContext;
	
	if(!(has_canvas || has_VML)) {
		$.fn.maphilight = function() { return this; };
		return;
	}
	
	if(has_canvas) {
		fader = function(element, opacity, interval) {
			if(opacity <= 1) {
				element.style.opacity = opacity;
				window.setTimeout(fader, 10, element, opacity + 0.1, 10);
			}
		};
		
		hex_to_decimal = function(hex) {
			return Math.max(0, Math.min(parseInt(hex, 16), 255));
		};
		css3color = function(color, opacity) {
			return 'rgba('+hex_to_decimal(color.substr(0,2))+','+hex_to_decimal(color.substr(2,2))+','+hex_to_decimal(color.substr(4,2))+','+opacity+')';
		};
		create_canvas_for = function(img) {
			var c = $('<canvas style="width:'+img.width+'px;height:'+img.height+'px;"></canvas>').get(0);
			c.getContext("2d").clearRect(0, 0, c.width, c.height);
			return c;
		};
		add_shape_to = function(canvas, shape, coords, options) {
			var i, context = canvas.getContext('2d');
			context.beginPath();
			if(shape == 'rect') {
				context.rect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
			} else if(shape == 'poly') {
				context.moveTo(coords[0], coords[1]);
				for(i=2; i < coords.length; i+=2) {
					context.lineTo(coords[i], coords[i+1]);
				}
			} else if(shape == 'circ') {
				context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2, false);
			}
			context.closePath();
			if(options.fill) {
				context.fillStyle = css3color(options.fillColor, options.fillOpacity);
				context.fill();
			}
			if(options.stroke) {
				context.strokeStyle = css3color(options.strokeColor, options.strokeOpacity);
				context.lineWidth = options.strokeWidth;
				context.stroke();
			}
			if(options.fade) {
				fader(canvas, 0);
			}
		};
		clear_canvas = function(canvas, area) {
			canvas.getContext('2d').clearRect(0, 0, canvas.width,canvas.height);
		};
	} else {
		if(!document.documentMode || document.documentMode<8) {
			document.createStyleSheet().addRule("v\\:*", "behavior: url(#default#VML); antialias: true;"); 
			document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
		}
		else 
		if(document.documentMode && document.documentMode>=8) {
			document.writeln('<?import namespace="v" implementation="#default#VML" ?>');
			document.namespaces.add("v", "urn:schemas-microsoft-com:vml","#default#VML"); 
		} else {
			document.createStyleSheet().addRule("v\\:*", "behavior: url(#default#VML); antialias: true;"); 
			document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
		}
		
		
		create_canvas_for = function(img) {
			return $('<var style="zoom:1;overflow:hidden;display:block;width:'+img.width+'px;height:'+img.height+'px;"></var>').get(0);
		};
		add_shape_to = function(canvas, shape, coords, options) {
			var fill, stroke, opacity, e;
			fill = '<v:fill color="#'+options.fillColor+'" opacity="'+(options.fill ? options.fillOpacity : 0)+'" />';
			stroke = (options.stroke ? 'strokeweight="'+options.strokeWidth+'" stroked="t" strokecolor="#'+options.strokeColor+'"' : 'stroked="f"');
			opacity = '<v:stroke opacity="'+options.strokeOpacity+'"/>';
			if(shape == 'rect') {
				e = $('<v:rect filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+coords[0]+'px;top:'+coords[1]+'px;width:'+(coords[2] - coords[0])+'px;height:'+(coords[3] - coords[1])+'px;"></v:rect>');
			} else if(shape == 'poly') {
				e = $('<v:shape filled="t" '+stroke+' coordorigin="0,0" coordsize="'+canvas.width+','+canvas.height+'" path="m '+coords[0]+','+coords[1]+' l '+coords.join(',')+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+canvas.width+'px;height:'+canvas.height+'px;"></v:shape>');
			} else if(shape == 'circ') {
				e = $('<v:oval filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(coords[0] - coords[2])+'px;top:'+(coords[1] - coords[2])+'px;width:'+(coords[2]*2)+'px;height:'+(coords[2]*2)+'px;"></v:oval>');
			}
			e.get(0).innerHTML = fill+opacity;
			$(canvas).append(e);
		};
		clear_canvas = function(canvas) {
			$(canvas).empty();
		};
	}
	shape_from_area = function(area) {
		var i, coords = area.getAttribute('coords').split(',');
		for (i=0; i < coords.length; i++) { coords[i] = parseFloat(coords[i]); }
		return [area.getAttribute('shape').toLowerCase().substr(0,4), coords];
	};
	
	is_image_loaded = function(img) {
		if(!img.complete) { return false; } // IE
		if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; } // Others
		return true;
	}

	canvas_style = {
		position: 'absolute',
		left: 0,
		top: 0,
		padding: 0,
		border: 0
	};
	
	$.fn.maphilight = function(opts) {
		opts = $.extend({}, $.fn.maphilight.defaults, opts);
		return this.each(function() {
			var img, wrap, options, map, canvas, canvas_always, mouseover;
			img = $(this);
			if(!is_image_loaded(this)) { return window.setTimeout(function() { img.maphilight(opts); }, 200); }
			options = $.metadata ? $.extend({}, opts, img.metadata()) : opts;
			map = $('map[name="'+img.attr('usemap').substr(1)+'"]');
			if(!(img.is('img') && img.attr('usemap') && map.size() > 0 && !img.hasClass('maphilighted'))) { return; }
			wrap = $('<div>').css({display:'block',background:'url('+this.src+')',position:'relative',padding:0,width:this.width,height:this.height});
			img.before(wrap).css('opacity', 0).css(canvas_style).remove();
			if($.browser.msie) { img.css('filter', 'Alpha(opacity=0)'); }
			wrap.append(img);
			
			canvas = create_canvas_for(this);
			$(canvas).css(canvas_style);
			canvas.height = this.height;
			canvas.width = this.width;
			
			mouseover = function(e) {
				var shape, area_options;
				area_options = $.metadata ? $.extend({}, options, $(this).metadata()) : options;
				if(!area_options.alwaysOn) {
					shape = shape_from_area(this);
					add_shape_to(canvas, shape[0], shape[1], area_options);
				}
			};
			
			if(options.alwaysOn) {
				$(map).find('area[coords]').each(mouseover);
			} else {
				if($.metadata) {
					// If the metadata plugin is present, there may be areas with alwaysOn set.
					// We'll add these to a *second* canvas, which will get around flickering during fading.
					$(map).find('area[coords]').each(function() {
						var shape, area_options;
						area_options = $.metadata ? $.extend({}, options, $(this).metadata()) : options;
						if(area_options.alwaysOn) {
							if(!canvas_always) {
								canvas_always = create_canvas_for(img.get());
								$(canvas_always).css(canvas_style);
								canvas_always.width = img.width();
								canvas_always.height = img.height();
								img.before(canvas_always);
							}
							shape = shape_from_area(this);
							add_shape_to(canvas_always, shape[0], shape[1], area_options);
						}
					})
				}
				$(map).find('area[coords]').mouseover(mouseover).mouseout(function(e) { clear_canvas(canvas); });
				$(map).find('area[coords]').focus(mouseover).blur(function(e) { clear_canvas(canvas); });
			}
			
			img.before(canvas); // if we put this after, the mouseover events wouldn't fire.
			img.addClass('maphilighted');
		});
	};
	$.fn.maphilight.defaults = {
		fill: true,
		fillColor: '000000',
		fillOpacity: 0.2,
		stroke: true,
		strokeColor: 'ff0000',
		strokeOpacity: 1,
		strokeWidth: 1,
		fade: true,
		alwaysOn: false
	};
})(jQuery);

window.omitNextFocus = false;
function doMmapLinks() {
	
	if($(this).attr('href') != "" && $(this).attr('href') != undefined && $(this).attr('rel') != "same") {
		/*if(window.FENETREVISITE) {
			window.FENETREVISITE.focus();
		}*/		
		window.omitNextFocus = true;
		var hhref = this.href;
		hhref = hhref.replace("bpi.fr/","bpi.fr/print/");
		window.FENETREVISITE = window.open(hhref,"visitev",'width=760,height=500,scrollbars=yes');
		window.FENETREVISITE.focus();
		//$('#tooltip').hide();
		
		return false;
	}	
}

window.baseU = "/modules/resources/view/default/En_pratique/Visite_virtuelle/";
//window.baseU = "./";
//window.baseU = "";

h = '';
h += '<div style="position:absolute;top:-50000px"><img src="'+window.baseU+'tooltip_nolien.gif" alt=""/>';
h += '<img src="'+window.baseU+'tooltip_no.gif" alt=""/>';
h += '<img src="'+window.baseU+'tooltip_lien.gif" alt=""/>';
h += '<img src="'+window.baseU+'tooltip.gif" alt=""/></div>';
if($('#left-column')[0]) {
$('#left-column')[0].innerHTML += h;
}

var styleElement = document.createElement("style");
styleElement.type = "text/css";
document.getElementsByTagName("head")[0].appendChild(styleElement);
cssT = "#tooltip h3 {text-decoration:underline} .noclick:hover, .noclick { cursor:default!important; text-decoration:none!important}";
cssT += ".nolink h3 {font-weight:normal!important;background:url("+window.baseU+"tooltip_nolien.gif) no-repeat !important; position:relative; text-decoration:none!important ";
cssT += "text-decoration:none!important;color:#59358a!important;text-decoration:none!important; }";
cssT += " .nolink {background:url("+baseU+"tooltip_no.gif) bottom right!important; text-decoration:none!important}";
cssT += " .mapper {display:block}";
cssT += " div#content-column {width:72em!important;}";
if(styleElement.styleSheet) {
	styleElement.styleSheet.cssText = cssT;
} else {
	nStyl = document.createTextNode(cssT);
	styleElement.appendChild(nStyl);
}


function myUpdate (event) {

		window.M_X = event.pageX;
		window.M_Y = event.pageY;		
		//$('#right-column').html(window.M_X);
		removeMapsTitles();
}

function removeMapsTitles() {
	if(window.mapsTitleSet) {
		$('#mmap area').each(function() {
			$(this).attr('title',"");
			$(this).attr('alt',"");
			$(this).removeAttr('title');
			$(this).removeAttr('alt');
		});
		window.mapsTitleSet = false;
	}
	
}

function checkMapsTitles(e) {
	//if(e.keyCode == 9)	 {		
		setMapsTitles();
//	}
}

function setMapsTitles() {
	if(!window.mapsTitleSet) {			
		$('#mmap area').each(function() {
			$('#log').html($(this)[0].tooltipText);
			$(this).attr('title',$(this)[0].tooltipText);
			$(this).attr('alt',$(this)[0].tooltipText);
			$(this)[0].title = $(this)[0].tooltipText;
			$(this)[0].alt = $(this)[0].tooltipText;
		});
		
		window.mapsTitleSet = true;
	}
}

window.mapsTitleSet = false;


$(document).ready(function() {
	$('#mmap *').tooltip({fixPNG:false,showURL:false, track:true,delay: 20,positionLeft: true,positionBottom:true,top:5}).click(doMmapLinks);
	$('.mapper').maphilight({stroke:false,strokeColor:'000000',fillColor:'000000',fillOpacity: 0.5}).hover(function() {this.alt = ""});	
	setMapsTitles();
	$(document.body).bind('keypress', checkMapsTitles);
	$(document.body).bind('mousemove', myUpdate);
	//$('.mapper').bind('onmouseover',myUpdate);
	//$('.mapper').bind('mouseover',myUpdate);
	$('.mapper').bind('mousemove',myUpdate);
	//$('.mapper').bind('onmousemove',myUpdate);
});

