var filename;
var convertTypes;

$(function() {
	$("#tabs").tabs( {
		fx : {
			opacity : 'toggle'
		}
	});
});

$(function() {
	$("input.file1").filestyle( {
		image : "stylesheets/images/view.jpg",
		imageheight : 40,
		imagewidth : 80,
		width : 249
	});
});

$(function() {
	// all hover and click logic for buttons
	$(".cc-button:not(.ui-state-disabled)").hover(function() {
		$(this).addClass("ui-state-hover");
	}, function() {
		$(this).removeClass("ui-state-hover");
	});
});

$(function() {
	$("#progressbar").progressbar();
});

$(document).ready(function() {
	var options = {
		beforeSubmit : beginUpload,
		success : uploadSuccess,
		dataType : 'json'
	};

	$('#uploadForm').submit(function() {
		$(this).ajaxSubmit(options);
		return false;
	});
});

$(document).ready(function() {
	$("#view").click(function() {
		self.location = "user/anonymous/storage/" + filename + "/view";
	});
});

function beginUpload() {
	$("#progressbar").show();
	$("#progressbar .ui-progressbar-value").animate( {
		width : '100%'
	}, 2000, endUpload);
}

function endUpload() {
	$("#progressbar").hide("blind", {}, 100,
			$("#progressbar .ui-progressbar-value").animate( {
				width : '0%'
			}));
	$("#uploadFileInfo").show("blind", {}, 100);
}

function uploadSuccess(r) {
	var hasFile = r.hasFile;
	var geshi = $("#geshi");

	if (hasFile) {
		filename = r.filename;
		convertTypes = r.convertTypes;
		$("#uploadFilename").text(filename);
		$("#uploadFiletype").text(r.fileType);
		geshi.empty();
		for ( var i = 0; i < convertTypes.length; i++) {
			$(
					"<option value='" + convertTypes[i] + "'>"
							+ convertTypes[i] + "</option>").appendTo(geshi)
		}
	} else {
		$("#uploadFilename").text("none");
		$("#uploadFiletype").text("none");

	}
}

// post-submit callback
