var gallery_app = function()
{
	var load_fb = function()
	{
		if(typeof $("a[rel=gallery], .gallery-fancybox").fancybox == 'function') 
		{
			$("a[rel=gallery], .gallery-fancybox").fancybox({
				'overlayOpacity':	0.8,
				'titlePosition' 	: 'over',
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
				}
			});
		}
	}
	if ($('#form_result').size() == 0) 
	{
		$('div#form-frontend_gallery_form-wrap').hide();		
	};

	
	$('#submit-your-own').bind('click', function(e)
	{
		e.preventDefault();
		$('div#form-frontend_gallery_form-wrap').slideToggle();
	});
	
	$('form#filterBy').live('submit', function(e)
	{
		var frm = $('form#filterBy');
		e.preventDefault();
		
		$.ajax({
			url: frm.attr('action'),
			type: 'POST',
			data: frm.serialize(),
			success: function(resp)
			{
				$('#content').html(resp);
				$('.zoomHover').css('display','none');
				   $('.photoGallery li, .item').hover(function() {
					  $('.zoomHover',this).stop(true, true).fadeTo("fast", 0.8);
					  }, function() { $('.zoomHover').fadeOut(500);
				});
				load_fb();
			}
		});
	});
	$('form#filterBy select').live('change', function()
	{
		$('form#filterBy').submit();
	});
	
	
	load_fb();
}


$(document).ready(gallery_app);
