
function logMediaVote(media_id, vote, showText)
{
	if(typeof showText == 'undefined') showText = 'false';
	if(typeof jQuery == 'undefined') alert('Could not save your vote, please wait and try again.');
	else{
		jQuery("#voteBoxBrowse"+media_id).html('Saving vote...');
		jQuery.post("/includes/browse/browseVote.php", { 'vmid': media_id, 'vote': vote, 'showText':showText }, function(data, textStatus){
			jQuery("#voteBoxBrowse"+media_id).replaceWith(data);
		});
	}
}

function initCommentBox(commentText, commentSubmit)
{
	commentText.val("Click to leave a comment");
	commentText.css({color:'#999'});
	commentSubmit.hide();
}
function focusCommentBox(event)
{
	if(event.data.box.val() == "Click to leave a comment"){
		event.data.box.val('');
		event.data.box.css({color:'#333'});
		event.data.submit.show();
		if(jQuery.browser.safari) event.data.submit.css({display:'block'});
	}
}
function blurCommentBox(event)
{
	if(event.data.box.val() == '') initCommentBox(event.data.box, event.data.submit);
}
function initCommentForm(formSelector)
{
	var commentForm = jQuery(formSelector);
	var commentText = commentForm.find('textarea');
	var commentSubmit = commentForm.find('input[type="submit"]');
	initCommentBox(commentText, commentSubmit);
	
	commentText.bind('focus', {box:commentText, submit:commentSubmit}, focusCommentBox);
	commentText.bind('blur', {box:commentText, submit:commentSubmit}, blurCommentBox);
}

var previewBtnTimeout = null;
var previewBtnDelay = 100; //miliseconds
function showPreviewButton(event){
	hideAllPreviewButtons();
	var pos = event.data.img.position();
	event.data.btn.show();
	event.data.btn.css({top:Math.round(pos.top+2)+'px', left:Math.round(pos.left+((event.data.img.width()/2)-(event.data.btn.width()/2)))+'px'});
}
function setPreviewButtonTimeout(event){
	previewBtnTimeout = window.setTimeout(function(){ hidePreviewButton(event); }, previewBtnDelay);
}
function clearPreviewButtonTimeout(){
	clearTimeout(previewBtnTimeout);
}
function hidePreviewButton(event){
	event.data.btn.hide();
}
function hideAllPreviewButtons(){
	jQuery('a.previewButton').hide();
}

