jQuery(document).ready(function() {

	$('.blurb a').click(function(e){
		e.preventDefault();
		$full_content = $($(this).attr('rel'));
		$('.blurb').fadeOut('slow', function(){
			$full_content.slideDown('slow');
		});
	});

	$('.full_content a').click(function(e){
		e.preventDefault();
		$blurb = $($(this).attr('rel'));
		$(this).parent().slideUp('slow', function(){
			$('.blurb').fadeIn('slow');
		});
	});


	//$('.scroll_bar').jScrollPane();

	next_item = 1;
	scroll_left = 0;
	scroller = false;
	max_left=0;

	var itemsWidth = 0;
	var magic_number = 19;

	//get the length of the list
	$(this).find(".item_div").each(function()
	{	
		itemsWidth += parseInt($(this).attr('rel')) + magic_number;
	});

	//max distance to the left the list can go before going past last item
	max_left -= (itemsWidth-$('.smallim').width());

	$('.smallim img').hover(function(){
		$('.slideShow').cycle({
		timeout: 0
		});

		$('#main_pic img').attr('style', 'padding-left:'+$(this).attr('rev')+'px').attr('src', $(this).attr('rel'));
		$('#main_pic_title').html($(this).attr('title'));
		noSlide = true;
	},      
		function () {}
);

$("#left_arrow").hover(function(){
	scroller = true;

	if(scroll_left<=0 && scroller)
	{
		$('#items').css('left', scroll_left);
		scroll_left = scroll_left + 10;
		setTimeout('scrollLeft()', 50);
	}

},
	function(){
	scroller = false;
});

$("#right_arrow").hover(function(){
	scroller = true;
	if(scroll_left>=max_left && scroller)
	{
		$('#items').css('left', scroll_left);
		scroll_left = scroll_left - 10;
		setTimeout('scrollRight()', 50);
	}

},
	function(){
	scroller = false;
});

$('.slideShow').cycle({
	fx:     'fade', 
	timeout: 4500, 
	before:   onBefore,
	pause: 1
});

});//end document ready

function scrollLeft()
{
if(scroll_left<=0 && scroller)
	{
		$('#items').css('left', scroll_left);
		scroll_left = scroll_left + 10;
		setTimeout('scrollLeft()', 50);
	}

}

function scrollRight()
{
if(scroll_left>=max_left && scroller)
	{
		$('#items').css('left', scroll_left);
		scroll_left = scroll_left - 10;
		setTimeout('scrollRight()', 50);
	}

}

function onBefore() { 
    $('#main_pic_title').html($(this).children().attr('title')); 
} 

function subSlideShow()
{/*
		
	if(!noSlide)
	{
		var $viewing = $('#main_pic img.viewing');

		if ( $viewing.length == 0 )
		{
			$active = $('#main_pic img:last');
		}

		var $next =  $viewing.next().length ? $viewing.next()
			: $('#main_pic img:first');

		$viewing.addClass('last_view');
		
		$viewing.fadeOut(100000, function(){
			//$viewing.removeClass('viewing');
			//$next.css({opacity: 0.0})
			//.addClass('viewing');
			//.animate({opacity: 1.0}, 1000, function() {
				//setTimeout('subSlideShow()', 4500);
			});//fade out
		//});//fade in
	}



	var listLength = $("#items").children("li").size();
		if(!noSlide)
	{
			$('#main_pic img').fadeOut('slow', function()
		{
			var src = $($($("#items").children("li")[next_item]).children('img')[0]).attr('rel');
			var title = $($($("#items").children("li")[next_item]).children('img')[0]).attr('title');
			$('#main_pic img').attr('src', src);
			$('#main_pic_title').html(title);
			$('#main_pic img').fadeIn('slow', function(){
				if(next_item<($("#items").children("li").size()-1))
				{
					next_item ++;
						console.log(next_item);
				}
				else
				{
					next_item = 0;
				}
				setTimeout('subSlideShow()', 3500);
			});
		});
	}*/
}