(function($){
	var frontend={
		showTimer:0,
		hideTimer:0,
		init:function(){
			this.initSlideshow();			
			this.initLink();
			this.initImageCaption();
			this.initPhotoTag();
			this.initLightbox();
		},
		initLink:function()
		{				
			$('.js-make-link').bind('click',{'parentclass':this},this.followlink);					
		},
		followlink:function(){
			location.href=$(this).find('a').first().attr('href');
		},
		initPhotoTag:function(){
			var tagOptions={
					requesTagstUrl: app.webroot+'pages/display/phototags',
					showAddTagLinks: false,
					imageWrapBox:{showTagList:false},
					externalAddTagLinks:{bind:true}
				};
				
			$('.familyportrait').photoTag(tagOptions);
		},
		initSlideshow:function(){
			$("#wrapper-header-image").slides(
					{
						container: 'wrapper-images',
						generateNextPrev: true,
						pagination : false,
						generatePagination: false,
						play:4000,
						slideSpeed : 600,
						animationStart:this.hideImageCaptionText,
						animationComplete:this.showImageCaptionText
					}
				);
		},
		hideImageCaptionText:function(){
			$('.wrapper-header-image-caption').hide();
		},
		showImageCaptionText:function(){
			var strCaption=$('.slides_control > div:visible img').attr('title');
			if (strCaption!='')
			{
				$('.wrapper-header-image-caption > p').html(strCaption);
				$('.wrapper-header-image-caption').show();
			}
		},
		initImageCaption:function(){
			/*$('.wrapper-images').bind('mouseenter',{ref:this},this.showCaptionDelay);
			$('.wrapper-header-image-caption').bind('mouseenter',{ref:this},this.showCaptionDelay);
			$('#wrapper-header-image > a').bind('mouseenter',{ref:this},this.showCaptionDelay);
			$('.wrapper-images').bind('mouseleave',{ref:this},this.hideCaptionDelay);
			$('.wrapper-header-image-caption').bind('mouseleave',{ref:this},this.hideCaptionDelay);
			*/
			this.showImageCaptionText();
		},
		showCaptionDelay:function(evt)
		{			
			if (evt.data.ref.hideTimer) { clearTimeout(evt.data.ref.hideTimer); }	
			if (!$('.wrapper-header-image-caption').is(':visible'))
			{
				$('.wrapper-header-image-caption').show('slide',{direction:'down'});
			}			 			
		},
		hideCaptionDelay:function(evt)
		{
			if (evt.data.ref.hideTimer) clearTimeout(evt.data.ref.hideTimer);
			evt.data.ref.hideTimer = setTimeout(evt.data.ref.hideCaption, 500);				
		},
		hideCaption:function(){
			$('.wrapper-header-image-caption').hide('slide',{direction:'down'});
		},
		initLightbox:function(){
			$('a.js-open-lightbox').fancybox();
		}
		
	};
	
	$(document).ready(function(){
		frontend.init();
	});
})(jQuery);

