


/*
	version 1.2
*/
NS.Package('NS.Site.ThumbNail');
(function($){
	NS.Site.ThumbNail = function(options){
		
		var _option = {};
		var _private = {
			// -------------------------------[ return initialization ]---------------------------------------------
			init : function (opt){
				opt = opt || {};
				return {
					target 	 : opt.target || 'a.thumbnail',
					fancybox : opt.fancybox || {
						'opacity'		: true,
						'overlayShow'	: false,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'
					}
				};
			},
			// -----------------------------[ render thumbnail position ]-------------------------------------------
			setPos : function (){
				var _thumbnails = _option.target;
				
				for(var i=0; i < _thumbnails.length; i++){
					
					var _thumb = $(_thumbnails[i]);
						
						//_img.height( _height );				
						(function(thumb){
							
						var _img 	= thumb.find('img'),
							_height = thumb.height(),
							_width 	= thumb.width();	
											
							Site.Image().getSize(_img.attr('src'), function(size){
								
								if(size.height > size.width){
				
									_img.height( Math.floor((_width / size.width) * size.height) );
									var _top 	= '-'+Math.floor(Math.floor((size.height - _height) /2)/4)+'px';
									var _left	= '0px';
								}else{
									
									_img.width( Math.floor((_height / size.height) * size.width) );
									var _top = '0px';
									var _left 	= '-'+Math.round(Math.floor((size.width - _width) / 2)/4)+'px';
								
								}
								_img.css({'top': _top});
								_img.css({'left': _left});
							});
						})(_thumb);
									
				}
			}
		};

		_option =_private.init( options );
		_option.target = $(_option.target);
		
		//set fancybox...
		if(_option.target.fancybox){
			_option.target.fancybox( _option.fancybox );
		}else{
			$$('Deze thumbnail maakt gebruik van fancybox');
		}
		_private.setPos();
	}
})(jQuery);





