/**
 * Slide scroller by David Winter
 * 
 * david@fatbeehive.com
 */
 
jQuery.fn.slidescroll = function(options) 
{
	return this.each(function() 
	{
		var settings = jQuery.extend({
			items: '#slidecontainer a',
			left_button: '#leftscroll',
			right_button: '#rightscroll',
			close_button: '#closebtn a',
			container: '#slidecontainer',
			info_container: '#thumbopen',
			scroll_speed: 500,
			info_slide: 500,
			max_visible: 6,
			data: {}
		}, options);
				
		var slide_amount = jQuery(settings.items).eq(0).outerWidth(true);
		var items = jQuery(settings.items, this);
		var items_count = items.size();
		var counter = 0;
				
		jQuery(settings.left_button).click(function() {
			if (counter > 0)
			{
				jQuery(settings.container).animate({
					marginLeft: '+='+slide_amount+'px'
				}, settings.scroll_speed, 'swing');
				counter--;
			}
			return false;
		});
		
		jQuery(settings.right_button).click(function() {
			if (settings.max_visible != items_count 
			&& counter < (items_count - settings.max_visible))
			{
				jQuery(settings.container).animate({
					marginLeft: '-='+slide_amount+'px'
				}, settings.scroll_speed, 'swing');
				counter++;
			}
			return false;
		});
		
		jQuery(settings.close_button).click(function() {
			jQuery(settings.info_container).slideUp(settings.info_slide);
			return false;
		});
		// this is pretty site specific...
		items.click(function() {
			var link = this;
			jQuery(settings.info_container).slideUp(settings.info_slide, function() {
				var id = jQuery(link).attr('href').replace('?id=', '');
				
				var quote = settings.data[id]['quote'];
				var topic = 'Hear '+settings.data[id]['firstname']+' '+settings.data[id]['surname']+' speak at the Summit on "'+settings.data[id]['topic_title']+'"';
				var caption = settings.data[id]['firstname']+' '+settings.data[id]['surname']+', '+settings.data[id]['position']+', '+settings.data[id]['company'];
				
				if (settings.data[id]['quote'] != '')
				{
					$('#thumbquote').text(quote);
					$('#thumbtopic').text(topic);
					$('#thumbcaption').text(caption);
					
				}
				else
				{
					$('#thumbquote').text(topic);
					$('#thumbtopic').text(caption);
					$('#thumbcaption').text('');
				}
				
				$('#bio_question_link').text('Click here to put your questions to '+settings.data[id]['firstname']+' '+settings.data[id]['surname']+' now for the Summit').attr('href', '/speakers.php?action=speaker&id='+id);
				
				jQuery(settings.info_container).slideDown(settings.info_slide);
			});
			
			return false;
		});
		
	});
};
