$().ready(function(){
	lightVisible = false;
	position = $('div#menu a.selected').position();
	w = $('div#menu a.selected').width();
	$('#menuSelectedLight').css('left', position.left + 68 + Math.round(w/2) + 'px');
	$('#menuSelectedLight').css('top', position.top + 17 + 'px');
	$('#menuSelectedLight').show();
/*
	$('#header').mousemove(function(e){
		var offset = $(this).offset();
		if (
			e.pageX > (offset.left + 110) &&
			e.pageX < (offset.left + 760) &&
			e.pageY < 80
		)
		{
			if (!lightVisible)
			{
				$('#menuHoverLight').show();
				lightVisible = true;
			}
			$('#menuHoverLight').css('left', (e.pageX - 30) + 'px');
			$('#menuHoverLight').css('top', (this.offsetTop + 17) + 'px');
		}
	});
*/
	$('div#menu a').mouseenter(function(){
		pW = $(this).position();
		aW = $(this).width();
		//$('#menuHoverLight').hide();
		$('#menuHoverLight').css('left', pW.left + 68 + Math.round(aW/2) + 'px');
		$('#menuHoverLight').css('top', pW.top + 17 + 'px');
		if (!lightVisible)
		{
			$('#menuHoverLight').show();
			lightVisible = true;
		}
	});

	$('div#menu').mouseleave(function(){
		$('#menuHoverLight').hide();
		lightVisible = false;
	});
});

model = {
 reload: function(){
  $('#photoList').hide();
  $.getJSON(
   '/ajax/modelPhotoListLoader',
   {albumId: $('#modelAlbumId').val()},
   function(g){
    $('#photoList').html(g.content);
    $('#photoList').show();
   }
  );
 }
}

fancyboxSettings =
{
	'hideOnContentClick': true,
	'overlayShow': false,
	'itemArray': photoList,
	'callbackOnStart': function(){keysEnabled = false},
	'callbackOnStop': function(){keysEnabled = true}
}

gallery = {
	step: 5,
	albumId: 0,
	from: 0,
	total: 0,
	init: function(){
		$("#model a.photo").fancybox(fancyboxSettings);
		$("#photos-list a.photo").fancybox(fancyboxSettings);
		gallery.reloadLinks();
		$('#gallery-l').click(function(){
			gallery.showPrevious();
			return false;
		});
		$('#gallery-r').click(function(){
			gallery.showNext();
			return false;
		});
		$("#gallery a.photo").fancybox(fancyboxSettings);
	},
	reloadLinks: function(){
		$('#gallery-l').removeClass();
		if(this.from>0){
			$('#gallery-l').addClass('enabled');
		}
		$('#gallery-r').removeClass();
		if(this.from<(this.total-this.step)){
			$('#gallery-r').addClass('enabled');
		}
	},
	showPrevious: function(){
		if(this.from>0){
			this.loadGallery(-this.step);
		}
	},
	showNext: function(){
		if(this.from<(this.total-this.step)){
			this.loadGallery(this.step);
		}
	},
	loadGallery: function(step){
		$.getJSON(
			'/ajax/galleryLoader',
			{
				albumId: this.albumId, 
				f: (this.from+step)
			},
			function(g){
				gallery.from=parseInt(g.from);
				$('#photos-list-mini').fadeOut('fast',function(){
					$('#photos-list-mini').html(g.content);
					$('#photos-list-mini').fadeIn('slow');
					$("#photos-list-mini a").fancybox(fancyboxSettings);
				});
				gallery.reloadLinks();
			}
		);
	}
}

$(document).ready(gallery.init);

