	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();

	
	
	
	var Scroller = new Class(
	{	
		Implements: [Events, Options],
	
		options: 
		{
			area: 50,
			velocity: 1,
			onChange: function(x, y)
			{
				this.element.scrollTo(x, y);
			}
		},
	
		initialize: function(element, options)
		{
			this.setOptions(options);
			this.element = $(element);
			this.listener = ($type(this.element) != 'element') ? $(this.element.getDocument().body) : this.element;
			this.timer = null;
			this.coord = this.getCoords.bind(this);
		},
	
		start: function()
		{
			this.listener.addEvent('mousemove', this.coord);
		},
	
		stop: function()
		{
			this.listener.removeEvent('mousemove', this.coord);
			this.timer = $clear(this.timer);
		},
	
		getCoords: function(event)
		{
			this.page = (this.listener.get('tag') == 'body') ? event.client : event.page;
			
			if (!this.timer) this.timer = this.scroll.periodical(50, this);
		},
	
		scroll: function()
		{
			var size 	= this.element.getSize(); 
			var scroll 	= this.element.getScroll(); 
			var pos 	= this.element.getPosition(), change = {'x': 0, 'y': 0};
			
			for (var z in this.page)
			{
				if (this.page[z] < (this.options.area + pos[z]) && scroll[z] != 0)
					change[z] = (this.page[z] - this.options.area - pos[z]) * this.options.velocity;
				else if (this.page[z] + this.options.area > (size[z] + pos[z]) && size[z] + size[z] != scroll[z])
					change[z] = (this.page[z] - size[z] + this.options.area - pos[z]) * this.options.velocity;
			}
			
			if (change.y || change.x) this.fireEvent('change', [scroll.x + change.x, scroll.y + change.y]);
		}
	
	});

	// Loader Image
	var loaderImage = new Image();
	
	window.addEvent("domready", function() 
	{
		// Load the Loader
		loaderImage.src = "/gallery/images/loader.gif";
		
		// Set Medium Image
		setMedium($("content").getElementsByTagName('img')[0].getAttribute("medium"), $("content").getElementsByTagName('img')[0].getAttribute("full"));
		
		// Initialize LightBox
		new Lightbox({
    		anchors: $$('a.lightbox'), //use all anchor tags with class "lightbox" instead
    		autoScanLinks: false
		});
		
		// Initialize Scroller
		var scroll1 = new Scroller("drag", 
		{
			area	: 150, 
			velocity: 1
		});
					
		$("drag").setStyle("cursor", "move");					
		$("drag").addEvent("mousedown", function() 
		{
			scroll1.start();
		});
		
		$("drag").addEvent("mouseup", function() 
		{
			scroll1.stop();
		});

		/*
		$('drag').addEvent('mouseover', scroll1.start.bind(scroll1));
		$('drag').addEvent('mouseout', scroll1.stop.bind(scroll1));
		*/
	});
	
	window.addEvent('load', function()
	{
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.version == 3)
		{
			// Hide the knob 
			$("scrollarea").setStyle("display", "none");
			
			// Add scroll to content
			$("content").setStyle("overflow", "auto"); 
		}
		else
		{
			// Initialize Thumbnails Vertical Scroller
			makeScrollbar( $('content'), $('scrollBarContainer'), $('scrollKnob'), false, false, 'scrollBack', 'scrollForward');
		}
	});


	function setMedium(src, fullsrc)
	{
		// Load Image
		var loadImage = new Image();
			loadImage.src = src;
		
		// Append Loader
		$("image").setStyles(
		{
			"background-image" 		: "url(/gallery/images/loader.gif)",
			"background-position" 	: "220px 150px",
			"background-repeat" 	: "no-repeat",
			"width"					: $("image").getParent().getSize().x,
			"height"				: $("image").getParent().getSize().y		
		});
		
		var resetScroll = setInterval(function()
		{
			if(loadImage.complete)
			{	
				$("image").getElementsByTagName("img")[0].src = loadImage.src;
				$("image").setStyles({
					"background-position" 	: "0 0",
					"width"					: loadImage.naturalWidth,
					"height"				: loadImage.naturalHeight
				});
							
				$("mediumA").href = fullsrc;
				$("fullA").href = fullsrc;

				$('drag').scrollTo(0, 0);
				
				clearInterval(resetScroll);
			}
		}, 50);		
	}
	
	
	function makeScrollbar(content, scrollbar, handle, horizontal, ignoreMouse, scrollBack, scrollForward)
	{
		var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
		var slider = new Slider(scrollbar, handle, 
		{	
			steps: steps,
			mode: (horizontal?'horizontal':'vertical'),
			onChange: function(step)
			{
				// Scrolls the content element in x or y direction.
				var x = (horizontal?step:0);
				var y = (horizontal?0:step);				
				
				var myElement = $(content);								
				new Fx.Scroll(myElement).start(x, y);
			}
		}).set(0);
		
		var toBack, toForward;
		
		$(scrollBack).addEvent('mousedown', function(e)
		{
			toBack = setInterval(function()
			{
				var step = slider.step - 60;	
						   slider.set(step);
			}, 50);
		});
		
		$(scrollBack).addEvent('mouseup', function(e)
		{
			clearInterval(toBack);
		});
		
		$(scrollForward).addEvent('mousedown', function(e)
		{
			toForward = setInterval(function()
			{
				var step = slider.step + 60;	
						   slider.set(step);
			}, 50);
		});
		
		$(scrollForward).addEvent('mouseup', function(e)
		{
			clearInterval(toForward);
		});
		
		if( !(ignoreMouse) )
		{
			// Scroll the content element when the mousewheel is used within the 
			// content or the scrollbar element.
			$$(content, scrollbar).addEvent('mousewheel', function(e)
			{	
				e = new Event(e).stop();
				var step = slider.step - e.wheel * 60;	
						   slider.set(step);			
			});
		}
		// Stops the handle dragging process when the mouse leaves the document body.
		$(document.body).addEvent('mouseleave',function()
		{
			slider.drag.stop()
		});
	}
	