var Awards = {Images: {}};

Awards.newAward = function() {
	var responseDiv = $j("#new-award-response-div");
	responseDiv.html("Creating new Event Page ...");
	var params = {title: $("new-award-title").value};
	var onSuccess = function(val) {
		responseDiv.html("award created successfully");
		var url = "/cms/awards/edit.php?id=" + val;
		loadUrl(url);
	};
	var onFailure = function(val) {
		responseDiv.html("ERROR: " + val);
	};
	callJson("/cms/awards/new.php", {parameters: params, onSuccess: onSuccess, onFailure: onFailure});
}.bind(Awards);

Awards.updateTitleAndBody = function(id) {
	var responseDiv = $j("#edit-response-div");
	responseDiv.html("Updating award title and body ...");
	var params = {title: $("edit-award-title").value, body: $("edit-award-body").value, id: id};
	var onSuccess = function(val) {
		responseDiv.html("award updated successfully");
//		reload();
	};
	var onFailure = function(val) {
		responseDiv.html("ERROR: " + val);
	};
	callJson("/cms/awards/edit_title_and_body.php", {parameters: params, onSuccess: onSuccess, onFailure: onFailure, method: 'post'});
}.bind(Awards);


Awards.addImage = function(id) {
	TINY.box.show("/cms/awards/add_image.php?id=" + id, 1, 400, 120, 2);
}.bind(Awards);


Awards.removeImage = function(id, filename) {
	var res = confirm("Are you sure you want to delete this image ?");
	if(!res) return;
	var onSuccess = function() {
		$j("#" + filename).fadeOut();
	};
	var onFailure = function(val) {
		alert('failed');
	};
	callJson("/cms/awards/remove_image_submit.php", {parameters: {award_id: id, filename: filename}, onSuccess: onSuccess, onFailure: onFailure});	
}.bind(Awards);

Awards.updateLogo = function(id) {
	TINY.box.show("/cms/awards/update_logo.php?id=" + id, 1, 400, 120, 2);
}.bind(Awards);

Awards.Images.init = function() {
	var clicked = function() {
		Awards.Images.clicked(this);
	};
	var links = $j(".image-links .image-link");
	links.click(clicked);
	links.first().click();
}.bind(Awards.Images);

Awards.Images.clicked = function(el) {
	var viewport = $j(".award-images .viewport");
	viewport.html("");
	var img = new Element("img", {src: el.getAttribute("imgsrc")});
	viewport.html(img);
	var links = $j(".image-links .image-link");
	links.removeClass("clicked");
	el.addClassName("clicked");
}.bind(Awards.Images);


Awards.deleteAward = function(id, divId) {
	var res = confirm("Are you sure you want to delete this award ?");
	if(!res) return;
	var params = {id: id}
	var onSuccess = function() {
		$j("#" + divId).fadeOut();
	};
	callJson("/cms/awards/delete.php", {parameters: params, onSuccess: onSuccess, method: 'post'});
}.bind(Awards);
