/*old slideshow functions, kept here in case we switch back*/
function next_slide() {
	var current = $('#baked_goods_wrapper .slide.current').eq(0);

	if($(current).hasClass('last')) {
		reset_slides();
	}
	else {
		$(current).fadeTo(500, 0, '', function() {
			$(current).next('.slide').addClass('current');
			$(current).removeClass('current');
			setTimeout('next_slide()', 4000);
		});
	}
	
}

function reset_slides() {
	$('#baked_goods_wrapper .slide').fadeTo(500,1,'',function() {
		
	});
	
	$('#baked_goods_wrapper .current').removeClass('current');
	start_slideshow();

}

function start_slideshow() {
	$('#baked_goods_wrapper .slide:first').addClass('current');
	
	setTimeout('next_slide()', 4000);	
}

/*slideshow functions currently in use on wtb and baked goods pages*/
function switch_image(el) {
	var new_image = $(el).find('img.wtb_placement');
	var new_src = new_image.attr('src');
	var spot = $('#slideshow_image').eq(0);
	
	if(spot.length > 0 && new_image.length > 0) {
		spot.attr('src', new_src);
	}
	
	set_current(el);
}

function fade_image(el) {
	var new_image = $(el).find('img.wtb_placement');
	var new_src = new_image.attr('src');
	var spot = $('div.slideshow_wrapper').eq(0);
	
	if(spot.length > 0 && new_image.length > 0) {
		var img = new Image();
		$(img).attr('src', new_src).fadeTo(0,0).addClass('second_image');
		spot.append(img);
		$(img).fadeTo(400,1,'',function() {
			$('#slideshow_image').remove();
			$(img).attr('id','slideshow_image').removeClass('second_image');
		});
	}
	
	set_current(el);	
}

function set_current(el) {
	$('div.one_item h3,div.one_item .address,div.one_item').removeClass('current');
	$(el).addClass('current').find('h3:first,p.address').addClass('current');	
}

function next_spot() {
	var current = $('div.one_item.current').eq(0);

	if($(current).hasClass('last')) {
		reset_spots();
	}
	else {
		var next = $(current).next('div.one_item');
		
		//adding to skip elements we don't have images for
		if(next.length > 0 && $(next).hasClass('skip')) {
			next = $(next).next('div.one_item');
			}
			
		//need to add this to jump one column to the next
		// if next isn't found
		if(next.length < 1) {
			//find the column
			var col = $(current).parents('div.std_column');
			//grab the next column
			var next_col = col.next('div.std_column');
			//grab the first item
			var next = $(next_col).find('div.one_item:first');
		}
		fade_image(next);
	}
}

function reset_spots() {
	fade_image('div.one_item:first');
}

function slide_show_on() {
	window.queue = setInterval('next_spot()',4000);
}

function slide_show_off() {
	window.clearInterval(window.queue);
}

function even_columns() {
	var columns = $('div.std_column.text, div.std_column.empty');
	var tallest = 435;
	var padding = 24;
	
	$(columns).each(function() {
		if($(this).height() > tallest) {
			tallest = $(this).height();	
		}
	});
	
	var new_height = tallest;
	$(columns).css('min-height', new_height);
}

