/*DEBUG functions*/	var debugEnabled = true; function _g(logData){if (debugEnabled){if (typeof console !== 'undefined'){console.group(logData);}}return false;}function _u(){if (debugEnabled){if (typeof console !== 'undefined'){console.groupEnd();	}}	return false;}function _d(logData){if (debugEnabled){	if (typeof console !== 'undefined'){console.log(logData);}}	return false;}

$(document).ready(function(){
	//_d('test');
	if ($('div.gallery figure').length >1){
		$('div.gallery figure img').load(function(){
			var src = $(this).attr('src');
			var srcParts = src.split('_');
			
			
			var h= $(this).parent().height()+12;
			var w = $(this).parent().width()+12;
			var ph  = $(this).parent().parent().height();
			var pw = $(this).parent().parent().width();
			_g(srcParts[0]);
				_d('h: '+h);
				_d('w: '+w);
				_d('ph: '+ph);
				_d('pw: '+pw);
			_u();
			$(this).parent().fadeIn('fast');
			$(this).parent().css('top',((ph-h)/2)+'px').css('left',((pw-w)/2)+'px')
			$(this).parent().transform({rotate: (((Math.random() * 10)-5)+'deg')});
			$('div.gallery figure:last-child').transform({rotate:'0deg'});
		});
		
	
		$('div.gallery figure').click(function(){
			_d('click');
			var firstFig = $('div.gallery figure:last-child');
			var nextFig = $('div.gallery figure:last-child').prev();
			nextFig.animate({rotate:'0deg'},'slow');
			firstFig.animate({
							rotate: (((Math.random() * 10)-5)+'deg'),
							translateX: '500px',
			},'fast',function(){
				firstFig.detach().prependTo($('div.gallery'));
				firstFig.animate({
								rotate: (((Math.random() * 10)-5)+'deg'),
								translateX: '0px'
				},'fast');
			});
		});
	} else {
		$('div.gallery figure img').load(function(){
			$(this).parent().fadeIn('fast');
			var h= $(this).parent().height();
			$(this).parent().parent().height(h).css('margin-bottom','10px');
		});
	}
	if ($('input.date').length >0){
		$('input.date').datepicker({
			dateFormat: 'dd-MM-yy'
		});
	}
	
});








