/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Patched Version by Jamie Thompson - Fixes IE7 Positioning Issues
 * http://jamazon.co.uk/web/2008/03/17/thickbox-31-ie7-positioning-bug/
*/
		  
var tb_pathToImage = "loadingAnimation.gif";

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$.1g.1Y=$.1g.3q&&/2l 6\\.0/i.2t(1c.1q.1v)&&!/2l 7\\.0/i.2t(1c.1q.1v);$(p).2H(n(){1E(\'a.19, 3f.19, 3b.19\');1x=1r 1B();1x.M=2O});n 1E(b){$(b).u(n(){8 t=R.16||R.1I||P;8 a=R.A||R.2u;8 g=R.2q||V;1j(t,a,g);R.3c();L V}).3a(\'19\')}n 1j(d,f,g){35{3(1Z p.z.J.2i==="1X"){$("z","12").r({D:"1R%",v:"1R%"});$("12").r("1P","2I");3(p.1N("1y")===P){$("z").s("<T 5=\'1y\'></T><4 5=\'B\'></4><4 5=\'9\'></4>");$("#B").u(I)}}o{3(p.1N("B")===P){$("z").s("<4 5=\'B\'></4><4 5=\'9\'></4>");$("#B").u(I)}}3(2A()){$("#B").2y("3o")}o{$("#B").2y("3m")}3(d===P){d=""}$("z").s("<4 5=\'H\'><2s M=\'"+1x.M+"\' /></4>");$(\'#H\').3k();8 h;3(f.O("?")!==-1){h=f.3e(0,f.O("?"))}o{h=f}8 i=/\\.2j$|\\.2h$|\\.2g$|\\.2f$|\\.2c$/;8 j=h.1n().26(i);3(j==\'.2j\'||j==\'.2h\'||j==\'.2g\'||j==\'.2f\'||j==\'.2c\'){1u="";1p="";18="";1t="";1s="";U="";1C="";1w=V;3(g){F=$("a[@2q="+g+"]").2V();25(E=0;((E<F.1i)&&(U===""));E++){8 k=F[E].A.1n().26(i);3(!(F[E].A==f)){3(1w){1t=F[E].16;1s=F[E].A;U="<1h 5=\'1W\'>&1f;&1f;<a A=\'#\'>2N &2M;</a></1h>"}o{1u=F[E].16;1p=F[E].A;18="<1h 5=\'1T\'>&1f;&1f;<a A=\'#\'>&2L; 2K</a></1h>"}}o{1w=1b;1C="1B "+(E+1)+" 2J "+(F.1i)}}}Q=1r 1B();Q.1a=n(){Q.1a=P;8 a=1Q();8 x=a[0]-1O;8 y=a[1]-1O;8 b=Q.v;8 c=Q.D;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}o 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}14=b+30;1e=c+2G;$("#9").s("<2s 5=\'1L\' M=\'"+f+"\' v=\'"+b+"\' D=\'"+c+"\' 2u=\'"+d+"\'/>"+"<4 5=\'2F\'>"+d+"<4 5=\'2E\'>"+1C+18+U+"</4></4><4 5=\'2D\'><a A=\'#\' 5=\'S\' 16=\'2B\'>1K</a> 1J 1H 1G</4>");$("#S").u(I);3(!(18==="")){n 15(){3($(p).N("u",15)){$(p).N("u",15)}$("#9").C();$("z").s("<4 5=\'9\'></4>");1j(1u,1p,g);L V}$("#1T").u(15)}3(!(U==="")){n 1F(){$("#9").C();$("z").s("<4 5=\'9\'></4>");1j(1t,1s,g);L V}$("#1W").u(1F)}p.1k=n(e){3(e==P){K=2z.2x}o{K=e.2w}3(K==27){I()}o 3(K==3n){3(!(U=="")){p.1k="";1F()}}o 3(K==3l){3(!(18=="")){p.1k="";15()}}};13();$("#H").C();$("#1L").u(I);$("#9").r({Y:"W"})};Q.M=f}o{8 l=f.2r(/^[^\\?]+\\??/,\'\');8 m=2p(l);14=(m[\'v\']*1)+30||3j;1e=(m[\'D\']*1)+3i||3h;X=14-30;Z=1e-3g;3(f.O(\'2k\')!=-1){1A=f.1D(\'3d\');$("#11").C();3(m[\'1m\']!="1b"){$("#9").s("<4 5=\'1M\'><4 5=\'1l\'>"+d+"</4><4 5=\'2e\'><a A=\'#\' 5=\'S\' 16=\'2B\'>1K</a> 1J 1H 1G</4></4><T 2d=\'0\' 1S=\'0\' M=\'"+1A[0]+"\' 5=\'11\' 1I=\'11"+1d.2b(1d.1z()*2a)+"\' 1a=\'1o()\' J=\'v:"+(X+29)+"q;D:"+(Z+17)+"q;\' > </T>")}o{$("#B").N();$("#9").s("<T 2d=\'0\' 1S=\'0\' M=\'"+1A[0]+"\' 5=\'11\' 1I=\'11"+1d.2b(1d.1z()*2a)+"\' 1a=\'1o()\' J=\'v:"+(X+29)+"q;D:"+(Z+17)+"q;\'> </T>")}}o{3($("#9").r("Y")!="W"){3(m[\'1m\']!="1b"){$("#9").s("<4 5=\'1M\'><4 5=\'1l\'>"+d+"</4><4 5=\'2e\'><a A=\'#\' 5=\'S\'>1K</a> 1J 1H 1G</4></4><4 5=\'G\' J=\'v:"+X+"q;D:"+Z+"q\'></4>")}o{$("#B").N();$("#9").s("<4 5=\'G\' 39=\'38\' J=\'v:"+X+"q;D:"+Z+"q;\'></4>")}}o{$("#G")[0].J.v=X+"q";$("#G")[0].J.D=Z+"q";$("#G")[0].37=0;$("#1l").12(d)}}$("#S").u(I);3(f.O(\'36\')!=-1){$("#G").s($(\'#\'+m[\'23\']).22());$("#9").21(n(){$(\'#\'+m[\'23\']).s($("#G").22())});13();$("#H").C();$("#9").r({Y:"W"})}o 3(f.O(\'2k\')!=-1){13();3($.1g.34){$("#H").C();$("#9").r({Y:"W"})}}o{$("#G").33(f+="&1z="+(1r 32().31()),n(){13();$("#H").C();1E("#G a.19");$("#9").r({Y:"W"})})}}3(!m[\'1m\']){p.20=n(e){3(e==P){K=2z.2x}o{K=e.2w}3(K==27){I()}}}}2Z(e){}}n 1o(){$("#H").C();$("#9").r({Y:"W"})}n I(){$("#2Y").N("u");$("#S").N("u");$("#9").2X("2W",n(){$(\'#9,#B,#1y\').2U("21").N().C()});$("#H").C();3(1Z p.z.J.2i=="1X"){$("z","12").r({D:"28",v:"28"});$("12").r("1P","")}p.1k="";p.20="";L V}n 13(){$("#9").r({2T:\'-\'+24((14/2),10)+\'q\',v:14+\'q\'});3(!(2S.1g.1Y)){$("#9").r({2R:\'-\'+24((1e/2),10)+\'q\'})}}n 2p(a){8 b={};3(!a){L b}8 c=a.1D(/[;&]/);25(8 i=0;i<c.1i;i++){8 d=c[i].1D(\'=\');3(!d||d.1i!=2){2Q}8 e=2C(d[0]);8 f=2C(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}L b}n 1Q(){8 a=p.2P;8 w=1c.2n||2m.2n||(a&&a.1V)||p.z.1V;8 h=1c.2o||2m.2o||(a&&a.1U)||p.z.1U;2v=[w,h];L 2v}n 2A(){8 a=1q.1v.1n();3(a.O(\'3p\')!=-1&&a.O(\'3r\')!=-1){L 1b}}',62,214,'|||if|div|id|||var|TB_window||||||||||||||function|else|document|px|css|append||click|width||||body|href|TB_overlay|remove|height|TB_Counter|TB_TempArray|TB_ajaxContent|TB_load|tb_remove|style|keycode|return|src|unbind|indexOf|null|imgPreloader|this|TB_closeWindowButton|iframe|TB_NextHTML|false|block|ajaxContentW|display|ajaxContentH||TB_iframeContent|html|tb_position|TB_WIDTH|goPrev|title||TB_PrevHTML|thickbox|onload|true|window|Math|TB_HEIGHT|nbsp|browser|span|length|tb_show|onkeydown|TB_ajaxWindowTitle|modal|toLowerCase|tb_showIframe|TB_PrevURL|navigator|new|TB_NextURL|TB_NextCaption|TB_PrevCaption|userAgent|TB_FoundURL|imgLoader|TB_HideSelect|random|urlNoQuery|Image|TB_imageCount|split|tb_init|goNext|Key|Esc|name|ou|Fermer|TB_Image|TB_title|getElementById|150|overflow|tb_getPageSize|100|hspace|TB_prev|clientHeight|clientWidth|TB_next|undefined|msie6|typeof|onkeyup|unload|children|inlineId|parseInt|for|match||auto||1000|round|bmp|frameborder|TB_closeAjaxWindow|gif|png|jpeg|maxHeight|jpg|TB_iframe|MSIE|self|innerWidth|innerHeight|tb_parseQuery|rel|replace|img|test|alt|arrayPageSize|which|keyCode|addClass|event|tb_detectMacXFF|Close|unescape|TB_closeWindow|TB_secondLine|TB_caption|60|ready|hidden|of|Prev|lt|gt|Next|tb_pathToImage|documentElement|continue|marginTop|jQuery|marginLeft|trigger|get|fast|fadeOut|TB_imageOff|catch||getTime|Date|load|safari|try|TB_inline|scrollTop|TB_modal|class|removeClass|input|blur|TB_|substr|area|45|440|40|630|show|188|TB_overlayBG|190|TB_overlayMacFFBGHack|mac|msie|firefox'.split('|'),0,{})) 

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

// fixes the fact that ie7 now reports itself as MSIE 6.0 compatible
$.browser.msie6 = 
        $.browser.msie 
        && /MSIE 6\.0/i.test(window.navigator.userAgent) 
        && !/MSIE 7\.0/i.test(window.navigator.userAgent);

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	}).removeClass('thickbox');
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
			
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>Fermer</a></div>"); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_Image").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>Fermer</a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>Fermer</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	
	if ( !(jQuery.browser.msie6)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


