$(document).ready(function() {
	$("#blog_mid .blog_pagewindow").scrollable({ 
		vertical: true,
		next: "#blog_top .blog_page .next",
		prev: "#blog_top .blog_page .prev",
		onSeek: function() {
			resizeScrollable();
		}
	});
	$("#blog_top .blog_page .next").click(function() {
		var api = $("#blog_mid .blog_pagewindow").data("scrollable");
		var index = api.getIndex();
		var items = api.getItems();
		
		if (index == items.length - 1) addItem();
	});
	resizeScrollable(0);
	
	$("#picasa .picasa_slideblock").scrollable({ 
		clickable: false,
		next: "#picasa_top .picasa_page .next",
		prev: "#picasa_top .picasa_page .prev",
		size: 1
	});
	$("#picasa .picasa_slide").each(function(index, element) {
		$(this).find("br").remove();
		$(this).find("p:first").remove();
		$(this).find("img").removeAttr("style");
		$(this).find("font[color='#6B6B6B']").removeAttr("color").addClass("label");
		$(this).find("font[color='#333333']").removeAttr("color").addClass("value");
		$(this).find("font[color]").removeAttr("color");
	});
	$("#picasa .picasa_slide a").click(function(event) {
		var href = $(this).attr("href");
		
		$("#picasa_overlay").empty();
		
		event.preventDefault();
		$.ajax({
			url: "_scripts/picasa.cfc",
			datatype: "html",
			data: {
				method: "showPicasaAlbum",
				returnformat: "plain",
				href: href
			},
			success: function(response) {
				$("#picasa_overlay").html(response).jqm({ overlay: 87 }).jqmShow();
			}
		})
	});
});

function resizeScrollable() {
	var height = 0;
	var index = $("#blog_mid .blog_pagewindow").scrollable().getIndex();
	
	if (arguments.length == 1) index = arguments[0];
	if (index > 0) $("#content #arrow").hide();
	else $("#content #arrow").show();
	height = $("#blog_mid .blog_entry").eq(index).height();
	
	$("#blog_mid .blog_pagewindow").animate({ height: height + "px" }, 200);
}

function addItem() {
	var api = $("#blog_mid .blog_pagewindow").data("scrollable");
	var index = api.getIndex() + 2;
	
	$.ajax({
		url: "../_scripts/blog.cfc",
		data: {
			method: "getBlogContent",
			returnformat: "plain",
			index: index
		},
		success: function(response) {
			api.addItem(response);
		}
	})
}


