$(document).ready(function(){
    // Load the classic theme
	Galleria.loadTheme('/scripts/galleria/themes/classic/galleria.classic.min.js');
	var currentGalleriaId=null;
	// Initialize Galleria
//	$('.galleria').galleria();
	$('.galleria').each(function(){
		var imageCount=0;
		currentGalleriaId=$(this).attr('id');
		$('a',this).each(function(){
			var galleriaConfig={show: imageCount}
			$(this).fancybox({
				thisGalleriaId : currentGalleriaId,
				onComplete		:	function() {
					$('#fancybox-content').height($('#fancybox-content').height()+50);
					//$('#fancybox-content').width($('#fancybox-content').width()+20);
					var linkTag=null;
					/*$('#fancybox-content').html('');
					if($(this).parent().hasClass('galleria')){
						currentGalleriaId=$(this).parent().attr('id');
					}else if($(this).parent().parent().hasClass('galleria')){
						currentGalleriaId=$(this).parent().parent().attr('id');
					}else{
						currentGalleriaId=$(this).parent().parent().parent().attr('id');
					}
					if($('#'+this.thisGalleriaId).get(0).nodeName.toLowerCase()=='li'){
						var selector='#'+this.thisGalleriaId+' div a';
					}else{
						var selector='#'+this.thisGalleriaId+' a';
					}*/
					var selector='#'+this.thisGalleriaId+' a';
					$('#fancybox-content').get(0).innerHTML='';
					$(selector).each(function(){
						link=document.createElement('a');
						link=$(link);
						link.attr('href',$(this).attr('href'));
						link.append($(this).find('img').clone());
						$('#fancybox-content').append(link);
						$('#fancybox-right').css('display','none');
						$('#fancybox-left').css('display','none');
					});
					$('#fancybox-content').galleria(galleriaConfig);
					$.fancybox.resize();
					$.fancybox.center();
					return true;
				},
				//href : $('#'+currentGalleriaId+'>a').attr('href')
				href : $('#'+currentGalleriaId+' a').attr('href')
			});
			imageCount++;
		});
	});
});
