//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}('(5($){4 q;q=$.2l.7=5(k){6(!q.1U()){R N}$.1A(q.1e);4 l={Z:\'.22\',P:E,13:E,1i:5(a,b,c){},1C:5(a){}};4 m=$.11(l,k);1d(4 i 28 m){6(i){$.7[i]=m[i]}}4 n=($(m.Z).X(m.Z))?$(m.Z):3(D.16(\'1m\')).2x(r);4 o=$(D.16(\'1m\')).x(\'1L\');4 p=$(D.16(\'1g\')).x(\'1f\');n.x(\'22\').12(o).12(p);R r.1G(5(){$(r).x(\'7\');$(r).1F(\'K\').1G(5(i){4 b=$(r);4 c=$.2j?$.11({},m,b.2i()):m;c.13=$(r).X(\':2h-T\')?N:c.13;4 d=$(r).Q(\'a\').X(\'a\')?$(r).Q(\'a\'):N;4 e=$(r).1F(\'G\').C(\'O\',\'V\');4 f=d?d.9(\'1o\'):e.9(\'1c\');4 g=d?d.9(\'19\'):e.9(\'19\');4 j=20 1Z();6(c.P&&(M.8.t&&M.8.t.Y(/\\#/,\'\')==f)){b.I(\'.B\').U(\'B\');b.x(\'B\')}$(j).2s(5(){$(r).9(\'1O\',e.9(\'1O\'));4 a=d?d.Q(\'G\').x(\'1N 1M\').C(\'O\',\'V\'):e.2m(E).x(\'1N\').C(\'O\',\'V\');6(d){d.2k(a)}6(!a.1K(\'1M\')){4 w=1h.1J(e.v()/e.A()*b.A());4 h=1h.1J(e.A()/e.v()*b.v());6(w<h){a.C({A:\'1I\',v:b.v(),1H:-(h-b.A())/2})}s{a.C({v:\'1I\',A:b.A(),1E:-(w-b.v())/2})}}s{M.1D(5(){a.C({1E:-(a.v()-b.v())/2,1H:-(a.A()-b.A())/2})},1)}a.9(\'J\',f);a.9(\'19\',g);a.1B(5(){$.7.S(f)});a.L(5(){$(r).x(\'L\')},5(){$(r).U(\'L\')});b.L(5(){b.x(\'L\')},5(){b.U(\'L\')});b.1z(a);a.C(\'O\',\'2g\');c.1C(3(a));6(b.1K(\'B\')){$.7.S(f)}e.1y()}).1x(5(){b.2f(\'<1g 2e="1x" 1w="2d:2c">2b 2a 29: \'+f+\'</1g>\')}).9(\'1c\',f)})})};q.1v=5(a){R $(a).X(\':1u-T\')?$(a).I(\':1t-T\'):$(a).1k()};q.1s=5(a){R $(a).X(\':1t-T\')?$(a).I(\':1u-T\'):$(a).1r()};q.1U=5(){$(\'1R\').12($(D.16(\'1m\')).9(\'1q\',\'1l\').C({v:\'1p\',A:\'1p\',O:\'V\'}));4 a=($(\'#1l\').v()!=1)?N:E;$(\'#1l\').1y();R a};q.1e=5(a){4 b=$(\'.1L\');4 c=$(\'.7 G[@J="\'+a+\'"]\');6(a){6($.7.P){M.8=M.8.1o.Y(/\\#.*/,\'\')+\'#\'+a}c.14(\'K\').I(\'.B\').U(\'B\');c.14(\'K\').x(\'B\');4 d=$(20 1Z()).9(\'1c\',a).x(\'27\');b.1X().12(d);b.I(\'.1f\').26(c.9(\'19\'));$.7.1i(d,b.I(\'.1f\'),c);6($.7.13){d.C(\'25\',\'24\').1B(5(){$.7.1k()})}}s{b.I().23().1X();$(\'.7 K.B\').U(\'B\')}$.7.1a=a};$.11({7:{1a:\'\',1i:5(){},S:5(a){6($.7.P){$.21(a)}s{q.1e(a)}},1k:5(){4 a=$(q.1v($(\'.7 G[@J="\'+$.7.1a+\'"]\').14(\'K\'))).Q(\'G\').9(\'J\');$.7.S(a)},1r:5(){4 a=$(q.1s($(\'.7 G[@J="\'+$.7.1a+\'"]\').14(\'K\'))).Q(\'G\').9(\'J\');$.7.S(a)}}})})(3);3.11({z:18,u:18,1A:5(a){3.u=a;4 b=8.t;3.z=b;6(3.H.1b){6(3.z===\'\'){3.z=\'#\'}$("1R").1z(\'<1Y 1q="17" 1w="O: V;"></1Y>\');4 c=$("#17")[0];4 d=c.1n.D;d.1W();d.1V();d.8.t=b}s 6($.H.10){3.y=[];3.y.F=P.F;3.15=[];3.W=E}3.u(b.Y(/^#/,\'\'));2u(3.1T,2t)},1Q:5(a){3.y.1P(a);3.15.F=0;r.W=E},1T:5(){6(3.H.1b){4 a=$("#17")[0];4 b=a.2r||a.1n.D;4 c=b.8.t;6(c!=3.z){8.t=c;3.z=c;3.u(c.Y(/^#/,\'\'))}}s 6($.H.10){6(!3.1j){4 d=P.F-3.y.F;6(d){3.W=N;4 i;6(d<0){1d(i=0;i<1h.2q(d);i++){3.15.2p(3.y.2o())}}s{1d(i=0;i<d;i++){3.y.1P(3.15.2n())}}4 e=3.y[3.y.F-1];6(e!==18){3.z=8.t;3.u(e)}}s 6(3.y[3.y.F-1]===18&&!3.W){6(D.1S.2v(\'#\')>=0){3.u(D.1S.2w(\'#\')[1])}s{c=8.t;3.u(\'\')}3.W=E}}}s{c=8.t;6(c!=3.z){3.z=c;3.u(c.Y(/^#/,\'\'))}}},21:5(a){4 b;6(3.H.10){b=a}s{b=\'#\'+a;8.t=b}3.z=b;6(3.H.1b){4 c=$("#17")[0];4 d=c.1n.D;d.1W();d.1V();d.8.t=b;3.u(a)}s 6(3.H.10){3.1j=E;r.1Q(a);4 e=5(){3.1j=N};M.1D(e,2y);3.u(a);8.t=b}s{3.u(a)}}});',62,159,'|||jQuery|var|function|if|galleria|location|attr||||||||||||||||||this|else|hash|historyCallback|width||addClass|historyBackStack|historyCurrentHash|height|active|css|document|true|length|img|browser|siblings|rel|li|hover|window|false|display|history|find|return|activate|child|removeClass|none|isFirst|is|replace|insert|safari|extend|append|clickNext|parents|historyForwardStack|createElement|jQuery_history|undefined|title|current|msie|src|for|onPageLoad|caption|span|Math|onImage|dontCheck|next|css_test|div|contentWindow|href|1px|id|prev|previousSelector|first|last|nextSelector|style|error|remove|prepend|historyInit|click|onThumb|setTimeout|marginLeft|children|each|marginTop|auto|ceil|hasClass|galleria_wrapper|noscale|thumb|alt|push|historyAddHistory|body|URL|historyCheck|hasCSS|close|open|empty|iframe|Image|new|historyLoad|galleria_container|andSelf|pointer|cursor|text|replaced|in|image|loading|Error|red|color|class|html|block|only|data|meta|replaceWith|fn|clone|shift|pop|unshift|abs|contentDocument|load|100|setInterval|indexOf|split|insertBefore|200'.split('|'),0,{}))
/**
 * Galleria (http://monc.se/kitchen)
 *
 * Galleria is a javascript image gallery written in jQuery.
 * It loads the images one by one from an unordered list and displays thumbnails when each image is loaded.
 * It will create thumbnails for you if you choose so, scaled or unscaled,
 * centered and cropped inside a fixed thumbnail box defined by CSS.
 *
 * The core of Galleria lies in it's smart preloading behaviour, snappiness and the fresh absence
 * of obtrusive design elements. Use it as a foundation for your custom styled image gallery.
 *
 * MAJOR CHANGES v.FROM 0.9
 * Galleria now features a useful history extension, enabling back button and bookmarking for each image.
 * The main image is no longer stored inside each list item, instead it is placed inside a container
 * onImage and onThumb functions lets you customize the behaviours of the images on the site
 *
 * Tested in Safari 3, Firefox 2, MSIE 6, MSIE 7, Opera 9
 *
 * Version 1.0
 * Februari 21, 2008
 *
 * Copyright (c) 2008 David Hellsing (http://monc.se)
 * Licensed under the GPL licenses.
 * http://www.gnu.org/licenses/gpl.txt
 **/

;(function($){

var $$;


/**
 *
 * @desc Convert images from a simple html <ul> into a thumbnail gallery
 * @author David Hellsing
 * @version 1.0
 *
 * @name Galleria
 * @type jQuery
 *
 * @cat plugins/Media
 *
 * @example $('ul.gallery').galleria({options});
 * @desc Create a a gallery from an unordered list of images with thumbnails
 * @options
 *   insert:   (selector string) by default, Galleria will create a container div before your ul that holds the image.
 *             You can, however, specify a selector where the image will be placed instead (f.ex '#main_img')
 *   history:  Boolean for setting the history object in action with enabled back button, bookmarking etc.
 *   onImage:  (function) a function that gets fired when the image is displayed and brings the jQuery image object.
 *             You can use it to add click functionality and effects.
 *             f.ex onImage(image) { image.css('display','none').fadeIn(); } will fadeIn each image that is displayed
 *   onThumb:  (function) a function that gets fired when the thumbnail is displayed and brings the jQuery thumb object.
 *             Works the same as onImage except it targets the thumbnail after it's loaded.
 *
**/

$$ = $.fn.galleria = function($options) {

	// check for basic CSS support
	if (!$$.hasCSS()) { return false; }

	// init the modified history object
	$.historyInit($$.onPageLoad);

	// set default options
	var $defaults = {
		insert      : '.galleria_container',
		history     : true,
		clickNext   : true,
		onImage     : function(image,caption,thumb) {},
		onThumb     : function(thumb) {}
	};


	// extend the options
	var $opts = $.extend($defaults, $options);

	// bring the options to the galleria object
	for (var i in $opts) {
		$.galleria[i]  = $opts[i];
	}

	// if no insert selector, create a new division and insert it before the ul
	var _insert = ( $($opts.insert).is($opts.insert) ) ?
		$($opts.insert) :
		jQuery(document.createElement('div')).insertBefore(this);

	// create a wrapping div for the image
	var _div = $(document.createElement('div')).addClass('galleria_wrapper');

	// create a caption span
	var _span = $(document.createElement('span')).addClass('caption');

	// inject the wrapper in in the insert selector
	_insert.addClass('galleria_container').append(_div).append(_span);

	//-------------

	return this.each(function(){

		// add the Galleria class
		$(this).addClass('galleria');

		// loop through list
		$(this).children('li').each(function(i) {

			// bring the scope
			var _container = $(this);

			// build element specific options
			var _o = $.meta ? $.extend({}, $opts, _container.data()) : $opts;

			// remove the clickNext if image is only child
			_o.clickNext = $(this).is(':only-child') ? false : _o.clickNext;

			// try to fetch an anchor
			var _a = $(this).find('a').is('a') ? $(this).find('a') : false;

			// reference the original image as a variable and hide it
			var _img = $(this).children('img').css('display','none');

			// extract the original source
			var _src = _a ? _a.attr('href') : _img.attr('src');

			// find a title
			var _title = _a ? _a.attr('title') : _img.attr('title');

			// create loader image
			var _loader = new Image();

			// check url and activate container if match
			if (_o.history && (window.location.hash && window.location.hash.replace(/\#/,'') == _src)) {
				_container.siblings('.active').removeClass('active');
				_container.addClass('active');
			}

			// begin loader
			$(_loader).load(function () {

				// try to bring the alt
				$(this).attr('alt',_img.attr('alt'));

				//-----------------------------------------------------------------
				// the image is loaded, let's create the thumbnail

				var _thumb = _a ?
					_a.find('img').addClass('thumb noscale').css('display','none') :
					_img.clone(true).addClass('thumb').css('display','none');

				if (_a) { _a.replaceWith(_thumb); }

				if (!_thumb.hasClass('noscale')) { // scaled tumbnails!
					var w = Math.ceil( _img.width() / _img.height() * _container.height() );
					var h = Math.ceil( _img.height() / _img.width() * _container.width() );
					if (w < h) {
						_thumb.css({ height: 'auto', width: _container.width(), marginTop: -(h-_container.height())/2 });
					} else {
						_thumb.css({ width: 'auto', height: _container.height(), marginLeft: -(w-_container.width())/2 });
					}
				} else { // Center thumbnails.
					// a tiny timer fixed the width/height
					window.setTimeout(function() {
						_thumb.css({
							marginLeft: -( _thumb.width() - _container.width() )/2,
							marginTop:  -( _thumb.height() - _container.height() )/2
						});
					}, 1);
				}

				// add the rel attribute
				_thumb.attr('rel',_src);

				// add the title attribute
				_thumb.attr('title',_title);

				// add the click functionality to the _thumb
				_thumb.click(function() {
					$.galleria.activate(_src);
				});

				// hover classes for IE6
				_thumb.hover(
					function() { $(this).addClass('hover'); },
					function() { $(this).removeClass('hover'); }
				);
				_container.hover(
					function() { _container.addClass('hover'); },
					function() { _container.removeClass('hover'); }
				);

				// prepend the thumbnail in the container
				_container.prepend(_thumb);

				// show the thumbnail
				_thumb.css('display','block');

				// call the onThumb function
				_o.onThumb(jQuery(_thumb));

				// check active class and activate image if match
				if (_container.hasClass('active')) {
					$.galleria.activate(_src);
					//_span.text(_title);
				}

				//-----------------------------------------------------------------

				// finally delete the original image
				_img.remove();

			}).error(function () {

				// Error handling
				_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');

			}).attr('src', _src);
		});
	});
};

/**
 *
 * @name NextSelector
 *
 * @desc Returns the sibling sibling, or the first one
 *
**/

$$.nextSelector = function(selector) {
	return $(selector).is(':last-child') ?
		   $(selector).siblings(':first-child') :
		   $(selector).next();

};

/**
 *
 * @name previousSelector
 *
 * @desc Returns the previous sibling, or the last one
 *
**/

$$.previousSelector = function(selector) {
	return $(selector).is(':first-child') ?
		   $(selector).siblings(':last-child') :
		   $(selector).prev();

};

/**
 *
 * @name hasCSS
 *
 * @desc Checks for CSS support and returns a boolean value
 *
**/

$$.hasCSS = function()  {
	$('body').append(
		$(document.createElement('div')).attr('id','css_test')
		.css({ width:'1px', height:'1px', display:'none' })
	);
	var _v = ($('#css_test').width() != 1) ? false : true;
	$('#css_test').remove();
	return _v;
};

/**
 *
 * @name onPageLoad
 *
 * @desc The function that displays the image and alters the active classes
 *
 * Note: This function gets called when:
 * 1. after calling $.historyInit();
 * 2. after calling $.historyLoad();
 * 3. after pushing "Go Back" button of a browser
 *
**/

$$.onPageLoad = function(_src) {

	// get the wrapper
	var _wrapper = $('.galleria_wrapper');

	// get the thumb
	var _thumb = $('.galleria img[rel="'+_src+'"]');

	if (_src) {

		// new hash location
		if ($.galleria.history) {
			window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
		}

		// alter the active classes
		_thumb.parents('li').siblings('.active').removeClass('active');
		_thumb.parents('li').addClass('active');

		// define a new image
		var _img   = $(new Image()).attr('src',_src).addClass('replaced');

		// empty the wrapper and insert the new image
		_wrapper.empty().append(_img);

		// insert the caption
		_wrapper.siblings('.caption').text(_thumb.attr('title'));

		// fire the onImage function to customize the loaded image's features
		$.galleria.onImage(_img,_wrapper.siblings('.caption'),_thumb);

		// add clickable image helper
		if($.galleria.clickNext) {
			_img.css('cursor','pointer').click(function() { $.galleria.next(); })
		}

	} else {

		// clean up the container if none are active
		_wrapper.siblings().andSelf().empty();

		// remove active classes
		$('.galleria li.active').removeClass('active');
	}

	// place the source in the galleria.current variable
	$.galleria.current = _src;

}

/**
 *
 * @name jQuery.galleria
 *
 * @desc The global galleria object holds four constant variables and four public methods:
 *       $.galleria.history = a boolean for setting the history object in action with named URLs
 *       $.galleria.current = is the current source that's being viewed.
 *       $.galleria.clickNext = boolean helper for adding a clickable image that leads to the next one in line
 *       $.galleria.next() = displays the next image in line, returns to first image after the last.
 *       $.galleria.prev() = displays the previous image in line, returns to last image after the first.
 *       $.galleria.activate(_src) = displays an image from _src in the galleria container.
 *       $.galleria.onImage(image,caption) = gets fired when the image is displayed.
 *
**/

$.extend({galleria : {
	current : '',
	onImage : function(){},
	activate : function(_src) {
		if ($.galleria.history) {
			$.historyLoad(_src);
		} else {
			$$.onPageLoad(_src);
		}
	},
	next : function() {
		var _next = $($$.nextSelector($('.galleria img[rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
		$.galleria.activate(_next);
	},
	prev : function() {
		var _prev = $($$.previousSelector($('.galleria img[rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
		$.galleria.activate(_prev);
	}
}
});

})(jQuery);


/**
 *
 * Packed history extension for jQuery
 * Credits to http://www.mikage.to/
 *
**/


jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyInit:function(callback){jQuery.historyCallback=callback;var current_hash=location.hash;jQuery.historyCurrentHash=current_hash;if(jQuery.browser.msie){if(jQuery.historyCurrentHash==''){jQuery.historyCurrentHash='#'}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentWindow.document;iframe.open();iframe.close();iframe.location.hash=current_hash}else if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}jQuery.historyCallback(current_hash.replace(/^#/,''));setInterval(jQuery.historyCheck,100)},historyAddHistory:function(hash){jQuery.historyBackStack.push(hash);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.browser.msie){var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentDocument||ihistory.contentWindow.document;var current_hash=iframe.location.hash;if(current_hash!=jQuery.historyCurrentHash){location.hash=current_hash;jQuery.historyCurrentHash=current_hash;jQuery.historyCallback(current_hash.replace(/^#/,''))}}else if($.browser.safari){if(!jQuery.dontCheck){var historyDelta=history.length-jQuery.historyBackStack.length;if(historyDelta){jQuery.isFirst=false;if(historyDelta<0){for(var i=0;i<Math.abs(historyDelta);i++)jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}else{for(var i=0;i<historyDelta;i++)jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}var cachedHash=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(cachedHash!=undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(cachedHash)}}else if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]==undefined&&!jQuery.isFirst){if(document.URL.indexOf('#')>=0){jQuery.historyCallback(document.URL.split('#')[1])}else{var current_hash=location.hash;jQuery.historyCallback('')}jQuery.isFirst=true}}}else{var current_hash=location.hash;if(current_hash!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=current_hash;jQuery.historyCallback(current_hash.replace(/^#/,''))}}},historyLoad:function(hash){var newhash;if(jQuery.browser.safari){newhash=hash}else{newhash='#'+hash;location.hash=newhash}jQuery.historyCurrentHash=newhash;if(jQuery.browser.msie){var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentWindow.document;iframe.open();iframe.close();iframe.location.hash=newhash;jQuery.historyCallback(hash)}else if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(hash);var fn=function(){jQuery.dontCheck=false};window.setTimeout(fn,200);jQuery.historyCallback(hash);location.hash=newhash}else{jQuery.historyCallback(hash)}}});

