/**
 *
 * Galleria (http://monc.se/kitchen/stew/galleria)
 * 
 * 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.
 * 
 *
 * Tested in Safari 3, Firefox 2, MSIE 6, MSIE 7, Opera 9
 * 
 * Version 0.9
 * Februari 13, 2008
 *
 * Copyright (c) 2008 David Hellsing (http://monc.se)
 * Licensed under the GPL license.
 * http://www.opensource.org/licenses/gpl-license.php
 *  
 **/
;(function(){var $$;$$=jQuery.fn.galleria=function(options){var defaults={nextText:'Click to view the next image',fadeIn:true};var opts=jQuery.extend(defaults,options);if(!$$.hasCSS()){return false;}
return this.each(function(){jQuery(this).addClass('galleria')
jQuery(this).children('li').each(function(i){var _container=jQuery(this);var _o=jQuery.meta?jQuery.extend({},opts,_container.data()):opts;var _img=jQuery(this).children('img').css('display','none');var _src=_img.is('img')?_img.attr('src'):jQuery(this).children('a').attr('href');var _loader=new Image();jQuery(_loader).load(function(){$(this).click(function(){_container.removeClass('active');jQuery($$.nextLi(_container)).addClass('active');});$(this).attr('title',_o.nextText);var _span=jQuery(document.createElement('span'));_span.addClass('caption').text(_img.attr('title'));jQuery(this).attr('alt',_img.attr('alt'));var _thumb=_img.clone(true).addClass('thumb cloned').css('display','none');if(!_thumb.hasClass('noscale')&&_thumb.hasClass('cloned')){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 if(_thumb.hasClass('cloned')){_thumb.css({marginLeft:-(_img.width()-_container.width())/2,marginTop:-(_img.height()-_container.height())/2});}else{_thumb=_container.children('a').children('img').addClass('thumb noscale').css('display','none').attr('title',_container.children('a').attr('title'));_span.text(_container.children('a').attr('title'));_container.children('a').replaceWith(_thumb);if(!jQuery.browser.opera){_thumb.css({marginLeft:-(_thumb.width()-_container.width())/2,marginTop:-(_thumb.height()-_container.height())/2});}}
_thumb.click(function(){_container.siblings('.active').removeClass('active');_container.addClass('active');});_thumb.hover(function(){jQuery(this).addClass('hover');},function(){jQuery(this).removeClass('hover');});var _div=jQuery(document.createElement('div'));_div.prepend(_span).prepend(this);_container.prepend(_div).prepend(_thumb);if(_o.fadeIn){_thumb.fadeIn();}
else{_thumb.css('display','block');}
_img.remove();}).error(function(){_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');}).attr('src',_src);});});};$$.nextLi=function(li){return jQuery(li).next().is('li')?jQuery(li).next():jQuery(li).siblings(':first-child');};$$.hasCSS=function(){$('body').append(jQuery(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;};})();
