/*======================================================================
	NICHOLAS SEBASTIAN HAIR SALON: JavaScript Functions
----------------------------------------------------------------------*/
$.extend({
	/*======================================================================
		HOMEPAGE
	----------------------------------------------------------------------*/
	homepageInit: function(){
		$.fn.cycle.defaults = { 
		    timeout: 6500,
			speed: 1000,
			sync: 1,
			delay: -3000
		};
		
		$('#callout-1 span').cycle();
		window.setTimeout(function() { $('#callout-2 span').cycle(); }, 400);
		window.setTimeout(function() { $('#callout-3 span').cycle(); }, 850);
	},
	/*======================================================================
		MEMBERS
	----------------------------------------------------------------------*/
	teamInit: function(){
		var $members = $('#members ul.member-list li.member');
		$('div.photo', $members)
			.hover(function(){
				if($.browser.msie && $.browser.version == '6.0') return false;
				
				$(this).css('cursor', 'pointer');
			})
			.click(function(){
				if($.browser.msie && $.browser.version == '6.0') return false;
				
				//hide any open modals
				$('div.info-container', $members).hide();

				//show this modal
				if($.browser.msie){
					$(this).parent().find('div.info-container').show();
				} else {
					$(this).parent().find('div.info-container').fadeIn('fast');
				}
		});


		$('div.info-container a.close', $members).click(function(){
			if($.browser.msie){
				$(this).parent().hide();
			} else {
				$(this).parent().fadeOut('fast');
			}
			return false;
		});
	}, 
	/*======================================================================
		GALLERY
	----------------------------------------------------------------------*/
	galleryInit: function(){
		var $imageContainer = $('#image-container'),
			$galleryLinks = $('#gallery-list li a'),
			$thumbLinks = $('#thumbs-container div.thumbs ul li a'),
			animating = false;

		/*---------------------------------
			GALLERY LINKS 
		---------------------------------*/
		$galleryLinks.click(function(){
			var $this = $(this);
			if($this.hasClass('current-gallery') || animating) return false;

			animating = true;

			var $targetGallery = $($this.attr('href')),
				$currentGallery = $('#thumbs-container div.current-gallery');
			
			$galleryLinks.removeClass('current-gallery');
			$this.addClass('current-gallery');

			$currentGallery.animate({ top: '90px',	opacity: '0' }, 500, 'swing', function(){ $currentGallery.removeClass('current-gallery') });

			$targetGallery
				.css({ top: '-90px', opacity: '0' })
				.animate({ top: '0', opacity: '1'}, 500, 'swing', function(){ $targetGallery.addClass('current-gallery'); animating = false; });

			return false;
		});

		/*---------------------------------
			THUMB LINKS
		---------------------------------*/
		$thumbLinks
			.not('.current').find('img').css({'opacity': 0.5})
			.end()
			.end()
			.hover(
				function(){
					$(this).find('img').fadeTo('fast', 1);
				},
				function(){
					$(this).not('.current').find('img').fadeTo('fast',0.5);
				}
			)
			.click(function(){
				if($(this).hasClass('current')) return false;

				$thumbLinks.removeClass('current');
				$(this).addClass('current');
				$thumbLinks.not('.current').find('img').fadeTo('fast',0.5);

				if($(this).parents('div.thumbs').hasClass('show-flourish'))
					$imageContainer.addClass('with-flourish');
				else
					$imageContainer.removeClass('with-flourish');

				$imageContainer.addClass('loading');
				var imageToLoad = new Image();

				$(imageToLoad)
					.load(function(){
						$this = $(this);
						$this.hide();
						$imageContainer
							.removeClass('loading')
							.find('#image img').replaceWith(this);
						$this.fadeIn();
					})
					.error(function(){
						$imageContainer
							.removeClass('loading')
							.find('#image img').replaceWith('<p>Our apologies, there was a problem loading your image.</p>');
					})
					.attr('src', this.href);
				return false;
			});
	}
});
	

