$.widget('ui.membersTooltip', {

	_init: function() {
		var obj = this;
		var parent = this.element;
		var container = this.options.container;
		
		parent.find('.photo-frame').live('click', function() {
			$('.author-info-clone .more a').attr('href', $('.author-info-clone .more a').attr('rel') );
			$('.author-info-clone .photo img').attr('src', $('.author-info-clone .photo img').attr('title') );
			
			var offset = $(this).closest(container).position();
			
			var height = $('.author-info').height();
			var width = $('.author-info').width();
			$('.author-info').html( $('.author-info-clone').html() );
			
			var minWidth = 1000;
			var left = offset.left - width;
			
			if($('body').width() < minWidth){
				left = 0;
			}else if($('body').width() > minWidth && left < 0 && $(this).closest(container).offset().left < width){
				var leftVal = -((parseInt($('body').width())-1000)/2);
				if(leftVal>left){
					left = leftVal;
				}
			}
			
			var top = offset.top - height;
			
			var picheight = $(this).closest('.photo').height();
			var picwidth = $(this).closest('.photo').width();

			
			$(this).parent().next('.author-info-hidden').find('li').each(function() {
				var replacement = $(this).attr('class').split('-');
				var val = $('.author-info').html();
				var regex = new RegExp( "\-\-" + replacement[1] + "\-\-", "g" );
				var matches = val.match(regex);
				var occurrences = ( matches ) ? matches.length : 0;
				
				for( var i = 0; i < occurrences; i++ ) {
					$('.author-info').html( $('.author-info').html().replace( "\-\-" + replacement[1] + "\-\-", $(this).html() ) );
				}
			});
		
			// $('.author-info').css('top', offset.top-height+picheight + "px");
			$('.author-info').css('top', top + "px");
			// $('.author-info').css('left', offset.left-width+picwidth + "px");
			$('.author-info').css('left', left + "px");
			$('.author-info').fadeIn('slow');
		});

	}
	
});

$(document).ready(function(){
	$(".anchor-scroll").anchorAnimate();

	$('.instructors-container').accordion({ collapsible: true });
	
	$('.crew .author-box').membersTooltip({ container: '.member' });
	
	// $('.hidden').hide();
});

/*******
	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***
	
	Never have an anchor jumping your content, slide it.

	Don't forget to put an id to your anchor !
	You can use and modify this script for any project you want, but please leave this comment as credit.
	
*****/
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function() {
		var caller = this
		$(caller).click( function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

