	var elem, opts, busy = false, imagePreloader = new Image, loadingTimer, loadingFrame = 1, imageRegExp = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$';
	var isIE6 = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7);
	var fileLoadingImage=        '/Files/Filer/MediaBox/loading.gif'; 
	var fileBottomNavCloseImage= '/Files/Filer/MediaBox/Luklabel.gif';
	var DivH = 440//294;  // max. H?he
	var DivW = 630//480;  // max. Breite
	var j=0;
	var flvplayer = '/Files/Filer/MediaBox/flvplayer.swf';
	
	jQuery.noConflict();	
	jQuery(document).ready(function(){
	jQuery(function()
	{
	  jQuery("div.MediaBox").prepend("<img src='"+fileLoadingImage+"' class='ldrgif' alt='loading...'/ >"); 
	  jQuery("div.MediaBox").MediaBoxDIVslideView();
		tb_initRefs('a.MediaBox, area.MediaBox, input.MediaBox, span.MediaBox');
		tb_intMovies('a');
		
		//imgLoader = new Image();// preload image
		//imgLoader.src = fileLoadingImage;
	})
});
	
	
	function tb_intMovies(domChunk)
	{
		jQuery(domChunk).click(function(){
			var t = this.title || this.name || '';
			var a = this.href || this.alt || null;
			var g = this.rel || false;
			var cla = (jQuery(this).hasClass("MediaBox")) ? true : false;
			
			if(a.indexOf("?")!==-1){ //If there is a query string involved
				var baseURL = a.substr(0, a.indexOf("?"));
			}else{ 
				var baseURL = a;
			}
		  var checkURL = baseURL.toLowerCase();
		  if((a) && (cla == false) && ( /\.(wmv|flv|mov|swf|avi)$/.test(checkURL) )  )
			{
				tb_showRefs(t,a,g);
				this.blur();
				return false;
			}
		});
	}
	
	function tb_initRefs(domChunk)
	{
		//var pictElsaa = TB_TempArray =jQuery('a[class="MediaBox"]');
		var pictElsaa = TB_TempArray =jQuery('a.MediaBox, area.MediaBox, input.MediaBox, span.MediaBox');//jQuery("a.MediaBox").size();
	  for (TB_Counter = 0;TB_Counter < pictElsaa.length; TB_Counter++) 
		{
			if(pictElsaa[TB_Counter].href)
			{
				var url = pictElsaa[TB_Counter].href.toLowerCase();
				if (url.match(/#/)) 
				{
					var container = url.substring(url.indexOf('#')+1);
					if(jQuery(container))
					{
						jQuery("#"+container).css("display","none");
						//jQuery(container).css("visibility" , "hidden");
					}
				}
			}
		}
		jQuery(domChunk).click(function(){
		var t = this.title || this.name || '';
		var a = this.href || this.alt || null;
		var g = this.rel || false;
		if(a)
		{
			tb_showRefs(t,a,g);
			this.blur();
		}
		return false;
		});
	}	
	
	//var quantofamo = 0;
	jQuery.fn.MediaBoxDIVslideView = function(settings)
	{
		  settings = jQuery.extend({
	     easeFunc: "easeInBack",
	     easeTime: 750,
	     toolTip: false
	  }, settings);
	  
		return this.each(function(){
			var container = jQuery(this);
			container.find("img.ldrgif").remove(); // removes the preloader gif
			container.removeClass("MediaBox").addClass("MediaBoxSlidestripViewer");
			var moreTextValue = this.moreText || null;
			var popup = this.popup || null;
			
			var popupValue = (popup) ? true :false;
			
			var pictWidth = container.find("img").width();
			var pictHeight = container.find("img").height();
			var pictEls = container.find("li").size();
			var MediaBoxSlidestripViewerWidth = pictWidth*pictEls;
			container.find("ul").css("width" , MediaBoxSlidestripViewerWidth); //assegnamo la larghezza alla lista UL	
			container.css("width" , pictWidth);
			container.css("height" , pictHeight);
			var currentIndex = 0;
			
			container.each(function(i)
			{
				jQuery(this).before("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");
				if((moreTextValue) &&(moreTextValue!="")){
					jQuery("div#stripTransmitter" + j + " ul").append("<li class='moreText'>"+moreTextValue+"</li>");//Flere billeder&nbsp;&nbsp;
				}
				jQuery(this).find("li").each(function(n){
					jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");
				});

				jQuery("div#stripTransmitter" + j + " a").each(function(z) {
					jQuery(this).bind("click", function(){
					jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
					currentIndex = z;
					var cnt = -(pictWidth*z);
					container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
					return false;
					   });
					});
					
					
					//the flere billeder text
				jQuery("div#stripTransmitter" + j + " li.moreText").each(function(z)
				{
					var g = jQuery(this).click(function(){
						//var ui5 	= 	jQuery(this).parent().parent().parent().find("a");
						var ui1 	= 	jQuery(this).parent().find("a");
						currentIndex +=1; 
						currentIndex = (currentIndex >= pictEls) ? 0 : currentIndex;
						ui1.eq(currentIndex).trigger("click");							
						return false;
					  });
				});					

				// next image via image click	14/01/2009
				//if(settings.popup == false)
				if(popupValue == false)
				{
					jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().next().find("img").each(function(z){
						var g = jQuery(this).click(function()
						{
							var ui5 	= 	jQuery(this).parent().parent().parent().parent().parent().find("a");
							currentIndex +=1; 
							currentIndex = (currentIndex >= pictEls) ? 0 : currentIndex;
							ui5.eq(currentIndex).trigger("click");							
							return false;							
						   });
						});
				}else
				{
					jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().next().find("img").each(function(z) {
	            var g = jQuery(this).click(function(){
						  var url = this.src;
					     if(url.indexOf("?")!==-1){ //If there is a query string involved
					      var baseURL = url.substr(0, url.indexOf("?"));
					     }else{ 
					      var baseURL = url;
					     }
						  var checkURL = baseURL.toLowerCase();
						  if( /\.(jpg|jpeg|png|gif|bmp|htm|php|xml|html|css|txt|pdf|wmv|flv|mov|swf|avi)$/.test(checkURL) ) {
						  var t = this.title || this.alt || this.name || null;
						  var g = this.rel || false;
						  thobjid = container.attr('id');
						  TB_showDIVLI(thobjid,t,checkURL,url);
						  this.blur();
						  return false;
						  }
						  });
					});
				}
				
				
				jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
				jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
	
				if(pictEls <= 1)
				{jQuery("div#stripTransmitter" +j).remove();}
				
				if(settings.toolTip)
				{
					container.next(".stripTransmitter ul").find("a").Tooltip({
					track: true,
					delay: 0,
					showURL: false,
					showBody: false
					});
				}
				});
				currentIndex;
				
			j++;
	  });	
	};

	
	
	function tb_showRefs(caption, url, imageGroup)
	{//function called when the user clicks on a thickbox link
		try 
		{
			if (typeof document.body.style.maxHeight === "undefined")
			{//if IE 6
				jQuery("body","html").css({height: "100%", width: "100%"});
				jQuery("html").css("overflow","hidden");
				if (document.getElementById("TBhideSelect") === null)
				{//iframe to hide select elements in ie6
					jQuery("body").append("<iframe id='TBhideSelect'></iframe><div id='TBoverlay'></div><div id='TBwindow'></div>");
					jQuery("#TBoverlay").click(TB_remove);
				}
			}else
			{//all others
				if(document.getElementById("TBoverlay") === null)
				{
					jQuery("body").append("<div id='TBoverlay'></div><div id='TBwindow'></div>");
					jQuery("#TBoverlay").click(TB_remove);
				}
			}
			if(!isIE6)
			{
				jQuery("#TBoverlay").addClass("TBoverlayMacFFBGHack");//use png overlay so hide flash	
			}
			if(caption==null)
			{
				caption="";
			}
			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);
  		var checkURL = baseURL.toLowerCase();			
	    
	    
	    if(caption==null){caption=""};
	    jQuery(window).scroll(TB_position);
	    TBoverlaySize();
	    TBload_position();

      TBprevCaption = "";
      TBprevURL = "";
      TBprevHTML = "";
      TBnextCaption = "";
      TBnextURL = "";
      TBnextHTML = "";
      TBimageCount = "";
      TB_FoundURL = false;
			if( /\.(jpg|jpeg|png|gif|bmp)$/.test(checkURL))
			{
		    TBload_position();
	      TBprevCaption = "";
	      TBprevURL = "";
	      TBprevHTML = "";
	      TBnextCaption = "";
	      TBnextURL = "";
	      TBnextPARAM = "";
	      TBprevPARAM = "";
	      TBnextHTML = "";
	      TBimageCount = "";
	      TB_FoundURL = false;

				if(imageGroup)
				{
					TB_TempArray =jQuery('a[rel="'+imageGroup+'"]');
		      for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TBnextHTML == "")); TB_Counter++) 
					{
						if(TB_TempArray[TB_Counter].href)
						{
							if(TB_TempArray[TB_Counter].href)
							{
				        var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase();
				        if (!(TB_TempArray[TB_Counter].href == url)) 
								{
				          if (TB_FoundURL) {
				          	TBnextPARAM = TB_TempArray[TB_Counter].param || '';
				            TBnextCaption = TB_TempArray[TB_Counter].alt;
				            TBnextURL = TB_TempArray[TB_Counter].href;
				            TBnextHTML = "\n<span id='TBnext'>\n<a href='#'>Next <small>(</small>&#8594;<small>)</small></a></span>";
				          } else {
				          	TBprevPARAM = TB_TempArray[TB_Counter].param || '';
				            TBprevCaption = TB_TempArray[TB_Counter].alt;
				            TBprevURL = TB_TempArray[TB_Counter].href;
				            TBprevHTML = "\n<span id='TBprev'>\n<a href='#'><small>(</small>&#8592;<small>)</small> Prev</a></span>";
				          }
				        } else {
				          TB_FoundURL = true;
				     			if(TB_TempArray.length > 1)
									{
										TBimageCount = "Billede " + (TB_Counter + 1) +" af "+ (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;
		 			var html = '';
			    // Code inserts html at the bottom of the page that looks similar to this:
			    //
			    html += '          <div id="outerImageContainer">';
			    html += '              <div id="imageContainer">';
			    html += '                  <img id="lightboxImage" src="'+url+'" width="'+imageWidth+'" height="'+imageHeight+'" alt="'+caption+'">';
			    html += '                  <div style="" id="hoverNav">';
			    if (!(TBprevHTML == ""))
					{
			    	html += '                      <a href="#" id="prevLink"></a>';
			    }
			    if (!(TBnextHTML == ""))
					{
			    	html += '                      <a href="#" id="nextLink"></a>';
					} 
			    html += '                  </div>';
			    html += '                  <div id="loading">';
			    html += '                      <a href="#" id="loadingLink">';
			    html += '                          <img src="'+fileLoadingImage+'">';
			    html += '                      </a>';
			    html += '                  </div>';
			    html += '              </div>';
			    html += '          </div>';
			    html += '          <div id="imageDataContainer">';
			    html += '              <div id="imageData">';
			    html += '                  <div id="imageDetails">';
			    html += '                      <span id="caption">'+caption+'</span>';
			    html += '                      <span id="numberDisplay">'+ TBimageCount +'</span>';
			    html += '                  </div>';
			    html += '                  <div id="bottomNav">';
			    html += '                      <a href="#" id="bottomNavClose">';
			    html += '                          <img src="'+fileBottomNavCloseImage+'">';
			    html += '                      </a>';
			    html += '                  </div>';
			    html += '              </div>';
			    html += '          </div>';
			    
					//jQuery("#TBwindow").fadeIn("slow").append(html);
					jQuery("#TBwindow").fadeIn("slow").append(html);
			    jQuery("#bottomNavClose").click(TB_remove);
			    jQuery("#outerImageContainer").css("height",TB_HEIGHT);
			    
		      if (!(TBprevHTML == "")) 
					{
		        function goPrev()
						{
							if(jQuery(document).unbind("click",goPrev))
							{
								jQuery(document).unbind("click",goPrev);
							}
							jQuery("#TBwindow").remove();
							jQuery("body").append("<div id='TBwindow'></div>");
		          tb_showRefs(TBprevCaption, TBprevURL, imageGroup);
		          return false;
		        }
		        jQuery("#prevLink").click(goPrev);
		        jQuery("#TBprev").click(goPrev); 
		      }
		      if (!(TBnextHTML == ""))
					{
		        function goNext()
						{
							jQuery("#TBwindow").remove();
							jQuery("body").append("\n<div id='TBwindow'>\n</div>");
							tb_showRefs(TBnextCaption, TBnextURL, imageGroup);		
							return false;	
		        }
		        jQuery("#nextLink").click(goNext);
		        jQuery("#TBnext").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 == 39){ // display previous image
		          if(!(TBnextHTML == "")){
		          document.onkeydown = "";
		          goNext();
		          }
		        } else if(keycode == 37){ // display next image
		          if(!(TBprevHTML == "")){
		          document.onkeydown = "";
		          goPrev();
		          }
		        }  
		      }
		      TB_position();
		      jQuery("#loadingLink").remove();
		      jQuery("#loading").remove();
		      
		      jQuery("#bottomNav").click(TB_remove);
		      jQuery("#bottomNavClose").click(TB_remove);
		      jQuery("#TBwindow").css({display:"block"}); //for safari using css instead of show
	      };
	      imgPreloader.src = url;			
			}else
			{
				CallFunctionNoNext(caption, url);
			}

	// Ende Bilder
	  } catch(e) {
	    alert( e );
	  }
	}

	function CallFunctionNoNext(caption, url)
	{
	  try {		
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );	
	    TBload_position();

			//	//640x360 wide screen
			//	var DivH = 440//294;  // max. H?he
			//var DivW = 630//480;  // max. Breite
			var DivWNew = 320;//480//630//158;
			var DivHNew = 240;// 294//440//147;

			lastpos=url.length;
			extImg = '';
			lastDotPost =-1;
		
			if (url.lastIndexOf('/') !=-1)
			{
				lastDotPost=url.lastIndexOf('/')+1;
				thefilename =url.substring(lastDotPost,lastpos);

				DivWNew = 650;//650;		
				DivHNew = 386;//366;
					
				if (thefilename.indexOf('43_') !=-1)
				{
					DivWNew = 478;//480//480//352//352//478 //478   //478;						
					//DivHNew = 363;//459//551//230//276//343 //305 //366;
				}
			}
			ajaxContentW = (params['width'])|| DivWNew; //defaults to 630 if no paramaters were added to URL
			ajaxContentH = (params['height'])|| DivHNew; //defaults to 440 if no paramaters were added to URL
//	     TB_WIDTH = parseInt(ajaxContentW) + 30;
//	     TB_HEIGHT = parseInt(ajaxContentH) + 60;

	     TB_WIDTH = parseInt(ajaxContentW);
	     TB_HEIGHT = parseInt(ajaxContentH);
				
				var baseURL = url;//.substr(0, url.indexOf("?"));
				var checkURL = baseURL.toLowerCase();

	 			var html = '';
		    // Code inserts html at the bottom of the page that looks similar to this:
		    //
		    html += '          <div id="outerImageContainer">';
		    html += '              <div id="imageContainer">';
		    html += '              </div>';
		    html += '          </div>';
		    
		    html += '          <div id="imageDataContainer">';
		    html += '              <div id="imageData">';
		    html += '                  <div id="bottomNav">';
		    html += '                      <a href="#" id="bottomNavClose">';
		    html += '                          <img src="'+fileBottomNavCloseImage+'">';
		    html += '                      </a>';
		    html += '                  </div>';
		    html += '              </div>';
		    html += '          </div>';
		    
				jQuery("#TBwindow").fadeIn("slow").append(html);
				if( /\.(wmv|flv|avi|swf)$/.test(checkURL) ) 
				{
					if( /\.(flv|swf)$/.test(checkURL) )
					{
						//jQuery("#TBwindow").css("height",ajaxContentH);
						//jQuery("#TBwindow").css("width",ajaxContentW);

						if(jQuery.browser.msie) 
						{
							jQuery("#TBwindow").css("height",DivHNew+40);
							jQuery("#TBwindow").css("width",DivWNew+20);							
	    				thecontent = "<div style='width:"+ajaxContentW+";height:"+ajaxContentH+";overflow:hidden;'><OBJECT id='wmv' style='VISIBILITY: visible;' width='"+DivWNew+"' height='"+DivHNew+"'  classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'><PARAM value='always' name='allowscriptaccess' /><PARAM value='true' name='allowfullscreen' /><PARAM value='file="+url+"&autostart=true' name='flashvars' /><PARAM value='"+flvplayer+"' name='movie' /></OBJECT></div>";	
							jQuery("#imageContainer").append(thecontent);
							//&backcolor=00416f&frontcolor=ffffff&lightcolor=000000&screencolor=000000&autostart=true&bufferlength=20
							
						}else
						{
							var sl = new SWFObject(flvplayer, "wmv", DivWNew, DivHNew, "0");
							sl.addParam('allowfullscreen','true');
							sl.addParam('allowscriptaccess','always');
							sl.addParam('wmode','opaque');
							sl.addParam('flashvars','file='+url+'&autostart=true');
							sl.write('imageContainer');
						}
						if(!jQuery.browser.msie) 
						{
							jQuery("#imageContainer").css({overflow:"hidden"});
						}
						jQuery("#imageContainer").css("padding",0);
						jQuery("#wmv").css("padding",0);
						jQuery("#wmv").css("margin",0);
						
					}
					else if( /\.(wmv|avi)$/.test(checkURL) )
					{
						if(jQuery.browser.msie) 
						{
							jQuery("#TBwindow").css("height",ajaxContentH+40);
							jQuery("#TBwindow").css("width",ajaxContentW+20);
			//			jQuery("#imageData").css("width","100%");				
	    				thecontent = "<object type='video/x-ms-wmv' width='"+ajaxContentW+"' height='"+ajaxContentH+"' data='"+url+"' ><param name='src' value='"+url+"' /><param name='autostart' value='true' width='"+ajaxContentW+"' height='"+ajaxContentH+"' /><param name='showcontrols' value='true' /><param name='stretchtofit' value='false' /><param name='controller' value='true' /></object>";	
							jQuery("#imageContainer").append(thecontent);
						} else 
						{
							jQuery("#TBwindow").css("height",ajaxContentH+40);
							jQuery("#TBwindow").css("width",ajaxContentW+20);						
							
							ajaxContentH = ajaxContentH + 1;
							thecontent = "<object style='margin-top:-1px' NAME='wmv' id='wmv' type='video/x-ms-wmv' width='"+ajaxContentW+"' height='"+ajaxContentH+"' data='"+url+"' ><param name='src' value='"+url+"' /><param name='autostart' value='true' /><param name='showcontrols' value='true' /><param name='stretchtofit' value='false' /><param name='controller' value='true' /></object>";
							
							jQuery("#imageContainer").css({overflow:"hidden"}).append(thecontent);
						}						
					} 
				}
				else if(url.indexOf('#') != -1)
				{
					var container = url.substring(url.indexOf('#')+1);
					thecontent = jQuery("#"+container).html();
					jQuery("#imageContainer").append("<div id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' style='width:"+(ajaxContentW)+"px;height:"+(ajaxContentH)+"px;overflow:auto;'>"+thecontent+"</div>");	
				}									
				else
				{
					jQuery("#imageContainer").append("<iframe frameborder='0' hspace='0' src='"+url+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='TB_showIframe()' style='width:"+(ajaxContentW )+"px;height:"+(ajaxContentH)+"px;background:#FFFFFF;'></iframe>");
				}				
		    jQuery("#bottomNavClose").click(TB_remove);
		    jQuery("#outerImageContainer").css("height",TB_HEIGHT);

      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 == 39){ // display previous image
          if(!(TBnextHTML == "")){
          document.onkeydown = "";
          goNext();
          }
        } else if(keycode == 37){ // display next image
          if(!(TBprevHTML == "")){
          document.onkeydown = "";
          goPrev();
          }
        }  
      }
      TB_position();
      jQuery("#loadingLink").remove();
      jQuery("#loading").remove();
      
      jQuery("#bottomNav").click(TB_remove);
      jQuery("#bottomNavClose").click(TB_remove);
      jQuery("#TBwindow").css({display:"block"}); //for safari using css instead of show
	  	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) {
	    alert( e );
	  }		
	}


	//HANDLES THE DIV LI REFS
	function TB_showDIVLI(objClass, caption,  checkURL, url)
	{//function called when the user clicks on a thickbox link
	  try {
			if (typeof document.body.style.maxHeight === "undefined")
			{//if IE 6
				jQuery("body","html").css({height: "100%", width: "100%"});
				jQuery("html").css("overflow","hidden");
				if (document.getElementById("TBhideSelect") === null)
				{//iframe to hide select elements in ie6
					jQuery("body").append("<iframe id='TBhideSelect'></iframe><div id='TBoverlay'></div><div id='TBwindow'></div>");
					jQuery("#TBoverlay").click(TB_remove);
				}
			}else
			{//all others
				if(document.getElementById("TBoverlay") === null)
				{
					jQuery("body").append("<div id='TBoverlay'></div><div id='TBwindow'></div>");
					jQuery("#TBoverlay").click(TB_remove);
				}
			}
			if(!isIE6){
				jQuery("#TBoverlay").addClass("TBoverlayMacFFBGHack");//use png overlay so hide flash
			}
			if(caption==null){caption="";}
			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);
  		var checkURL = baseURL.toLowerCase();			
	    
	    
	    if(caption==null){caption=""};
	    jQuery(window).scroll(TB_position);
	    TBoverlaySize();
	    TBload_position();

      TBprevCaption = "";
      TBprevURL = "";
      TBprevHTML = "";
      TBnextCaption = "";
      TBnextURL = "";
      TBnextHTML = "";
      TBimageCount = "";
      TB_FoundURL = false;
			if( /\.(jpg|jpeg|png|gif|bmp)$/.test(checkURL))
			{
		    TBload_position();
	      TBprevCaption = "";
	      TBprevURL = "";
	      TBprevHTML = "";
	      TBnextCaption = "";
	      TBnextURL = "";
	      TBnextPARAM = "";
	      TBprevPARAM = "";
	      TBnextHTML = "";
	      TBimageCount = "";
	      TB_FoundURL = false;

	      TB_TempArray = jQuery("div#"+objClass+" li img").get(); //jQuery("a[@rel="+imageGroup+"]").get();
	      for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TBnextHTML == "")); TB_Counter++) 
				{
	        //var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase();
	        if(TB_TempArray[TB_Counter].src)
	        {
		        var urlTypeTemp = TB_TempArray[TB_Counter].src.toLowerCase();
		        if (!(TB_TempArray[TB_Counter].src == url)) 
						{
		          if (TB_FoundURL) {
		            TBnextCaption = TB_TempArray[TB_Counter].alt;
		            TBnextURL = TB_TempArray[TB_Counter].src;
		            TBnextHTML = "\n<span id='TBnext'>\n<a href='#'>Next <small>(</small>&#8594;<small>)</small></a></span>";
		          } else {
		            TBprevCaption = TB_TempArray[TB_Counter].alt;
		            TBprevURL = TB_TempArray[TB_Counter].src;
		            TBprevHTML = "\n<span id='TBprev'>\n<a href='#'><small>(</small>&#8592;<small>)</small> Prev</a></span>";
		          }
		        } else {
		          TB_FoundURL = true;
		     			if(TB_TempArray.length > 1)
							{
								TBimageCount = "Billede " + (TB_Counter + 1) +" af "+ (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;
		 			var html = '';
			    // Code inserts html at the bottom of the page that looks similar to this:
			    //
			    html += '          <div id="outerImageContainer">';
			    html += '              <div id="imageContainer">';
			    html += '                  <img id="lightboxImage" src="'+url+'" width="'+imageWidth+'" height="'+imageHeight+'" alt="'+caption+'">';
			    html += '                  <div style="" id="hoverNav">';
			    if (!(TBprevHTML == ""))
					{
			    	html += '                      <a href="#" id="prevLink"></a>';
			    }
			    if (!(TBnextHTML == ""))
					{
			    	html += '                      <a href="#" id="nextLink"></a>';
					} 
			    html += '                  </div>';
			    html += '                  <div id="loading">';
			    html += '                      <a href="#" id="loadingLink">';
			    html += '                          <img src="'+fileLoadingImage+'">';
			    html += '                      </a>';
			    html += '                  </div>';
			    html += '              </div>';
			    html += '          </div>';
			    html += '          <div id="imageDataContainer">';
			    html += '              <div id="imageData">';
			    html += '                  <div id="imageDetails">';
			    html += '                      <span id="caption">'+caption+'</span>';
			    html += '                      <span id="numberDisplay">'+ TBimageCount +'</span>';
			    html += '                  </div>';
			    html += '                  <div id="bottomNav">';
			    html += '                      <a href="#" id="bottomNavClose">';
			    html += '                          <img src="'+fileBottomNavCloseImage+'">';
			    html += '                      </a>';
			    html += '                  </div>';
			    html += '              </div>';
			    html += '          </div>';
			    
					//jQuery("#TBwindow").fadeIn("slow").append(html);
					jQuery("#TBwindow").fadeIn("slow").append(html);
			    jQuery("#bottomNavClose").click(TB_remove);
			    jQuery("#outerImageContainer").css("height",TB_HEIGHT);
			    
		      if (!(TBprevHTML == ""))
					{
		        function goPrev()
						{
							if(jQuery(document).unbind("click",goPrev))
							{
								jQuery(document).unbind("click",goPrev);
							}
							jQuery("#TBwindow").remove();
							jQuery("body").append("<div id='TBwindow'></div>");
		          TB_showDIVLI(objClass,TBprevCaption, checkURL, TBprevURL);
		          return false;
		        }
		        jQuery("#prevLink").click(goPrev);
		        jQuery("#TBprev").click(goPrev); 
		      }
		
		      if (!(TBnextHTML == ""))
					{
		        function goNext(){
		          jQuery("#TBwindow").remove();
		          jQuery("body").append("\n<div id='TBwindow'>\n</div>");
		          TB_showDIVLI(objClass,TBnextCaption, checkURL, TBnextURL);
		          return false;  
		        }
		        jQuery("#nextLink").click(goNext);
		        jQuery("#TBnext").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 == 39){ // display previous image
		          if(!(TBnextHTML == "")){
		          document.onkeydown = "";
		          goNext();
		          }
		        } else if(keycode == 37){ // display next image
		          if(!(TBprevHTML == "")){
		          document.onkeydown = "";
		          goPrev();
		          }
		        }  
		      }
		      
		      TB_position();
		      jQuery("#loadingLink").remove();
		      jQuery("#loading").remove();
		      
		      jQuery("#bottomNav").click(TB_remove);
		      jQuery("#bottomNavClose").click(TB_remove);
		      jQuery("#TBwindow").css({display:"block"}); //for safari using css instead of show
	      };
	      imgPreloader.src = url;
				
			}else
			{
				CallFunctionNoNext(caption, url);
			}	    
	// Ende Bilder
	  } catch(e) {
	    alert( e );
	  }
	}


//helper functions
	function TB_resize()
	{
	  TB_WIDTH = (DivW*1) + 30;
	  TB_HEIGHT = (DivH*1) + 40;
	  ajaxContentW = TB_WIDTH - 30;
	  ajaxContentH = TB_HEIGHT - 45;
	  // Resizing large images - orginal by Christian Montoya edited by me.
	  var pagesize = TB_getPageSize();
	  var x = pagesize[0] - 100;
	  var y = pagesize[1] - 100;
	  if (ajaxContentW > x) {
	    ajaxContentH = ajaxContentH * (x / ajaxContentW);
	    ajaxContentW = x; 
	    if (ajaxContentH > y) { 
	      ajaxContentW = ajaxContentW * (y / ajaxContentH);
	      ajaxContentH = y; 
	    }
	  } else if (ajaxContentH > y) { 
	    ajaxContentW = ajaxContentW * (y / ajaxContentH);
	    ajaxContentH = y; 
	    if (ajaxContentW > x) { 
	      ajaxContentH = ajaxContentH * (x / ajaxContentW);
	      ajaxContentW = x;
	    }
	  }
	  TB_WIDTH = (ajaxContentW*1) + 30;
	  TB_HEIGHT = (ajaxContentH*1) + 40;
   // End Resizing
	}
	function TB_showIframe(){
	  jQuery("#TBwindow").css({display:"block"});
	}
	function TB_remove()
	{
		
		if (jQuery("#wmv")) 
		{
			try {
				jQuery("#wmv").Stop();
			} catch(e) {}
			jQuery("#wmv").empty().remove();
		}
		
	  //jQuery("#wmv").stop().empty().remove();
	  
	  jQuery("#TBhideSelect").fadeOut("slow");
	  jQuery("#TBwindow").fadeOut("slow",function(){jQuery('#TBwindow,#TBhideSelect').remove();});
	  jQuery("#TBoverlay").fadeOut("slow",function(){jQuery('#TBoverlay,').remove();});
	  return false;
	}
	
	function TB_position() {
	  var pagesize = TB_getPageSize();
	  var arrayPageScroll = TB_getPageScrollTop();
	  jQuery("#TBwindow").css({width:TB_WIDTH+"px",left: (arrayPageScroll[0] + (pagesize[0] - TB_WIDTH)/2)+"px", top: (arrayPageScroll[1] + (pagesize[1]-TB_HEIGHT)/4)+"px" });
	}
	
	
	function TBoverlaySize()
	{
		var docHeight = 0;
		
	  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) 
		{  
	    yScroll = window.innerHeight + window.scrollMaxY;
	    xScroll = window.innerWidth + window.scrollMaxX;
	    docHeight = document.body.clientHeight;
	    
	    var deff = document.documentElement;
	    var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
	    var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
	    xScroll -= (window.innerWidth - wff);
	    yScroll -= (window.innerHeight - hff);
	  } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
		{ // all but Explorer Mac
	    yScroll = document.body.scrollHeight;
	    xScroll = document.body.scrollWidth;
	    docHeight = document.body.clientHeight;
	  } else 
		{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	    yScroll = document.body.offsetHeight;
	    xScroll = document.body.offsetWidth;
	    docHeight = document.body.clientHeight;
	  }
	    
		var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  
	  //alert(myHeight);
	  jQuery("#TBoverlay").css({"height":myHeight +"px"});
	  jQuery("#TBhideSelect").css({"height":myHeight +"px","width":xScroll +"px"});
	}
	
	
	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 = new Array(w,h) 
	  return arrayPageSize;
	}
		
	function TBload_position() {
	  var pagesize = TB_getPageSize();
	  var arrayPageScroll = TB_getPageScrollTop();
	  jQuery("#TBload")
	  .css({left: (arrayPageScroll[0] + (pagesize[0] - 100)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-100)/2))+"px" })
	  .css({display:"block"});
	  
	  oldheight = jQuery("#TBoverlay").css("height");
	  
	  newvalue = parseInt(oldheight) + DivH;
	  jQuery("#TBoverlay").css("height",newvalue);
	  
	  //alert(jQuery("#TBoverlay").css("height"));
	  //alert(pagesize[0]);
	}
	
	
	function TB_getPageScrollTop(){
	  var yScrolltop;
	  var xScrollleft;
	  if (self.pageYOffset || self.pageXOffset) {
	    yScrolltop = self.pageYOffset;
	    xScrollleft = self.pageXOffset;
	  } else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){   // Explorer 6 Strict
	    yScrolltop = document.documentElement.scrollTop;
	    xScrollleft = document.documentElement.scrollLeft;
	  } else if (document.body) {// all other Explorers
	    yScrolltop = document.body.scrollTop;
	    xScrollleft = document.body.scrollLeft;
	  }
	  arrayPageScroll = new Array(xScrollleft,yScrolltop) 
	  return arrayPageScroll;
	}

	
function tb_getParameters( query ) {
	//alert(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_parseQuery ( query ) {
	//alert(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;
  }
}	
	
	document.onkeydown = function(e){
	  if (e == null) { // ie
	    keycode = event.keyCode;
	  } else { // mozilla
	    keycode = e.which;
	  }
	  if(keycode == 27){ // close
	    TB_remove();
	  }
	}
