function toggleStar(photo_id) {
    var effect = new Effect.Opacity("vote-widget", {to:0.3, duration:0.4});

    function onCompleteStar(transport, object) {
	effect.cancel();
	new Effect.Opacity("vote-widget", {to:1.0, duration:0.2});
    }

    new Ajax.Updater($("vote-widget"), "star",
	{parameters: "photo_id="+photo_id, 
	 onComplete: onCompleteStar,
	 evalScripts: true});
}

function hideStarsNote() {
    $('stars-note').style.display = 'none';
}

function fixGalleryFloats() {
    lastParent = 0;
    galleryItems = document.getElementsByClassName("galleryItem");

    for (i = 0; i < galleryItems.length; i++) {
	galleryItem = galleryItems[i];

	firstRow = 0;
	if (galleryItem.parentNode != lastParent) {
	    lastTop = 0;
	    rowHeight = 0;
	    rowStart = i;
	    if (!lastParent)
		firstRow = 1;
	    lastParent = galleryItem.parentNode;
	}

	galleryItem.style.height = "auto";
	galleryItem.style.clear = "none";

	if (galleryItem.offsetTop != lastTop) {
	    if (!firstRow)
		galleryItem.style.clear = "left";
	    rowHeight = galleryItem.offsetTop - lastTop - 
		(galleryItem.style.marginTop + galleryItem.style.marginBottom);
	    for (j = rowStart; j < i; j++) {
		galleryItems[j].style.height = rowHeight+"px";
	    }
	    lastTop = galleryItem.offsetTop;
	    rowStart = i;
	}
    }
}

// ------------------------------------------------------------------------
// Keyboard Shortcuts

function handleCommonKeys(ev, keyCode) {
    if (keyCode == 47) {
	// / - jump to search field
	var searchField = document.getElementsByName('q')[0];
	if (searchField.value == 'Search') searchField.value='';
	searchField.focus();
	cancelEvent(ev);
	return false;
    } else if (keyCode == 103) {
	// g - initiate goto sequence
	lastKey = 103;
	cancelEvent(ev);
	return false;
    } else if (keyCode == 106) {
	// j - previous page
	var prevLink = $("prev_link");
	if (prevLink != null)
	    document.location.href = prevLink.href;
	cancelEvent(ev);
	return false;
    } else if (keyCode == 107) {
	// k - next page
	var nextLink = $("next_link");
	if (nextLink != null)
	    document.location.href = nextLink.href;
	cancelEvent(ev);
	return false;
    } else if (keyCode == 114) {
	// r - random photo
	document.location.href = "photo-random";
	cancelEvent(ev);
	return false;
    } else
	return true;
}
