 //







var format_remove_accents = function (string) {
	var chars = {'ç':'c', 'æ':'ae', 'œ':'oe', '[áàäâå]':'a', '[éèëê]':'e', '[íìïî]':'i', '[óòöô]':'o', '[úùüû]':'u', 'ÿ':'y'};
	string = String(string);
	for( var c in chars ) {
		string = string.replace( new RegExp( c ,"g"), chars[c] );
	}
	return string;
};

var format_clean_for_url = function(string) {
	string = (string+'').toLowerCase();
	string = format_remove_accents(string);
	string = String(string).replace( new RegExp("([^a-z0-9])+" ,"g"), '_');
	return string;
};



var is_redirecting=false;
var redirect = function(location,force){
	force = force || false;
	location = location || window.location.href;
	if (!is_redirecting || force) {
		is_redirecting = true;
		window.location.href = location;
	}
	return false;
};














/*
 * flashMessenger plugin
 */
var flashMessenger = {
	setup: function(appendTo, msgOpacity) {
		flashMessenger.msgID = 'flashMessenger';
		// appendTo is the element the msg is appended to
		if (appendTo == undefined) {
			appendTo = 'body';
		}
		// Opacity of the message
		flashMessenger.msgOpacity = .9;

		if (msgOpacity != undefined) {
			flashMessenger.msgOpacity = parseFloat(msgOpacity);
		}
		// Inject the message structure
		jQuery(appendTo).append('<div id="'+flashMessenger.msgID+'" class="flashMessenger"><div class="round"></div><p></p><div class="round"></div></div>');

	},

	displayMsg: function(msg, type) {
		if (typeof type == undefined) {
			type = 'info';
		}
		if (msg == '') {
			return;
		}
		clearTimeout(flashMessenger.t2);
		// Inject message
		jQuery('#'+flashMessenger.msgID+' p').html(msg);
		jQuery('#'+flashMessenger.msgID).addClass('type_'+type);
		// Show message
		jQuery('#'+flashMessenger.msgID+'').show().animate({ opacity: flashMessenger.msgOpacity}, 200);
		// Watch for mouse & keyboard in .5s
		flashMessenger.t1 = setTimeout("flashMessenger.bindEvents()", 700);
		// Remove message after 5s
		flashMessenger.t2 = setTimeout("flashMessenger.removeMsg()", 5000);
	},

	bindEvents: function() {
	// Remove message if mouse is moved or key is pressed : Marche pas sous IE, les events sont jamais déclenchés :(
//		jQuery(window)
//			.mousemove(flashMessenger.removeMsg)
//			.click(flashMessenger.removeMsg)
//			.keypress(flashMessenger.removeMsg);
		jQuery(document).bind('mousemove click keypress',flashMessenger.removeMsg);
	},

	removeMsg: function() {
		// Unbind mouse & keyboard
		jQuery(document).unbind('mousemove click keypress', flashMessenger.removeMsg);
		// If message is fully transparent, fade it out
		if (jQuery('#'+flashMessenger.msgID).css('opacity') == flashMessenger.msgOpacity) {
			jQuery('#'+flashMessenger.msgID).animate({ opacity: 0 }, 500, function() { jQuery(this).hide() });
		}
	}
};

jQuery(document).ready(function(){
	flashMessenger.setup();
});






// qs_score - Quicksilver Score
//
// A port of the Quicksilver string ranking algorithm
//
// "hello world".score("axl") //=> 0.0
// "hello world".score("ow") //=> 0.6
// "hello world".score("hello world") //=> 1.0
//
// Tested in Firefox 2 and Safari 3
//
// The Quicksilver code is available here
// http://code.google.com/p/blacktree-alchemy/
// http://blacktree-alchemy.googlecode.com/svn/trunk/Crucible/Code/NSString+BLTRRanking.m
//
// The MIT License
//
// Copyright (c) 2008 Lachie Cox
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


String.prototype.score = function(abbreviation,offset) {
	offset = offset || 0 // TODO: I think this is unused... remove
	if (abbreviation.length == 0) {
		return 0.9;
	}
	if (abbreviation.length > this.length) {
		return 0.0;
	}

	var mot = format_remove_accents(this);

	for (var i = abbreviation.length; i > 0; i--) {
		var sub_abbreviation = abbreviation.substring(0,i);
		var index = mot.indexOf(sub_abbreviation);
		if(index < 0) {
			continue;
		}
		if(index + abbreviation.length > mot.length + offset) {
			continue;
		}
		var next_string	   = mot.substring(index+sub_abbreviation.length);
		var next_abbreviation = null;
		if(i >= abbreviation.length) {
			next_abbreviation = '';
		} else {
			next_abbreviation = abbreviation.substring(i)
		}
		var remaining_score   = next_string.score(next_abbreviation,offset+index);
		if (remaining_score > 0) {
			var score = mot.length-next_string.length;
			if (index != 0) {
				var j = 0;
				var c = mot.charCodeAt(index - 1);
				if (c==32 || c == 9) {
					for(var j=(index-2); j >= 0; j--) {
						c = mot.charCodeAt(j);
						score -= ((c == 32 || c == 9) ? 1 : 0.15);
					}
				} else {
					score -= index;
				}
			}

			score += remaining_score * next_string.length;
			score /= mot.length;
			return score;
		}
	}
	return 0.0;
};








/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
 * $Rev: 2447 $
 *
 * Version 2.1.1
 */
;(function($){

/**
 * The bgiframe is chainable and applies the iframe hack to get
 * around zIndex issues in IE6. It will only apply itself in IE
 * and adds a class to the iframe called 'bgiframe'. The iframe
 * is appeneded as the first child of the matched element(s)
 * with a tabIndex and zIndex of -1.
 *
 * By default the plugin will take borders, sized with pixel units,
 * into account. If a different unit is used for the border's width,
 * then you will need to use the top and left settings as explained below.
 *
 * NOTICE: This plugin has been reported to cause perfromance problems
 * when used on elements that change properties (like width, height and
 * opacity) a lot in IE6. Most of these problems have been caused by
 * the expressions used to calculate the elements width, height and
 * borders. Some have reported it is due to the opacity filter. All
 * these settings can be changed if needed as explained below.
 *
 * @example $('div').bgiframe();
 * @before <div><p>Paragraph</p></div>
 * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
 *
 * @param Map settings Optional settings to configure the iframe.
 * @option String|Number top The iframe must be offset to the top
 * 		by the width of the top border. This should be a negative
 *	  number representing the border-top-width. If a number is
 * 		is used here, pixels will be assumed. Otherwise, be sure
 *		to specify a unit. An expression could also be used.
 * 		By default the value is "auto" which will use an expression
 * 		to get the border-top-width if it is in pixels.
 * @option String|Number left The iframe must be offset to the left
 * 		by the width of the left border. This should be a negative
 *	  number representing the border-left-width. If a number is
 * 		is used here, pixels will be assumed. Otherwise, be sure
 *		to specify a unit. An expression could also be used.
 * 		By default the value is "auto" which will use an expression
 * 		to get the border-left-width if it is in pixels.
 * @option String|Number width This is the width of the iframe. If
 *		a number is used here, pixels will be assume. Otherwise, be sure
 * 		to specify a unit. An experssion could also be used.
 *		By default the value is "auto" which will use an experssion
 * 		to get the offsetWidth.
 * @option String|Number height This is the height of the iframe. If
 *		a number is used here, pixels will be assume. Otherwise, be sure
 * 		to specify a unit. An experssion could also be used.
 *		By default the value is "auto" which will use an experssion
 * 		to get the offsetHeight.
 * @option Boolean opacity This is a boolean representing whether or not
 * 		to use opacity. If set to true, the opacity of 0 is applied. If
 *		set to false, the opacity filter is not applied. Default: true.
 * @option String src This setting is provided so that one could change
 *		the src of the iframe to whatever they need.
 *		Default: "javascript:false;"
 *
 * @name bgiframe
 * @type jQuery
 * @cat Plugins/bgiframe
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 */
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top	 : 'auto', // auto == .currentStyle.borderTopWidth
			left	: 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src	 : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
			html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
					   'style="display:block;position:absolute;z-index:-1;'+
						   (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
						   'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
						   'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
						   'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
						   'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};

})(jQuery);


// ATTENTION !!! CLUETIP 1.03=> 1.05 buggé avec nos scripts !!!
// NE PAS UPGRADER VERS CES VERSIONS
// Exemple de bug : page guilde / overview / artisanat
// afficher le tooltip d'un filtre ?, puis celui d'un header (juste au dessus)=>le texte du précédent est repris.
//
// fix enox : pour les tt avec splitTitle, le body n'était pas remis dans l'attr title apres un premier survol

/*
 * jQuery clueTip plugin
 * Version 1.0.1  (April 23, 2009)
 * @requires jQuery v1.2.6+
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
 
/*
 *
 * Full list of options/settings can be found at the bottom of this file and at http://plugins.learningjquery.com/cluetip/
 *
 * Examples can be found at http://plugins.learningjquery.com/cluetip/demo/
 *
*/

;(function($) { 
  $.cluetip = {version: '1.0.1'};
  var $cluetip, $cluetipInner, $cluetipOuter, $cluetipTitle, $cluetipArrows, $dropShadow, imgCount;
  $.fn.cluetip = function(js, options) {
	if (typeof js == 'object') {
	  options = js;
	  js = null;
	}
	return this.each(function(index) {
	  var link = this, $this = $(this);	  
	  
	  // support metadata plugin (v1.0 and 2.0)
	  var opts = $.extend(true, {}, $.fn.cluetip.defaults, options || {}, $.metadata ? $this.metadata() : $.meta ? $this.data() : {});

	  // start out with no contents (for ajax activation)
	  var cluetipContents = false;
	  var cluezIndex = parseInt(opts.cluezIndex, 10)-1;
	  var isActive = false, closeOnDelay = 0;

	  // create the cluetip divs
	  if (!$('#cluetip').length) {
		$cluetipInner = $('<div id="cluetip-inner"></div>');
		$cluetipTitle = $('<h3 id="cluetip-title"></h3>');		
		$cluetipOuter = $('<div id="cluetip-outer"></div>').append($cluetipInner).prepend($cluetipTitle);
		$cluetip = $('<div id="cluetip"></div>').css({zIndex: opts.cluezIndex})
		.append($cluetipOuter).append('<div id="cluetip-extra"></div>')[insertionType](insertionElement).hide();
		$('<div id="cluetip-waitimage"></div>').css({position: 'absolute', zIndex: cluezIndex-1})
		.insertBefore('#cluetip').hide();
		$cluetip.css({position: 'absolute', zIndex: cluezIndex});
		$cluetipOuter.css({position: 'relative', zIndex: cluezIndex+1});
		$cluetipArrows = $('<div id="cluetip-arrows" class="cluetip-arrows"></div>').css({zIndex: cluezIndex+1}).appendTo('#cluetip');
	  }
	  var dropShadowSteps = (opts.dropShadow) ? +opts.dropShadowSteps : 0;
	  if (!$dropShadow) {
		$dropShadow = $([]);
		for (var i=0; i < dropShadowSteps; i++) {
		  $dropShadow = $dropShadow.add($('<div></div>').css({zIndex: cluezIndex-i-1, opacity:.1, top: 1+i, left: 1+i}));
		};
		$dropShadow.css({position: 'absolute', backgroundColor: '#000'})
		.prependTo($cluetip);
	  }
	  var tipAttribute = $this.attr(opts.attribute), ctClass = opts.cluetipClass;
	  if (!tipAttribute && !opts.splitTitle && !js) return true;
	  // if hideLocal is set to true, on DOM ready hide the local content that will be displayed in the clueTip
	  if (opts.local && opts.localPrefix) {tipAttribute = opts.localPrefix + tipAttribute;}
	  if (opts.local && opts.hideLocal) { $(tipAttribute + ':first').hide(); }
	  var tOffset = parseInt(opts.topOffset, 10), lOffset = parseInt(opts.leftOffset, 10);
	  // vertical measurement variables
	  var tipHeight, wHeight;
	  var defHeight = isNaN(parseInt(opts.height, 10)) ? 'auto' : (/\D/g).test(opts.height) ? opts.height : opts.height + 'px';
	  var sTop, linkTop, posY, tipY, mouseY, baseline;
	  // horizontal measurement variables
	  var tipInnerWidth = isNaN(parseInt(opts.width, 10)) ? 275 : parseInt(opts.width, 10);
	  var tipWidth = tipInnerWidth + (parseInt($cluetip.css('paddingLeft'),10)||0) + (parseInt($cluetip.css('paddingRight'),10)||0) + dropShadowSteps;
	  var linkWidth = this.offsetWidth;
	  var linkLeft, posX, tipX, mouseX, winWidth;
			
	  // parse the title
	  var tipParts;
	  var tipTitle = (opts.attribute != 'title') ? $this.attr(opts.titleAttribute) : '';
	  if (opts.splitTitle) {
		if(tipTitle == undefined) {tipTitle = '';}
		tipParts = tipTitle.split(opts.splitTitle);
		tipTitle = tipParts.shift();
	  }
	  if (opts.escapeTitle) {
		tipTitle = tipTitle.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;');
	  }
	  
	  var localContent;

/***************************************	  
* ACTIVATION
****************************************/
	
//activate clueTip
	var activate = function(event) {
	  if (!opts.onActivate($this)) {
		return false;
	  }
	  isActive = true;
	  $cluetip.removeClass().css({width: tipInnerWidth});
	  if (tipAttribute == $this.attr('href')) {
		$this.css('cursor', opts.cursor);
	  }
	  $this.attr('title','');
	  if (opts.hoverClass) {
		$this.addClass(opts.hoverClass);
	  }
	  linkTop = posY = $this.offset().top;
	  linkLeft = $this.offset().left;
	  mouseX = event.pageX;
	  mouseY = event.pageY;
	  if ($this[0].tagName.toLowerCase() != 'area') {
		sTop = $(document).scrollTop();
		winWidth = $(window).width();
	  }
// position clueTip horizontally
	  if (opts.positionBy == 'fixed') {
		posX = linkWidth + linkLeft + lOffset;
		$cluetip.css({left: posX});
	  } else {
		posX = (linkWidth > linkLeft && linkLeft > tipWidth)
		  || linkLeft + linkWidth + tipWidth + lOffset > winWidth 
		  ? linkLeft - tipWidth - lOffset 
		  : linkWidth + linkLeft + lOffset;
		if ($this[0].tagName.toLowerCase() == 'area' || opts.positionBy == 'mouse' || linkWidth + tipWidth > winWidth) { // position by mouse
		  if (mouseX + 20 + tipWidth > winWidth) {  
			$cluetip.addClass(' cluetip-' + ctClass);
			posX = (mouseX - tipWidth - lOffset) >= 0 ? mouseX - tipWidth - lOffset - parseInt($cluetip.css('marginLeft'),10) + parseInt($cluetipInner.css('marginRight'),10) :  mouseX - (tipWidth/2);
		  } else {
			posX = mouseX + lOffset;
		  }
		}
		var pY = posX < 0 ? event.pageY + tOffset : event.pageY;
		$cluetip.css({left: (posX > 0 && opts.positionBy != 'bottomTop') ? posX : (mouseX + (tipWidth/2) > winWidth) ? winWidth/2 - tipWidth/2 : Math.max(mouseX - (tipWidth/2),0)});
	  }
		wHeight = $(window).height();

/***************************************
* load a string from cluetip method's first argument
***************************************/
	  if (js) {
		if (typeof js == 'function') {
		  js = js($this[0]);
		}
		$cluetipInner.html(js);
		cluetipShow(pY);
	  }
/***************************************
* load the title attribute only (or user-selected attribute). 
* clueTip title is the string before the first delimiter
* subsequent delimiters place clueTip body text on separate lines
***************************************/

	  else if (tipParts) {
		var tpl = tipParts.length;
		$cluetipInner.empty();
		for (var i=0; i < tpl; i++){
		  if (i == 0) {
			$cluetipInner.html(tipParts[i]);
		  } else { 
			$cluetipInner.append('<div class="split-body">' + tipParts[i] + '</div>');
		  }			
		};
		cluetipShow(pY);
	  }
/***************************************
* load external file via ajax		  
***************************************/

	  else if (!opts.local && tipAttribute.indexOf('#') != 0) {
		if (/\.(jpe?g|tiff?|gif|png)$/i.test(tipAttribute)) {
		  $cluetipInner.html('<img src="' + tipAttribute + '" alt="' + tipTitle + '" />');
		  cluetipShow(pY);
		} else if (cluetipContents && opts.ajaxCache) {
		  $cluetipInner.html(cluetipContents);
		  cluetipShow(pY);
		} else {
		  var optionBeforeSend = opts.ajaxSettings.beforeSend,
			  optionError = opts.ajaxSettings.error,
			  optionSuccess = opts.ajaxSettings.success,
			  optionComplete = opts.ajaxSettings.complete;
		  var ajaxSettings = {
			cache: false, // force requested page not to be cached by browser
			url: tipAttribute,
			beforeSend: function(xhr) {
			  if (optionBeforeSend) {optionBeforeSend.call(link, xhr, $cluetip, $cluetipInner);}
			  $cluetipOuter.children().empty();
			  if (opts.waitImage) {
				$('#cluetip-waitimage')
				.css({top: mouseY+20, left: mouseX+20})
				.show();
			  }
			},
			error: function(xhr, textStatus) {
			  if (isActive) {
				if (optionError) {
				  optionError.call(link, xhr, textStatus, $cluetip, $cluetipInner);
				} else {
				  $cluetipInner.html('<i>sorry, the contents could not be loaded</i>');  
				}
			  }
			},
			success: function(data, textStatus) {	   
			  cluetipContents = opts.ajaxProcess.call(link, data);
			  if (isActive) {
				if (optionSuccess) {optionSuccess.call(link, data, textStatus, $cluetip, $cluetipInner);}
				$cluetipInner.html(cluetipContents);
			  }
			},
			complete: function(xhr, textStatus) {
			  if (optionComplete) {optionComplete.call(link, xhr, textStatus, $cluetip, $cluetipInner);}
			  imgCount = $('#cluetip-inner img').length;
			  if (imgCount && !$.browser.opera) {
				$('#cluetip-inner img').load(function() {
				  imgCount--;
				  if (imgCount<1) {
					$('#cluetip-waitimage').hide();
					if (isActive) cluetipShow(pY);
				  }
				}); 
			  } else {
				$('#cluetip-waitimage').hide();
				if (isActive) { cluetipShow(pY); }
			  } 
			}
		  };
		  var ajaxMergedSettings = $.extend(true, {}, opts.ajaxSettings, ajaxSettings);
		  
		  $.ajax(ajaxMergedSettings);
		}

/***************************************
* load an element from the same page
***************************************/
	  } else if (opts.local) {
		
		var $localContent = $(tipAttribute + (/#\w+$/.test(tipAttribute) ? '' : ':eq(' + index + ')')).clone(true).show();
		$cluetipInner.html($localContent);
		cluetipShow(pY);
	  }
	};

// get dimensions and options for cluetip and prepare it to be shown
	var cluetipShow = function(bpY) {
	  $cluetip.addClass('cluetip-' + ctClass);
	  if (opts.truncate) { 
		var $truncloaded = $cluetipInner.text().slice(0,opts.truncate) + '...';
		$cluetipInner.html($truncloaded);
	  }
	  function doNothing() {}; //empty function
	  tipTitle ? $cluetipTitle.show().html(tipTitle) : (opts.showTitle) ? $cluetipTitle.show().html('&nbsp;') : $cluetipTitle.hide();
	  if (opts.sticky) {
		var $closeLink = $('<div id="cluetip-close"><a href="#">' + opts.closeText + '</a></div>');
		(opts.closePosition == 'bottom') ? $closeLink.appendTo($cluetipInner) : (opts.closePosition == 'title') ? $closeLink.prependTo($cluetipTitle) : $closeLink.prependTo($cluetipInner);
		$closeLink.bind('click.cluetip', function() {
		  cluetipClose();
		  return false;
		});
		if (opts.mouseOutClose) {
		  if ($.fn.hoverIntent && opts.hoverIntent) { 
			$cluetip.hoverIntent({
			  over: doNothing, 
			  timeout: opts.hoverIntent.timeout,  
			  out: function() { $closeLink.trigger('click'); }
			});
		  } else {
			$cluetip.hover(doNothing, 
			function() {$closeLink.trigger('click'); });
		  }
		} else {
		  $cluetip.unbind('mouseout');
		}
	  }
// now that content is loaded, finish the positioning 
	  var direction = '';
	  $cluetipOuter.css({overflow: defHeight == 'auto' ? 'visible' : 'auto', height: defHeight});
	  tipHeight = defHeight == 'auto' ? Math.max($cluetip.outerHeight(),$cluetip.height()) : parseInt(defHeight,10);   
	  tipY = posY;
	  baseline = sTop + wHeight;
	  if (opts.positionBy == 'fixed') {
		tipY = posY - opts.dropShadowSteps + tOffset;
	  } else if ( (posX < mouseX && Math.max(posX, 0) + tipWidth > mouseX) || opts.positionBy == 'bottomTop') {
		if (posY + tipHeight + tOffset > baseline && mouseY - sTop > tipHeight + tOffset) { 
		  tipY = mouseY - tipHeight - tOffset;
		  direction = 'top';
		} else { 
		  tipY = mouseY + tOffset;
		  direction = 'bottom';
		}
	  } else if ( posY + tipHeight + tOffset > baseline ) {
		tipY = (tipHeight >= wHeight) ? sTop : baseline - tipHeight - tOffset;
	  } else if ($this.css('display') == 'block' || $this[0].tagName.toLowerCase() == 'area' || opts.positionBy == "mouse") {
		tipY = bpY - tOffset;
	  } else {
		tipY = posY - opts.dropShadowSteps;
	  }
	  if (direction == '') {
		posX < linkLeft ? direction = 'left' : direction = 'right';
	  }
	  $cluetip.css({top: tipY + 'px'}).removeClass().addClass('clue-' + direction + '-' + ctClass).addClass(' cluetip-' + ctClass);
	  if (opts.arrows) { // set up arrow positioning to align with element
		var bgY = (posY - tipY - opts.dropShadowSteps);
		$cluetipArrows.css({top: (/(left|right)/.test(direction) && posX >=0 && bgY > 0) ? bgY + 'px' : /(left|right)/.test(direction) ? 0 : ''}).show();
	  } else {
		$cluetipArrows.hide();
	  }

// (first hide, then) ***SHOW THE CLUETIP***
	  $dropShadow.hide();
	  $cluetip.hide()[opts.fx.open](opts.fx.open != 'show' && opts.fx.openSpeed);
	  if (opts.dropShadow) { $dropShadow.css({height: tipHeight, width: tipInnerWidth}).show(); }
	  if ($.fn.bgiframe) { $cluetip.bgiframe(); }
	  // delayed close (not fully tested)
	  if (opts.delayedClose > 0) {
		closeOnDelay = setTimeout(cluetipClose, opts.delayedClose);
	  }
	  // trigger the optional onShow function
	  opts.onShow.call(link, $cluetip, $cluetipInner);
	};

/***************************************
   =INACTIVATION
-------------------------------------- */
	var inactivate = function(event) {
	  isActive = false;
	  $('#cluetip-waitimage').hide();
	  if (!opts.sticky || (/click|toggle/).test(opts.activation) ) {
		cluetipClose();
clearTimeout(closeOnDelay);		
	  };
	  if (opts.hoverClass) {
		$this.removeClass(opts.hoverClass);
	  }
	};
// close cluetip and reset some things
	var cluetipClose = function() {
	  $cluetipOuter 
	  .parent().hide().removeClass();
	  opts.onHide.call(link, $cluetip, $cluetipInner);
	  $this.removeClass('cluetip-clicked');
	  if (tipTitle) { // fix enox
	    if (opts.splitTitle!='' && tipParts){
      $this.attr(opts.titleAttribute, tipTitle + opts.splitTitle + tipParts.join(opts.splitTitle));
      }else{
      $this.attr(opts.titleAttribute, tipTitle);
      }
	  }
	  $this.css('cursor','');
	  if (opts.arrows) $cluetipArrows.css({top: ''});
	};

	$(document).bind('hideCluetip', function(e) {
	  cluetipClose();
	});
/***************************************
   =BIND EVENTS
-------------------------------------- */
  // activate by click
	  if ( (/click|toggle/).test(opts.activation) ) {
		$this.bind('click.cluetip', function(event) {
		  if ($cluetip.is(':hidden') || !$this.is('.cluetip-clicked')) {
			activate(event);
			$('.cluetip-clicked').removeClass('cluetip-clicked');
			$this.addClass('cluetip-clicked');
		  } else {
			inactivate(event);
		  }
		  this.blur();
		  return false;
		});
  // activate by focus; inactivate by blur	
	  } else if (opts.activation == 'focus') {
		$this.bind('focus.cluetip', function(event) {
		  activate(event);
		});
		$this.bind('blur.cluetip', function(event) {
		  inactivate(event);
		});
  // activate by hover
	// clicking is returned false if cluetip url is same as href url
	  } else {
		$this.bind('click.cluetip', function() {
		  if ($this.attr('href') && $this.attr('href') == tipAttribute && !opts.clickThrough) {
			return false;
		  }
		});
		//set up mouse tracking
		var mouseTracks = function(evt) {
		  if (opts.tracking == true) {
			var trackX = posX - evt.pageX;
			var trackY = tipY ? tipY - evt.pageY : posY - evt.pageY;
			$this.bind('mousemove.cluetip', function(evt) {
			  $cluetip.css({left: evt.pageX + trackX, top: evt.pageY + trackY });
			});
		  }
		};
		if ($.fn.hoverIntent && opts.hoverIntent) {
		  $this.bind('mouseover.cluetip', function() {$this.attr('title',''); })
		  .hoverIntent({
			sensitivity: opts.hoverIntent.sensitivity,
			interval: opts.hoverIntent.interval,  
			over: function(event) {
			  activate(event);
			  mouseTracks(event);
			}, 
			timeout: opts.hoverIntent.timeout,  
			out: function(event) {inactivate(event); $this.unbind('mousemove.cluetip');}
		  });		   
		} else {
		  $this.bind('mouseenter.cluetip', function(event) {
			activate(event);
			mouseTracks(event);
		  })
		  .bind('mouseleave.cluetip', function(event) {
			inactivate(event);
			$this.unbind('mousemove.cluetip');
		  });
		}
	  }
	});
  };
  
/*
 * options for clueTip
 *
 * each one can be explicitly overridden by changing its value. 
 * for example: $.fn.cluetip.defaults.width = 200; 
 * would change the default width for all clueTips to 200. 
 *
 * each one can also be overridden by passing an options map to the cluetip method.
 * for example: $('a.example').cluetip({width: 200}); 
 * would change the default width to 200 for clueTips invoked by a link with class of "example"
 *
 */
  
  $.fn.cluetip.defaults = {  // set up default options
	width:			275,	  // The width of the clueTip
	height:		   'auto',   // The height of the clueTip
	cluezIndex:	   3200,	   // Sets the z-index style property of the clueTip
	positionBy:	   'auto',   // Sets the type of positioning: 'auto', 'mouse','bottomTop', 'fixed'
	topOffset:		15,	   // Number of px to offset clueTip from top of invoking element
	leftOffset:	   15,	   // Number of px to offset clueTip from left of invoking element
	local:			false,	// Whether to use content from the same page for the clueTip's body
	localPrefix:	  null,	   // string to be prepended to the tip attribute if local is true
	hideLocal:		true,	 // If local option is set to true, this determines whether local content
								// to be shown in clueTip should be hidden at its original location
	attribute:		'rel',	// the attribute to be used for fetching the clueTip's body content
	titleAttribute:   'title',  // the attribute to be used for fetching the clueTip's title
	splitTitle:	   '',	   // A character used to split the title attribute into the clueTip title and divs
								// within the clueTip body. more info below [6]
	escapeTitle:	  false,	// whether to html escape the title attribute
	showTitle:		true,	 // show title bar of the clueTip, even if title attribute not set
	cluetipClass:	 'default',// class added to outermost clueTip div in the form of 'cluetip-' + clueTipClass.
	hoverClass:	   '',	   // class applied to the invoking element onmouseover and removed onmouseout
	waitImage:		true,	 // whether to show a "loading" img, which is set in jquery.cluetip.css
	cursor:		   'help',
	arrows:		   false,	// if true, displays arrow on appropriate side of clueTip
	dropShadow:	   true,	 // set to false if you don't want the drop-shadow effect on the clueTip
	dropShadowSteps:  6,		// adjusts the size of the drop shadow
	sticky:		   false,	// keep visible until manually closed
	mouseOutClose:	false,	// close when clueTip is moused out
	activation:	   'hover',  // set to 'click' to force user to click to show clueTip
								// set to 'focus' to show on focus of a form element and hide on blur
	clickThrough:	 false,	// if true, and activation is not 'click', then clicking on link will take user to the link's href,
								// even if href and tipAttribute are equal
	tracking:		 false,	// if true, clueTip will track mouse movement (experimental)
	delayedClose:	 0,		// close clueTip on a timed delay (experimental)
	closePosition:	'top',	// location of close text for sticky cluetips; can be 'top' or 'bottom' or 'title'
	closeText:		'Close',  // text (or HTML) to to be clicked to close sticky clueTips
	truncate:		 0,		// number of characters to truncate clueTip's contents. if 0, no truncation occurs

	// effect and speed for opening clueTips
	fx: {			 
					  open:	   'show', // can be 'show' or 'slideDown' or 'fadeIn'
					  openSpeed:  ''
	},	 

	// settings for when hoverIntent plugin is used			 
	hoverIntent: {	
					  sensitivity:  3,
			  			  interval:	 50,
			  			  timeout:	  0
	},

	// short-circuit function to run just before clueTip is shown. 
	onActivate:	   function(e) {return true;},

	// function to run just after clueTip is shown. 
	onShow:		   function(ct, ci){},
	// function to run just after clueTip is hidden.
	onHide:		   function(ct, ci){},
	// whether to cache results of ajax request to avoid unnecessary hits to server	
	ajaxCache:		true,  

	// process data retrieved via xhr before it's displayed
	ajaxProcess:	  function(data) {
						data = data.replace(/<(script|style|title)[^<]+<\/(script|style|title)>/gm, '').replace(/<(link|meta)[^>]+>/g,'');
						return data;
	},				

	// can pass in standard $.ajax() parameters. Callback functions, such as beforeSend, 
	// will be queued first within the default callbacks. 
	// The only exception is error, which overrides the default
	ajaxSettings: {
					  // error: function(ct, ci) { /* override default error callback */ }
					  // beforeSend: function(ct, ci) { /* called first within default beforeSend callback }
					  dataType: 'html'
	},
	debug: false
  };


/*
 * Global defaults for clueTips. Apply to all calls to the clueTip plugin.
 *
 * @example $.cluetip.setup({
 *   insertionType: 'prependTo',
 *   insertionElement: '#container'
 * });
 * 
 * @property
 * @name $.cluetip.setup
 * @type Map
 * @cat Plugins/tooltip
 * @option String insertionType: Default is 'appendTo'. Determines the method to be used for inserting the clueTip into the DOM. Permitted values are 'appendTo', 'prependTo', 'insertBefore', and 'insertAfter'
 * @option String insertionElement: Default is 'body'. Determines which element in the DOM the plugin will reference when inserting the clueTip.
 *
 */
   
  var insertionType = 'appendTo', insertionElement = 'body';

  $.cluetip.setup = function(options) {
	if (options && options.insertionType && (options.insertionType).match(/appendTo|prependTo|insertBefore|insertAfter/)) {
	  insertionType = options.insertionType;
	}
	if (options && options.insertionElement) {
	  insertionElement = options.insertionElement;
	}
  };
  
})(jQuery);













/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *	   used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *							 If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *							 If set to null or omitted, the cookie will be a session cookie and will not be retained
 *							 when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *						require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '; path=/';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};










/**
 * .disableTextSelect - Disable Text Select Plugin
 *
 * Version: 1.0
 * Updated: 2007-08-11
 *
 * Used to stop users from selecting text
 *
 * Copyright (c) 2007 James Dempster (letssurf@gmail.com, http://www.jdempster.com/category/jquery/disabletextselect/)
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 **/

/**
 * Requirements:
 * - jQuery (John Resig, http://www.jquery.com/)
 **/
(function($) {
	if ($.browser.mozilla) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).css({
					'MozUserSelect' : 'none'
				});
			});
		};
	} else if ($.browser.msie) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).bind('selectstart', function() {
					return false;
				});
			});
		};
	} else {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).mousedown(function() {
					return false;
				});
			});
		};
	}
})(jQuery);







/*
 * jquery.geekga.js - jQuery plugin for Google Analytics
 *
 * This plugin extends jQuery with two new functions:
 *
 *   - $().geekGaTrackPage(account_id)
 *	   Track a pageview.
 *
 *   - $().geekGaTrackEvent(category, action, label, value)
 *	   Track an event with a category, action, label and value.
 *
 *
 * This code is in the public domain.
 *
 * Willem van Zyl
 * willem@geekology.co.za
 * http://www.geekology.co.za/blog/
 */

;(function($) {

  var pageTracker;

  /**
   * Track a pageview, e.g.:
   *
   *   $().geekGaTrackPage('UA-0000000-0');
   */
  $.fn.geekGaTrackPage = function(account_id) {

	//check whether to use an unsecured or a ssl connection:
	var host = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	var src = host + 'google-analytics.com/ga.js';

	//load the Google Analytics javascript file:
	$.getScript(src, function() {
	  if (typeof _gat != undefined) {
		//the ga.js file was loaded successfully, set the account id:
		pageTracker = _gat._getTracker(account_id);

		//track the pageview:
		pageTracker._trackPageview();
	  }
	  else {
		//the ga.js file wasn't loaded successfully:
		throw "Unable to load ga.js; _gat has not been defined.";
	  }
	});

  };

  /**
   * Track an event, e.g.:
   *
   *   $('a.twitter').click(function() {
   *	 $().geekGaTrackEvent('feed', 'click', 'Twitter', 'willemvzyl');
   *   });
   */
  $.fn.geekGaTrackEvent = function(category, action, label, value) {

	if (typeof pageTracker != undefined) {
	  //the pageTracker was defined, track the event:
	  pageTracker._trackEvent(category, action, label, value);
	} else {
	  //the pageTracker wasn't defined:
	  throw "Unable to track event; pageTracker has not been defined";
	}

  };

})(jQuery);








/**
 *  jQuery combobox youhouuuu
 */
jQuery.fn.comboBox = function(options){


	var options = jQuery.extend({
	  autocomplete:false,
	  width:300,
	  widthWrapper:false,
	  maxHeight:100,
	  emptyText:'- Tout -',
	  icon:false,
	  iconWidth:16,
	  iconHeight:16,
	  iconBlank:'/img/blank.gif'
	},options);

	var timer;
	var list = this;

	if ( list.length ) {
		var container = list.parent();

		var table = jQuery('<table class="comboBox"><tr><td></td><td></td></tr></table>');
		table.css('width', options.width);
		var td_first = table.find('td:first');
		var td_last = table.find('td:last');
		td_last.css('width', 17);
		var select = jQuery('<div class="comboBoxWrapper"><ul></ul></div>');
		if (options.widthWrapper) {
			select.css('width', options.widthWrapper - 2).disableTextSelect();
		} else {
			select.css('width', options.width - 2).disableTextSelect();
		}

		var select_ul = select.find('ul:first');
		if (options.autocomplete) {
			list.prepend('<option value="">'+options.emptyText+'</option>');
		}
		list.children('option').each(function(index, item) {
			var icon = '';
			if (options.icon) {
				var tmpIcon = $(item).attr('icon') || options.iconBlank;
				icon = '<img src="'+tmpIcon+'" alt="" width="'+options.iconWidth+'" height="'+options.iconHeight+'" />&nbsp;';
			}
			select_ul.append('<li val="'+$(item).attr('value')+'">'+icon+$(item).text()+'</li>');
		});

		var rows = select_ul.children('li'), cache = rows.map(function(){
			return format_remove_accents($(this).text().toLowerCase());
		});

		container.append(table);
		container.append(select);
		td_first.html(list);
		list.hide();
		select.hide();

		var iconField = {};
		if (options.icon) {
			iconField = jQuery('<img src="'+options.iconBlank+'" alt="" class="comboBoxIcon" width="'+options.iconWidth+'" height="'+options.iconHeight+'" />');
		}
		var field = {};
		var fieldText = {};
		if (options.autocomplete) {
			var fieldWidth = options.width - 25;
			if (options.icon) {
				td_first.append(iconField);
				fieldWidth -= (options.iconWidth + 2);
			}
			field = jQuery('<input type="text" value="" class="comboBoxField" />');
			field.css('width', fieldWidth).click(function(){
				wrapperToggle();
			});
			fieldText = field;
		} else {
			field = jQuery('<div class="comboBoxField"><span>&nbsp;</span></div>');
			if (options.icon) {
				field.prepend(iconField);
			}
			field.css('width', options.width - 25).click(function(){
				wrapperToggle();
			}).disableTextSelect();
			fieldText = field.find('span:first');
		}
		td_first.append(field);

		var arrow = jQuery('<a class="comboBoxArrow">&nbsp;</a>');
		arrow.click(function(){
			wrapperToggle();
		}).hover(function(){
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
		td_last.append(arrow);

		rows.hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		}).click(function(){
			if (options.autocomplete) {
				fieldText.val($(this).text()).change();
			} else {
				fieldText.html($(this).text());
				if (options.icon) {
					var icon = $(this).find('img');
					if (icon) {
						iconField.attr('src', icon.attr('src'));
					} else {
						iconField.attr('src', options.iconBlank);
					}
				}
			}
			list.val($(this).attr('val')).change();
			wrapperClose();
		});

		if (options.autocomplete) {
			field.click(function(){
				if (fieldText.val() == options.emptyText) {
					fieldText.val('').keyup();
				}
			});
			var first = list.children('option:first');
			first.attr('selected', 'selected');
			fieldText.val(first.text());
		}

		if (list.val()) {
			var text = list.find('option:selected').text();
			if (options.autocomplete) {
				fieldText.val(text);
			} else {
				fieldText.html(text);
			}
		}
		
		select.mouseout(function() {
			timer = setTimeout(function() {
				wrapperClose();
			}, 200);
		}).mouseover(function() {
			clearTimeout(timer);
		});

		list.change(updSel);
		updSel();

		if (options.autocomplete) {
			fieldText.keyup(filter);//.keyup();
			wrapperClose();
		}

	}

	list.comboBox.updateSelection = function(){
		updSel();
	}

	return this;

	function updSel(){
		var selected = list.find('option:selected');
		if (options.autocomplete) {
			fieldText.val(selected.text());
		} else {
			fieldText.html(selected.text());
		}
		if (options.icon) {
			iconField.attr('src', selected.attr('icon') || options.iconBlank);
		}
	}

	function wrapperOpen() {
		select.show();
		arrow.addClass('opened');
	}

	function wrapperClose() {
		select.hide();
		arrow.removeClass('opened');
	}

	function wrapperToggle() {
		if (select.css('display') == 'none') {
			wrapperOpen();
		} else {
			wrapperClose();
		}
	}

	function filter(){
		var term = jQuery.trim( fieldText.val().toLowerCase() ), scores = [];

		if ( !term ) {
			rows.show();
			select.hide();
		} else {
			rows.hide();
			select.show();

			term = format_remove_accents(term);
			cache.each(function(i){
				var score = this.score(term);
				if (score > 0) { scores.push([score, i]); }
			});

			jQuery.each(scores.sort(function(a, b){return b[0] - a[0];}), function(){
				jQuery(rows[ this[1] ]).show();
			});
			jQuery(rows[0]).show();
		}
	}
};




























/*
 * SimpleModal 1.2.2 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2008 Eric Martin
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 181 2008-12-16 16:51:44Z emartin24 $
 */

/**
 * SimpleModal is a lightweight jQuery plugin that provides a simple
 * interface to create a modal dialog.
 *
 * The goal of SimpleModal is to provide developers with a cross-browser
 * overlay and container that will be populated with data provided to
 * SimpleModal.
 *
 * There are two ways to call SimpleModal:
 * 1) As a chained function on a jQuery object, like $('#myDiv').modal();.
 * This call would place the DOM object, #myDiv, inside a modal dialog.
 * Chaining requires a jQuery object. An optional options object can be
 * passed as a parameter.
 *
 * @example $('<div>my data</div>').modal({options});
 * @example $('#myDiv').modal({options});
 * @example jQueryObject.modal({options});
 *
 * 2) As a stand-alone function, like $.modal(data). The data parameter
 * is required and an optional options object can be passed as a second
 * parameter. This method provides more flexibility in the types of data
 * that are allowed. The data could be a DOM object, a jQuery object, HTML
 * or a string.
 *
 * @example $.modal('<div>my data</div>', {options});
 * @example $.modal('my data', {options});
 * @example $.modal($('#myDiv'), {options});
 * @example $.modal(jQueryObject, {options});
 * @example $.modal(document.getElementById('myDiv'), {options});
 *
 * A SimpleModal call can contain multiple elements, but only one modal
 * dialog can be created at a time. Which means that all of the matched
 * elements will be displayed within the modal container.
 *
 * SimpleModal internally sets the CSS needed to display the modal dialog
 * properly in all browsers, yet provides the developer with the flexibility
 * to easily control the look and feel. The styling for SimpleModal can be
 * done through external stylesheets, or through SimpleModal, using the
 * overlayCss and/or containerCss options.
 *
 * SimpleModal has been tested in the following browsers:
 * - IE 6, 7
 * - Firefox 2, 3
 * - Opera 9
 * - Safari 3
 *
 * @name SimpleModal
 * @type jQuery
 * @requires jQuery v1.2.2
 * @cat Plugins/Windows and Overlays
 * @author Eric Martin (http://ericmmartin.com)
 * @version 1.2.2
 */
(function ($) {
	var ie6 = $.browser.msie && parseInt($.browser.version) == 6 && !window['XMLHttpRequest'],
		ieQuirks = $.browser.msie && !$.boxModel,
		w = [];

	/*
	 * Stand-alone function to create a modal dialog.
	 *
	 * @param {string, object} data A string, jQuery object or DOM object
	 * @param {object} [options] An optional object containing options overrides
	 */
	$.modal = function (data, options) {
		return $.modal.impl.init(data, options);
	};

	/*
	 * Stand-alone close function to close the modal dialog
	 */
	$.modal.close = function () {
		$.modal.impl.close();
	};

	/*
	 * Chained function to create a modal dialog.
	 *
	 * @param {object} [options] An optional object containing options overrides
	 */
	$.fn.modal = function (options) {
		return $.modal.impl.init(this, options);
	};

	/*
	 * SimpleModal default options
	 *
	 * opacity: (Number:50) The opacity value for the overlay div, from 0 - 100
	 * overlayId: (String:'simplemodal-overlay') The DOM element id for the overlay div
	 * overlayCss: (Object:{}) The CSS styling for the overlay div
	 * containerId: (String:'simplemodal-container') The DOM element id for the container div
	 * containerCss: (Object:{}) The CSS styling for the container div
	 * dataCss: (Object:{}) The CSS styling for the data div
	 * zIndex: (Number: 1000) Starting z-index value
	 * close: (Boolean:true) Show closeHTML?
	 * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the
				  default close link. SimpleModal will automatically add the closeClass to this element.
	 * closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
	 * position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
	 * persist: (Boolean:false) Persist the data across modal calls? Only used for existing
				DOM elements. If true, the data will be maintained across modal calls, if false,
				   the data will be reverted to its original state.
	 * onOpen: (Function:null) The callback function used in place of SimpleModal's open
	 * onShow: (Function:null) The callback function used after the modal dialog has opened
	 * onClose: (Function:null) The callback function used in place of SimpleModal's close
	 */
	$.modal.defaults = {
		opacity: 50,
		overlayId: 'modalBoxOverlay',
		overlayCss: {},
		containerId: 'modalBox',
		containerCss: {},
		dataCss: {},
		zIndex: 3000,
		close: false,
		closeHTML: '<a class="modalCloseImg" title="Close"></a>',
		closeClass: 'simplemodal-close',
		position: null,
		persist: false,
		onOpen: null,
		onShow: null,
		onClose: null
	};

	/*
	 * Main modal object
	 */
	$.modal.impl = {
		/*
		 * Modal dialog options
		 */
		opts: null,
		/*
		 * Contains the modal dialog elements and is the object passed
		 * back to the callback (onOpen, onShow, onClose) functions
		 */
		dialog: {},
		/*
		 * Initialize the modal dialog
		 */
		init: function (data, options) {
			// don't allow multiple calls
			if (this.dialog.data) {
				return false;
			}

			// merge defaults and user options
			this.opts = $.extend({}, $.modal.defaults, options);

			// keep track of z-index
			this.zIndex = this.opts.zIndex;

			// set the onClose callback flag
			this.occb = false;

			// determine how to handle the data based on its type
			if (typeof data == 'object') {
				// convert DOM object to a jQuery object
				data = data instanceof jQuery ? data : $(data);

				// if the object came from the DOM, keep track of its parent
				if (data.parent().parent().size() > 0) {
					this.dialog.parentNode = data.parent();

					// persist changes? if not, make a clone of the element
					if (!this.opts.persist) {
						this.dialog.orig = data.clone(true);
					}
				}
			}
			else if (typeof data == 'string' || typeof data == 'number') {
				// just insert the data as innerHTML
				data = $('<div/>').html(data);
			}
			else {
				// unsupported data type!
				alert('SimpleModal Error: Unsupported data type: ' + typeof data);
				return false;
			}
			this.dialog.data = data.addClass('simplemodal-data').css(this.opts.dataCss);
			data = null;

			// create the modal overlay, container and, if necessary, iframe
			this.create();

			// display the modal dialog
			this.open();

			// useful for adding events/manipulating data in the modal dialog
			if ($.isFunction(this.opts.onShow)) {
				this.opts.onShow.apply(this, [this.dialog]);
			}

			// don't break the chain =)
			return this;
		},
		/*
		 * Create and add the modal overlay and container to the page
		 */
		create: function () {
			// get the window properties
			w = this.getDimensions();

			// add an iframe to prevent select options from bleeding through
			if (ie6) {
				this.dialog.iframe = $('<iframe src="javascript:false;"/>')
					.css($.extend(this.opts.iframeCss, {
						display: 'none',
						opacity: 0,
						position: 'fixed',
						height: w[0],
						width: w[1],
						zIndex: this.opts.zIndex,
						top: 0,
						left: 0
					}))
					.appendTo('body');
			}

			// create the overlay
			this.dialog.overlay = $('<div/>')
				.attr('id', this.opts.overlayId)
				.addClass('simplemodal-overlay')
				.css($.extend(this.opts.overlayCss, {
					display: 'none',
					opacity: this.opts.opacity / 100,
					height: w[0],
					width: w[1],
					position: 'fixed',
					left: 0,
					top: 0,
					zIndex: this.opts.zIndex + 1
				}))
				.appendTo('body');

			// create the container
			this.dialog.container = $('<div/>')
				.attr('id', this.opts.containerId)
				.addClass('simplemodal-container')
				.css($.extend(this.opts.containerCss, {
					display: 'none',
					position: 'fixed',
					zIndex: this.opts.zIndex + 2
				}))
				.append('<div class="modalBoxTop"></div><div class="modalBoxContent"></div><div class="modalBoxBottom"></div>')
				.appendTo('body');
				/*.append(this.opts.close
					? $(this.opts.closeHTML).addClass(this.opts.closeClass)
					: '')*/

			var modalBoxBottom = this.dialog.container.children('.modalBoxBottom');
			if (!this.opts.buttons) {
				var btn = $('<button class="btn-Fermer">Fermer</button>').click(function(){ $.modal.close(); });
				modalBoxBottom.append(btn);
			} else {
				$.each(this.opts.buttons, function(i, item) {
					var btn = $('<button class="btn-'+i+'">'+i+'</button>');
					if ($.isFunction(item)) {
						btn.click(item);
					}
					modalBoxBottom.append(btn);
				});
			}

			this.setPosition();

			// fix issues with IE
			if (ie6 || ieQuirks) {
				this.fixIE();
			}

			// hide the data and add it to the container
			this.dialog.container.children('.modalBoxContent').append(this.dialog.data.hide());

		},
		/*
		 * Bind events
		 */
		bindEvents: function () {
			var self = this;

			// bind the close event to any element with the closeClass class
			$('.' + this.opts.closeClass).bind('click.simplemodal', function (e) {
				e.preventDefault();
				self.close();
			});

			// update window size
			$(window).bind('resize.simplemodal', function () {
				// redetermine the window width/height
				w = self.getDimensions();

				// reposition the dialog
				self.setPosition();

				if (ie6 || ieQuirks) {
					self.fixIE();
				}
				else {
					// update the iframe & overlay
					self.dialog.iframe && self.dialog.iframe.css({height: w[0], width: w[1]});
					self.dialog.overlay.css({height: w[0], width: w[1]});
				}
			});
		},
		/*
		 * Unbind events
		 */
		unbindEvents: function () {
			$('.' + this.opts.closeClass).unbind('click.simplemodal');
			$(window).unbind('resize.simplemodal');
		},
		/*
		 * Fix issues in IE6 and IE7 in quirks mode
		 */
		fixIE: function () {
			var p = this.opts.position;
			if ($.browser.msie && parseInt($.browser.version) == 8) return;
			  

			// simulate fixed position - adapted from BlockUI
			$.each([this.dialog.iframe || null, this.dialog.overlay, this.dialog.container], function (i, el) {
				if (el) {
					var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
						bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
						bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth',
						ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth',
						sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop',
						s = el[0].style;

					s.position = 'absolute';
					if (i < 2) {
						s.removeExpression('height');
						s.removeExpression('width');
						s.setExpression('height','' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"');
						s.setExpression('width','' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"');
					}
					else {
						var te, le;
						if (p && p.constructor == Array) {
							if (p[0]) {
								var top = typeof p[0] == 'number' ? p[0].toString() : p[0].replace(/px/, '');
								te = top.indexOf('%') == -1
									? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
									: parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
							}
							if (p[1]) {
								var left = typeof p[1] == 'number' ? p[1].toString() : p[1].replace(/px/, '');
								le = left.indexOf('%') == -1
									? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
									: parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
							}
						}
						else {
							te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
							le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
						}
						s.removeExpression('top');
						s.removeExpression('left');
						s.setExpression('top', te);
						s.setExpression('left', le);
					}
				}
			});
		},
		getDimensions: function () {
			var el = $(window);

			// fix a jQuery/Opera bug with determining the window height
			var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery <= '1.2.6' ?
				document.documentElement['clientHeight'] :
				el.height();

			return [h, el.width()];
		},
		setPosition: function () {
			var top, left,
				hCenter = (w[0]/2) - ((this.dialog.container.height() || this.dialog.data.height())/2),
				vCenter = (w[1]/2) - ((this.dialog.container.width() || this.dialog.data.width())/2);

			if (this.opts.position && this.opts.position.constructor == Array) {
				top = this.opts.position[0] || hCenter;
				left = this.opts.position[1] || vCenter;
			} else {
				top = hCenter;
				left = vCenter;
			}
			this.dialog.container.css({left: left, top: top});
		},
		/*
		 * Open the modal dialog elements
		 * - Note: If you use the onOpen callback, you must "show" the
		 *			overlay and container elements manually
		 *		 (the iframe will be handled by SimpleModal)
		 */
		open: function () {
			// display the iframe
			this.dialog.iframe && this.dialog.iframe.show();

			if ($.isFunction(this.opts.onOpen)) {
				// execute the onOpen callback
				this.opts.onOpen.apply(this, [this.dialog]);
			}
			else {
				// display the remaining elements
				this.dialog.overlay.show();
				this.dialog.container.show();
				this.dialog.data.show();
			}

			// bind default events
			this.bindEvents();
		},
		/*
		 * Close the modal dialog
		 * - Note: If you use an onClose callback, you must remove the
		 *		 overlay, container and iframe elements manually
		 *
		 * @param {boolean} external Indicates whether the call to this
		 *	 function was internal or external. If it was external, the
		 *	 onClose callback will be ignored
		 */
		close: function () {
			// prevent close when dialog does not exist
			if (!this.dialog.data) {
				return false;
			}

			if ($.isFunction(this.opts.onClose) && !this.occb) {
				// set the onClose callback flag
				this.occb = true;

				// execute the onClose callback
				this.opts.onClose.apply(this, [this.dialog]);
			}
			else {
				// if the data came from the DOM, put it back
				if (this.dialog.parentNode) {
					// save changes to the data?
					if (this.opts.persist) {
						// insert the (possibly) modified data back into the DOM
						this.dialog.data.hide().appendTo(this.dialog.parentNode);
					}
					else {
						// remove the current and insert the original,
						// unmodified data back into the DOM
						this.dialog.data.remove();
						this.dialog.orig.appendTo(this.dialog.parentNode);
					}
				}
				else {
					// otherwise, remove it
					this.dialog.data.remove();
				}

				// remove the remaining elements
				this.dialog.container.remove();
				this.dialog.overlay.remove();
				this.dialog.iframe && this.dialog.iframe.remove();

				// reset the dialog object
				this.dialog = {};
			}

			// remove the default events
			this.unbindEvents();
		}
	};
})(jQuery);


Lotro.nav.hide = function(entry) {
	if ((entry != Lotro.nav.cursor)||(entry=='')) {
		return;
	}
	$("#headerMiddle" + entry).hide();
	$('#headerNav'+entry).parent().removeClass('active');
};

Lotro.nav.show = function(entry) {
	Lotro.nav.hide(Lotro.nav.cursor);
	Lotro.nav.cursor = entry;
	$("#headerMiddle" + entry).show();
	var li = $("#headerNav" + entry).parent();
	if (li.hasClass("active")) {
		return;
	}
	li.addClass("active");
	Lotro.nav.onNav = true;
	Lotro.nav.onUl = false;
	li.mouseout(function(){
		Lotro.nav.onNav = false;
		window.setTimeout(function() {
			if (!Lotro.nav.onNav && !Lotro.nav.onUl) {
				Lotro.nav.reset();
			}
		},
		3000);
	}).mouseover(function(){
		Lotro.nav.onNav = true;
	});
	$("#headerMiddle").mouseout(function(){
		Lotro.nav.onUl = false;
		window.setTimeout(function() {
			if (!Lotro.nav.onNav && !Lotro.nav.onUl) {
				Lotro.nav.reset();
			}
		},
		3000);
	}).mouseover(function(){
		Lotro.nav.onUl = true;
	});
};

Lotro.nav.reset = function() {
	Lotro.nav.hide(Lotro.nav.cursor);
	Lotro.nav.cursor = Lotro.nav.current;
	Lotro.nav.show(Lotro.nav.cursor);
};

$(function(){
	$("#headerNav li a").mouseover(function(){
		var id = String($(this).attr('id')).replace(/headerNav/g, '');
		Lotro.nav.show(id);
	});
});




